Forum Moderators: coopster
//connection shiz
$return = $_SERVER[HTTP_REFERER];
if(eregi('^[a-z0-9]+$', $layout))
{
$query = mysql_query("SELECT * FROM ****** WHERE name='$layout'");
$true = mysql_num_rows($query);
if($true == 0)
{
header("Location: $return");
}
else
{
setcookie("layout", "", time()-360000000);
setcookie("layout", $layout, time()+360000000);
if($return!= "")
{
header("Location: $return");
}
else
{
$query = mysql_query("SELECT * FROM ******");
$fetch = mysql_fetch_array($query);
header("Location: $fetch[siteurl]");
}
}
}
else
{
header("Location: $return");
}
?>
as you can see ive now attempted to delete the cookie and then create a new one instead of trying to just change the value of the current one, Any Suggestions Please?
and then change.php sets a cookie on the visitor's computer so that when they are redirected back to the main site, the main site can get the layout from SQL based on what their cookie is set to.
I'd assume you're using a default layout, and checking like:
if (!isset($_COOKIE['layout'])) {
$layout = 'default';
}
// Query the db for the layout and display it, etc.
Have you tried also adding a url parameter as well, for those without cookies enabled? Like so:
if (!isset($_COOKIE['layout']) ¦¦!isset($_REQUEST['layout'])) {
$layout = 'default';
}
// run your queries, etc.
Then on your change.php, append the layout to the redirection url(s).
header("Location: $return?layout=$layout");
Without seeing the entire workings of the code, it's hard to find the exact problem. It could be a simple typo or perhaps just some qwerk. What I tend to do is run through everything step by step and check syntax and that each item does what it's supposed to do. You could call the cookie vars and display them to see if they're getting set. If they're not, then most likely the browser is refusing the cookies, but by using a url paramteter as well, you ensure the data gets set and used.
Change:
$return = $_SERVER[HTTP_REFERER];
To:
$return = $_SERVER['REQUEST_URI'];
I think the problem may be that your browser (IE or FF) is not setting the HTTP_REFERER. From the PHP web site:
Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
REQUEST_URI returns everything after [domain.com...] that was requested to access that page. If you're using a query variable, for example?layout=blah, you can use $_SERVER['QUERY_STRING'] for your comparison.
The reason I am mentioning this is that I test with all errors displayed. If I call $_SERVER['HTTP_REFERER'] I get 'undefined index' warning, no matter if I'm using FF or IE. Even if I am redirected or click a link.
Then you can check for the REFERER and if it's there, redirect to it.