PHP - How to get tokens?

I was told that I need to check the tokens below, but I'm not sure where to start. I have only open access to the website from which I retrieve data. Does someone explain me tokens or give me an example to make me move?

Do I need access to another server?

function send_CAD($number, $street, $website, $f_opts = true){         
    $year   = date('Y', time());    
    $number = trim($number);
    $street = urlencode(trim($street));
    $post_data = "__EVENTTARGET=&__EVENTARGUMENT=&".
                 "__VIEWSTATE=/wEPD...&" .
                 "__EVENTVALIDATION=/wEWNw...&".
                 "txtAddrNum=$number&listStDir=&";
...
+3
source share
2 answers

I'm not sure exactly what you are asking, so here is the answer in both directions:

If you have the full URL that you are trying to parse, use parse_url:

$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);

The above example outputs:

Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)

If you have only part of the URL request, you can use parse_str:

parse_str($str, $output);
echo $output['first'];  // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz

If you have the url you are trying to use, use http_build_query:

$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor

, , filter_input / PHP:

http://us2.php.net/manual/en/ref.filter.php
http://us2.php.net/manual/en/function.filter-input-array.php

http://us2.php.net/manual/en/filter.filters.validate.php
http://us2.php.net/manual/en/filter.filters.sanitize.php

filter_validate_array :

/* data actually came from POST
$_POST = array(
    'product_id'    => 'libgd<script>',
    'component'     => '10',
    'versions'      => '2.0.33',
    'testscalar'    => array('2', '23', '10', '12'),
    'testarray'     => '2',
);
*/

$args = array(
    'product_id'   => FILTER_SANITIZE_ENCODED,
    'component'    => array('filter'    => FILTER_VALIDATE_INT,
                            'flags'     => FILTER_REQUIRE_ARRAY, 
                            'options'   => array('min_range' => 1, 'max_range' => 10)
                           ),
    'versions'     => FILTER_SANITIZE_ENCODED,
    'doesnotexist' => FILTER_VALIDATE_INT,
    'testscalar'   => array(
                            'filter' => FILTER_VALIDATE_INT,
                            'flags'  => FILTER_REQUIRE_SCALAR,
                           ),
    'testarray'    => array(
                            'filter' => FILTER_VALIDATE_INT,
                            'flags'  => FILTER_REQUIRE_ARRAY,
                           )

);

$myinputs = filter_input_array(INPUT_POST, $args);

var_dump($myinputs);
echo "\n";

:

array(6) {
  ["product_id"]=>
      array(1) {
        [0] => string(17) "libgd%3Cscript%3E"
      }
  ["component"]=>
      array(1) {
        [0] => int(10)
      }
  ["versions"]=>
      array(1) {
        [0] => string(6) "2.0.33"
      }
  ["doesnotexist"]=>
      NULL
  ["testscalar"]=>
      bool(false)
  ["testarray"]=>
      array(1) {
        [0] => int(2)
      }
}
+4

VIEWSTATE .. ASP.NET. PHP. ASP.NET php-, , :

echo "<pre>".print_r($_REQUEST, TRUE)."</pre>";

, . , :

$itemid = $_REQUEST['itemid'];

"", .

$_REQUEST $_GET, $_POST , php-.

0

Source: https://habr.com/ru/post/1784829/


All Articles