hello... i have been working on this for 2 days with no use. It is giving me a hard time. I reduced the code to 3 lines so i can work with it.
I am trying to set php cookie inside JS. Any commments are greately appreciated.
the code follows:
echo "<script language=php type=text/php>";
echo "setcookie(\"hacp_rfp\", 'aa:dd:vv', '1043789457' , \"/\");";
echo "</script>";
and i also tried the followiong but also with no use.....
echo "<script language=php type=text/php>";
setcookie("hacp_rfp", 'aa:dd:vv', '1043789457' , "/");
echo "</script>";
to make sure that the content of the values are current, i tried it as a PHP code and this one WORKS fine:
$lifetime = time()+3600;
setcookie("hacp_test", "aa:bb:cc" , $lifetime, "/");
echo $lifetime;
trying to setcookie inside JS but no use
Moderator: General Moderators
-
PingLeeQuan
- Forum Commoner
- Posts: 58
- Joined: Tue Sep 03, 2002 8:08 am
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
PHP is server side not client side so you can't use PHP functions within Javascript which is client side.
Have a read of:
viewtopic.php?t=1030
Mac
Have a read of:
viewtopic.php?t=1030
Mac
-
PingLeeQuan
- Forum Commoner
- Posts: 58
- Joined: Tue Sep 03, 2002 8:08 am
Thanks twigletmac for your response. Actually i already read the article and it make sence to me--good explanation--.
May be this is a dumb question, but i am using PHP script. Doesn't PHP Script have access to php functions? I know it is still a client side scripting...the reason i am asking is i tried many things in PHP script and they worked fine. (i.e DB read insert....loading)
May be you can shed some light on this for me.
thanks again
May be this is a dumb question, but i am using PHP script. Doesn't PHP Script have access to php functions? I know it is still a client side scripting...the reason i am asking is i tried many things in PHP script and they worked fine. (i.e DB read insert....loading)
May be you can shed some light on this for me.
thanks again
When you write php script, it is executed before the page is rendered on the user's page. Javascript, on the other hand, is executed *after* the page is rendered.
In the example you posted above, it should work correctly BUT you need to change it so that it says it is type javascript, rather than PHP. But since you are explicitly telling it exactly what javascript you want, you may as well write it in the HTML/Javascript side.
In the example you posted above, it should work correctly BUT you need to change it so that it says it is type javascript, rather than PHP. But since you are explicitly telling it exactly what javascript you want, you may as well write it in the HTML/Javascript side.