Forum Moderators: coopster
please help me if you know what could be the problem, I have no idea what is wrong here.
I have this code in the Santy template page:
{php}if (!isset($_COOKIE["pageterms"])) {
$termscheck = "<script language=\"Javascript\" src=\"popup.js\"> </script>";
// print $termscheck;
print "hello";
}
{/php}
It always prints "hello", even if the cookie is there. If I place the same code in the main page, not the template, it will work, but I must run the javascript in the <body> tag. If I let the code run in the main page, not the template, it will display the $termscheck before or after <html></html>
I hope I was clear in my explanation. Can anybody help me please?
Yours truly,
Alin
Then // (as in c and c++) means a comment
So
if (!isset($_COOKIE["pageterms"])) {
$termscheck = "<script language=\"Javascript\" src=\"popup.js\"> </script>";
// print $termscheck;
print "hello";
As you see this script has to show hello. If you want it to write the javascript then uncomment that line and comment hello like this:
<?php
if (!isset($_COOKIE["pageterms"])) {
$termscheck = "<script language=\"Javascript\" src=\"popup.js\"> </script>";
print $termscheck;
}
?>
And that's all
Best regards and have a good time learning php
Michal Cibor
PS. Welcome to WebmasterWorld!
Thanks for answering and your welcome, I can see it's a great forum :)
I'm afraid though that you missunderstood me.
In the Smarty template system, embedding php code in a template page is done with {php} {/php}. This is not a regular php page, it's integrated in Smarty. What Smarty does is compile the pages and caches them, so when the user accesses the page a second time, if nothing was changed, the php will be speared of parsing the code again. I'm new to Smarty, I just have to integrate these few lines, I don't know much about it.
Also, I know I put that line as a comment, I just put "print "hello"" there as a test. The problem I'm having is that the code doesn't read the cookie - it will always print "hello", no matter if the cookie is set or not.
If I put the code in a regular page, it will read the cookie normally, so I'm guessing this is something from Smarty.
I seached the net for embedding php code in Smarty but didn't find anything that refers to handling cookies. It should work as any other php code embedded, but it doesnt.
Thanks again.
Alin
I finally understood why I was having the problem. Smarty caches the parsed php code and only updates the page when there are changes (I think). So when I included the code it only worked for the first time, then nothing.
This saves lots of server resources but it seems it can cause problems to people that don't know how it works - like me :)
I think that's the answer to the problem, I'm currently trying to find a way around this :)
Cheers
PS: Just noticed I posted "Santy" instead of "Smarty" in the thread name. argh.