Forum Moderators: coopster
I'd like to append a variable to all my urls:
<?php
$url = $_SERVER['REQUEST_HEADER'];
$finalurl = $url.'?var=1';
if ($url != $finalurl) {
header("Location:$finalurl");
} else {
echo "solved!";
}
?>
it appends the ?var=1 but also gives a redirect loop.
I tried also with REQUEST_URI and same result...
it seems the condition I put is ignored...
any help is apreciated...
thanks!
ricc.
$new_var = "1"; //If $var is not set than what do you want $var to say
$path = $_SERVER['REQUEST_URI'] . "?var=" . $new_var;
if (!isset($var)) {
header("Location: $path");
} elseif ($var != $new_var) {
$path = $_SERVER['REQUEST_URI'] . "&var=" . $new_var;
header("Location: $path");
}
?>
Little longer but it should work.
now I'm trying to put myself $new_var in the url instead having it already assigned.
Then I'd like the script (that's included in a template, I have it in every page) to retain that value until I put a new value.
e.g. when I write in adress bar:
www.mypath?var3
it should be retained for the next pages. Until I write:
www.mypath?var4
That also should be retained, and so on.
But I'm a bit lost...
If you can help again, Thanx!
ricc.
<?php
$var = $_GET['var']; //Gets the var from the url (if exists)
setcookie("TestCookie", $var, time()+3600);
$new_var = "1"; //If $var is not set than what do you want $var to say (default value)
$new_var = $_COOKIE['TestCookie'];
$path = $_SERVER['REQUEST_URI'] . "?lang=" . $new_var;
if (!isset($var)) {
if ($var != $new_var) {
header("Location: $path");}
}
?>
It works, but unfortunately it relies on cookies... no idea if there are alternative solutions though... (session?)
bye
ricc.