Forum Moderators: coopster
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
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.
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?
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.
$_SERVER['PHP_SELF']
there are other vars too that might work, check Server variables [php.net]
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