skip to Main Content

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

7

Answers


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

    print_r($_GET);
    
    Login or Signup to reply.
    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:

    Login or Signup to reply.
  2. I always tend to use something like:

    $image = isset($_GET['image']) ? $_GET['image'] : FALSE;
    
    Login or Signup to reply.
  3. is your ‘image’ a file? If so then it should be in $_FILES not $_GET

    do print_r($_GET); and print_r($_FILES);

    what do you see?

    Login or Signup to reply.
  4. Kindly check your .htaccess also, maybe some rewrite rule there is destroying your GET parameters. See https://stackoverflow.com/a/6656450/216084

    Login or Signup to reply.
  5. 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.

    Login or Signup to reply.
  6. This is old, but I just stumbled upon the same problem and found an easy fix. I was using a short php tag (<?....?>). Once I changed it to <?php....?>, my $_GET started working again. I have no idea why only this was affected by the short tag, but it fixed. Hope this helps someone else…

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search