'Undefined index' error in some PCs and not in others
Moderator: General Moderators
'Undefined index' error in some PCs and not in others
Everything works fine on my three PCs, also from other people which I have let them test (from different countries). But when my brother tests it Im get the following, this happens each time he makes an action that deals with the php code, db etc. We have checked that we have the exact same version of Explorer. Why is it happening due to firewalls or? Cookies are Enabled on his PC..? Im going nuts on this and cant debug it really cuz I have no error on my pc? There is nothing send to the browser either.
Notice: Undefined index: HTTP_REFERER in /customers/serapsungur.com/serapsungur.com/httpd.www/new_whynot/cart1.php on line 65
Warning: Cannot modify header information - headers already sent by (output started at /customers/serapsungur.com/serapsungur.com/httpd.www/new_whynot/cart1.php:65) in /customers/serapsungur.com/serapsungur.com/httpd.www/new_whynot/cart1.php on line 65
thanks,
Serap
Notice: Undefined index: HTTP_REFERER in /customers/serapsungur.com/serapsungur.com/httpd.www/new_whynot/cart1.php on line 65
Warning: Cannot modify header information - headers already sent by (output started at /customers/serapsungur.com/serapsungur.com/httpd.www/new_whynot/cart1.php:65) in /customers/serapsungur.com/serapsungur.com/httpd.www/new_whynot/cart1.php on line 65
thanks,
Serap
Yes I think so - they have a firewall setup by their service provider. The thing is that he can add new items (updating the DB) but with the error each time php is called. If that is problem how do you usually solve it with so many combinations out there?? And let them test bigger sites - you name it - to check their cookie settings that works fine.
Thanks,
Serap
Thanks,
Serap
Here is the code (from the clasic Macromedia example) :
and line 65 is removeItem...
EDITED BY BECH100: ADDED PHP TAGS - PLEASE REMEMBER TO DO IT YOURSELF, EASIER TO READ
and line 65 is removeItem...
Code: Select all
<?php
include("db2.php");
error_reporting(E_ALL);
switch($action)
{
case "add_item":
{
AddItem($id, $qty, $color);
break;
}
case "update_item":
{
UpdateItem($_GET["id"], $_GET["qty"],$_GET["colorid"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["id"], $_GET["color"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
function AddItem($id, $qty, $color)
{
$cookieId = GetCartId();
$result = mysql_query("select count(*) from cart where itemId=$id and color='$color' and cookieId='" . GetCartId() . "' ");
$row=mysql_fetch_row($result);
$check_result=$row[0];
if ($check_result== 0)
{
@mysql_query("insert into cart(cookieId, itemId, qty, color)
values('" . GetCartId() . "', $id, $qty, '$color' )");
header("location: ".$_SERVER["HTTP_REFERER"]);
}
else
{
UpdateItem($id, $qty);
header("location: ".$_SERVER["HTTP_REFERER"]);
}
}
function UpdateItem($itemId, $qty)
{
//echo "update item";
//echo $_SERVER['HTTP_REFERER'];
}
function RemoveItem($itemId, $color)
{
@mysql_query("delete from cart where itemId=$itemId and color='$color' and cookieId='" . GetCartId() . "' ");
header("location: ".$_SERVER["HTTP_REFERER"]);
}
function ShowCart()
{
//to be filled
}
}
?>It sounds llike it is there firewall blocking the HTTP_REFERER header being passed to your server, if you dont put the line
in, it should be ok, but if the is no HTTP_REFERER variable set you are not going to have anywhere for the header to redirect you to, you might want to check that it contains a value or default it to something!error_reporting(E_ALL);
found this
as an array in your session var... or you could use a cookie by
unserialize($cookie); push($cookie[0],$url); serialize($cookie); (or
something like that.. ) either way you will have an array of visited
urls.. much like the javascript history method..
you could store $url = $_SERVER['http_host'] . $_SERVER['request_uri'];$_SERVER['HTTP_REFERER'] should not be used.. often times user behind a
proxy are configure not to submit http_referer
note.. rfc2616
15.1.3 Encoding Sensitive Information in URI's
Because the source of a link might be private information or might
reveal an otherwise private information source, it is strongly
recommended that the user be able to select whether or not the
Referer field is sent. For example, a browser client could have a
toggle switch for browsing openly/anonymously, which would
respectively enable/disable the sending of Referer and From
information.
Clients SHOULD NOT include a Referer header field in a (non-secure)
HTTP request if the referring page was transferred with a secure
protocol.
Authors of services which use the HTTP protocol SHOULD NOT use GET
based forms for the submission of sensitive data, because this will
cause this data to be encoded in the Request-URI. Many existing
servers, proxies, and user agents will log the request URI in some
place where it might be visible to third parties. Servers can use
POST-based form submission instead
as an array in your session var... or you could use a cookie by
unserialize($cookie); push($cookie[0],$url); serialize($cookie); (or
something like that.. ) either way you will have an array of visited
urls.. much like the javascript history method..
But I understand from your replies that the
$_SERVER["HTTP_REFERER"]
can not be trusted at all? then when making a site with PHP - this is my first site with PHP.
The problem is that when a user makes an add_item I have to get back to the caller site...so if I use (in caller site)
$url = $_SERVER['http_host'] . $_SERVER['request_uri'];
I will post $url..to cart1.php
and in cart1.php use:
header("location: "$url"]);
Do you guys never use $_SERVER["HTTP_REFERER"] then on your sites??
(how does all other sites handle it ex. amazon? )
And how can you protect you code then from firewall blockings?
thanks,
Serap
$_SERVER["HTTP_REFERER"]
can not be trusted at all? then when making a site with PHP - this is my first site with PHP.
The problem is that when a user makes an add_item I have to get back to the caller site...so if I use (in caller site)
$url = $_SERVER['http_host'] . $_SERVER['request_uri'];
I will post $url..to cart1.php
and in cart1.php use:
header("location: "$url"]);
Do you guys never use $_SERVER["HTTP_REFERER"] then on your sites??
(how does all other sites handle it ex. amazon? )
And how can you protect you code then from firewall blockings?
thanks,
Serap