简体   繁体   中英

Why won't $_GET work PHP 5.3.21?

I'm using $_GET within a switch statement to determine with options to display in a select box. Things were great until I upgraded my server to PHP 5.3.21. Now I get undefined index and undefined variable error messages. I've modified my code to include if isset(). Now there are no errors, but I can't get PHP to recognize that $_GET["menuid"} does have a value.

URL that I'm trying to get variables from:

http://www.example.com/mod/page/view.php?id=5100&module=1&menuid=2&module=1&page=2

Code I'm using:

if (isset($_GET['menuid'])) {
    $menuid = $_GET['menuid'];
}
else {
    $menuid = "not working";
}

echo $menuid;
switch($menuid) {
    // My code
   }

The results are:

"not working"

EDIT: Results of `var_dump($_GET)' on the PHP sub page

array(0) { }

EDIT: Results of var_dump($_GET) on the PHP main page

array(4) { ["id"]=> string(4) "5100" ["module"]=> string(1) "1" ["menuid"]=> string(1) "2" ["page"]=> string(1) "2" }

The above var_dump is from the PHP main page. The original code is on a separate PHP page that I've included to the PHP main page with a file_get_contents();. Would the file_get_contents() cause this problem?

It turns out that file_get_contents() was making $_GET not work correctly. I've modified my code on the main PHP page to require_once(). A var_dump($_GET) of the sub PHP page, that my original code is on, is now resulting in this:

array(4) { ["id"]=> string(4) "5100" ["module"]=> string(1) "1" ["menuid"]=> string(1) "2" ["page"]=> string(1) "2" }

Thank you to @Mansfield for you help

You have two times a "module" defined. I think the right URL looks like this:

http://www.example.com/mod/page/view.php?id=5100&menuid=2&module=1&page=2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM