dousha1873 2011-01-11 20:33
浏览 55
已采纳

PHP - 如何获得令牌?

I was told I needed to validate the tokens below but I'm not sure where to start. I only have public access to the website I'm pulling the data from. Someone explain to me tokens or give an example to get me moving?

Do I need access to the other 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=&";
...
  • 写回答

2条回答 默认 最新

  • duanfan8699 2011-01-11 21:09
    关注

    I'm not sure exactly what you're asking so here's the answer in both directions:

    If you have a full url that you're 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 will output:

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

    If you have only the query part of the url 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 a url that you're trying to construct 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
    

    If you need to do validation on the data, once you've gotten it, you can use the built in filter_input functions with validation/sanitizing options in 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

    Example from filter_validate_array page:

    /* 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 "
    ";
    

    The above example will output:

    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)
          }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.