GET URL parameter in PHP

前端 未结 9 979
旧时难觅i
旧时难觅i 2020-11-22 07:32

I\'m trying to pass a URL as a url parameter in php but when I try to get this parameter I get nothing

I\'m using the following url form:

http://loc         


        
相关标签:
9条回答
  • 2020-11-22 08:21

    As Alvaro said, $_GET is not a function but an array containing the parameters So you can retrieve one element from that array using

    <?php
    $link = $_GET['link'];
    echo $link;
    ?>
    

    Expected OP:

    www.google.com
    
    0 讨论(0)
  • 2020-11-22 08:24

    I was getting nothing for any $_GET["..."] (e.g print_r($_GET) gave an empty array) yet $_SERVER['REQUEST_URI'] showed stuff should be there. In the end it turned out that I was only getting to the web page because my .htaccess was redirecting it there (my 404 handler was the same .php file, and I had made a typo in the browser when testing).

    Simply changing the name meant the same php code worked once the 404 redirection wasn't kicking in!

    So there are ways $_GET can return nothing even though the php code may be correct.

    0 讨论(0)
  • 2020-11-22 08:26

    To make sure you're always on the safe side, without getting all kinds of unwanted code insertion use FILTERS:

    echo filter_input(INPUT_GET,"link",FILTER_SANITIZE_STRING);
    

    More reading on php.net function filter_input, or check out the description of the different filters

    0 讨论(0)
提交回复
热议问题