8

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

1
  • you should change the $HTTP_GET_VARS['image']==0 to $_GET['image']==0 Commented Aug 16, 2012 at 19:02

7 Answers 7

7

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.

Sign up to request clarification or add additional context in comments.

Comments

5
  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:

4 Comments

It works fine on all the other sites so I not sure it is a php install problem
@user1604132 - Q: What did you see when you tried the "phpinfo()" test script with your "?image=2" URL?
When I use this /popup_image.php?image=2 it works but when i use this /build-your-own-rapid-deployment-portable-camera-system-quick-setup-wireless-video-internal-battery-pi-9.html?image=2 it does not work. I using mod rewrites to change the url also I am using OSCommerce. This is not making sense to me. All my other sites works fine just not this one.
Ok so I found when the problem is but not sure how to fix it RewriteRule ^(.*)-pi-([0-9]+).html\?(.*)$ /popup_image.php?$3&pID=$2 RewriteRule ^(.*)-pi-([0-9]+).html(.*)$ /popup_image.php?pID=$2 If I remove the everything from the ? over it will get the variable but currently it will not get anything past the pID=$*
2

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

print_r($_GET); 

2 Comments

Hi user16.., I did some research too and it looks like you should not be using $HTTP_GET_VARS. (See php.net/manual/en/reserved.variables.get.php). But if you're still having problems, perhaps try using the session variables inherent in PHP?
The site was original coded for php 4 and i am not using it on php 5 plateform
2

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...

Comments

0

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?

3 Comments

Array ( [pID] => 9 ) Array ( )
This is not an image it is a number then I am writing that number to a html tag later in the page. The url qurey is site.com/pi-9.html?image=2
I am using rewrites for the url RewriteRule ^(.*)-pi-([0-9]+).html\?(.*)$ /popup_image.php?$3&pID=$2 RewriteRule ^(.*)-pi-([0-9]+).html(.*)$ /popup_image.php?pID=$2
0

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

Comments

-1

I always tend to use something like:

$image = isset($_GET['image']) ? $_GET['image'] : FALSE; 

2 Comments

I did this and it just comes back blank
Let me edit it a bit.. copy / paste is sometimes a bad habit. Try now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.