Forum Moderators: coopster

Message Too Old, No Replies

error Undefined index: HTTP_REFERER on different PCs

         

bagheera

8:19 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



Everything works fine on my PC but when my brother tests it from his company PC I get the following error below this happens each time he makes an action that deals with the HTTP_REFERER. - adding an item, deleting an item etc . I have heard it could have something to do with firewalls? But how do you test your code (with all the combinations of firewalls etc out there) and what is the best practice for this? This will be my first site in php... Does this then mean that using HTTP_REFERER is actually obsolete? or do you need to exception handle it somehow? Ill be happy for any advice

Notice: Undefined index: HTTP_REFERER in /customers/mysite.com/mysite.com/httpd.www/new/cart1.php on line 65

Warning: Cannot modify header information - headers already sent by (output started at /customers/mysite.com/mysite.com/httpd.www/new/cart1.php:65) in /customers/mysite.com/mysite.com/httpd.www/new/cart1.php on line 65

jatar_k

8:32 pm on Mar 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



cart1.php on line 65 - what is on line 65

As to referer in general, it is unreliable at best, it can't be used as an integral dependency in your software or you are going to run into these issues. Use sessions if you need to be sure. You can have a login where the user is authenticated and then you run off of session vars from there.

bagheera

8:44 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



This is on line 65
....
header("location: ".$_SERVER["HTTP_REFERER"]);
....

But how do I get back to the page I want when f.ex submitting addItem to cart1.php - which inserts stuff - then I just need to get back to my caller page? Im new to php and were 'told' to use HTTP_REFERER...? What would be the workaround.

The code works from all other PCs but not his? and This IS quite unreliable?

jatar_k

8:52 pm on Mar 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Probably just happens to be the first cpu that doesn't have referer data, don't worry better now than later because there will be more.

what about passing the pagename to cart1? then the script will always know where it came from and you won't have to rely on referer data.

bagheera

9:05 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



So Ill do smtg like:
--> pass $url to cart1.php

header("location: $url"]);

?

and is it possible to get $url from caller page without needing to hardcoding it...ie any standard variable that will work (Not like the HTTP_REFERER stuff).

Do you know the reason why HTTP_REFERER dont work - Ive just thought about it for days....
Thanks.

jatar_k

9:21 pm on Mar 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try having it pass somthing like

$_SERVER['PHP_SELF']

there are other vars too that might work, check Server variables [php.net]

aalaap

10:49 am on Mar 13, 2004 (gmt 0)



First of all, ensure its not a capitals/lowercase problem. Try $_SERVER["HTTP_REFERER"] and see if it works.

Secondly, keep in mind that this variable is only available if the clients browser sent it in the http request. If the client is using some privacy tools, or maybe a proxy server etc, this variable is not available. But a @ before the line, and then check for the length .. if 0, it wasn't provided. I've noticed that (in most cases, at least) local browsing (http://localhost) makes IE not pass the referer.

For what you need to do (not track referrers, but use them to send people to where they came from), maybe you could try and change your script to a self-posting one, i.e. Right now, perhaps a script posts to cart1.php and then you send the visitor back to the refering url. Instead, you could put the cart processing code in that script itself. I'm assuming a usual scenario here, where a cart script (cart.php for example) is mainly one central script which has actions (buy, empty, etc) that would best be posted to itself (action=buy&product=xyz...). Of course your situation can be different, but this would be the approach I'd take.

If all else fails, then I guess the best option is to pass the current script url to the next script. If I were to do that, I'd do away with clunky &url=http%3A%2F%2F.. type tags, and instead, in every script, store $_SERVER['PHP_SELF'] in a $_SESSION["CURRENT_SCRIPT"] .. and use it whenever required from any script .. for example cart1.php.

Hope that helps and wasn't too .. over the top :)

- Aalaap