Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_GET not working

Tags:

php

I cannot get my $_GET to work. It works on every other site I have on the server but just not on this site. The site is osCommerce and I am running PHP 5.

if (($HTTP_GET_VARS['image'] ==0) && ($products['products_image_lrg'] != '')) {
    //do something
};

I also tried

echo $_GET['image'] 

and it still will not work. It just gives me undefined index.

The URL looks like this: /blah.php?image=2

I have stripped the page down to the bare still not working see below

<?php

    echo $HTTP_GET_VARS['image'];
    echo $_GET["image"];
    echo "<br />";
?>

I get this

Notice: Undefined variable: HTTP_GET_VARS in \popup_image.php on line 3 Notice: Undefined index: image in \popup_image.php on line 4 

I have been doing some more digging and it looks like a problem somewhere in oscommerce not allowing it to read

like image 506
user1604132 Avatar asked Aug 16 '12 19:08

user1604132


People also ask

What is $_ GET variable?

PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL.

How does get work in PHP?

There are two methods in PHP to collect data submitted in a FORM. GET Method and POST Method. In the GET method, you submit data from HTML FORM/collected using a super global variable $_GET. This method sends the encoded information from the FORM through the webpage URL.


3 Answers

You have forgotten to add the QSA (query string append) flag on your mod rewrite rule. Without this flag, any query string added to your url before the rewrite is discarded in favor of the new query string added to the rewrite rule, though it will still be visible in the bar at the top of the browser.

like image 105
Matt R Avatar answered Sep 28 '22 19:09

Matt R


  1. the following should work with PHP 5.x:

    • HTTP: http://myserver/blah.php?image=2

    • PHP (blah.php?):

      if (isset($_GET['image'])) { $idx=$_GET['image']; // Should be "2" }

  2. I'm assuming you're trying to access "$_GET[]" from "blah.php". If not, you need to pass the URL to the page you're calling.

  3. print_r($_GET) or var_dump($_GET) is a good idea. So is bumping error_reporting(NNN).

  4. An even better idea is to create a dummy page, phpinfo.php:

    • phpinfo.php:

      <?php phpinfo (); ?>

    • http query:

      http://myserver/phpinfo.php?image=2

    Q: Does phpquery() show you the "image" URL anywhere???

  5. Finally, here's a similar case that turned out to be a PHP install problem:

    • http://social.expression.microsoft.com/Forums/en-IE/web/thread/4a36ab6f-98c7-4a29-b9d7-06fd79c4b0c6
like image 26
paulsm4 Avatar answered Sep 28 '22 17:09

paulsm4


First, try looking at an entire print out of the $_GET array:

print_r($_GET);
like image 34
bobbiloo Avatar answered Sep 28 '22 18:09

bobbiloo