Forum Moderators: coopster
been trying to work on a style swithcer for my site using cookies. it works but when i use php query strings to pass a value to a script, to make the style wicth by clicking on a link, i canot get it to work. the code is below can someone please help me. its not my code as i found it on
[alistapart.com...]
swticher:
<?php
setcookie ('sitestyle', $set, time()+31536000, »
'/', 'yourdomain.com', '0');
header("Location: $HTTP_REFERER");
?>
link:
<a href="./switcher.php?set=red">
click here to change to RED style!</a>
style reference:
<link rel="stylesheet" type="text/css"
media="screen" title="User
Defined Style" href="<?php echo
(!$sitestyle)?'defaultstyle':$sitestyle?>.css" />
ive checked the code so many times without finding anything, so any help is appreciated..
thanks
kumar
washrack.com/wasim/blog/index.php?textid=36
it will make a difference. If you are3 tring to collect the variakes one way a but your server is set up another way. Run a phpinfo() to see.
[uk.php.net...]
Then adjust your code accordingly.
found a way to get the results of the phpinfo() function, but cant say i understand cause there is so much info.
can anyone please go to the following address and tell em if glabal vars is on or off...?
i still need help to get around the problem if it is off.
thanks
kumar
[edited by: jatar_k at 5:16 pm (utc) on Oct. 27, 2003]
[edit reason] removed personal url [/edit]
Your reasoning for why is wrong actually.
$HTTP_COOKIE_VARS["skinname"]
can be used with register_globals on or off. If it is on then you can use just $skinname. If it is off you have to use the syntax above. That particular syntax is for php 4.1.0 and below, you should use $_COOKIE['skinname'] since you have 4.1.2
take a look through these
PHP Predefined Variables [ca.php.net]
redirecting based on $HTTP_REFERER is not a very reliable way to do things as it is not always present for you to use.
What exactly is the problem with the code? Where does it get to before it stops working? What behaviours are not occuring? Are you getting any error messages?
You'll have to give us a little better explanation of the situation so we can understand what exactly is happening.
well, as for code, it deosnt give me any parsing errors.
the default style that i set is working, but it does not want to change. I think there is a problem in writing the cookie. i went to the cookie folder in 'documents and settings' and could not find the cookie there even tough i ran the script. so that seems to be the problem.
by the way how can i avoid using $HTTP_REFERER?
thanks for the edit jatar_k
kumar
serialize [ca.php.net] and unserialize [ca.php.net] for storing more complex data in the cookie.
sessions [ca.php.net] instead of cookies.
actually storing the pagename in either the cookie or the session to avoid the use of referrer.
i was just going trought he original code agaon, and found out that the cookie is not being set. i use a different script as well for the same skining purpose, suiing radio buttons to pass a var to the script, code as follows:
form:
<form action="setcookie.php3" method="post">
Choose preferred skin:<br /><br />
<input type="radio" name="skin" value="wolf.css">Wolf<br />
<input type="radio" name="skin" value="accguitar.css">Guitar<br />
<input type="radio" name="skin" value="watch.css">Time<br /><br />
<input type="submit" name ="button" value="Enter Site">
</form>
script:
<?php
$skin = $_POST["skin"];
setcookie("skinname",$skin,time()+7200);
header('location:http://url/welcome.php3');
?>
now the above works fine, and the cookie is set.
anu explanation to why this wors while the initial code i posted does would be appreciated, as not understanding this is driving me nuts!
initial code:
<?php
$set = $_GET['set'];
setcookie('sitestyle',$set, time()+7200, '/', 'my_url');
header('Location: '.$_SERVER['HTTP_REFERER']);
?>
im checking out the recomendations u made, thanks...
kumar