PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello to all. Yesterday I came across an issue where I can't execute cookie set properly on the server. It works locally though without no problems. The domain's path is "/tmp" for session_path. Here's the code. Thanks for comments:
if (!isset($_COOKIE['TestCookie'])) {
$vote_com2 = mysqli_query($connect,"UPDATE news SET up = '".$upv."' WHERE news_id = '$idn'" );
setcookie("TestCookie", $idn, time()+3600,"/",".mydomain.net");
}
This may be obvious, but is the code being run on a subdomain of "mydomain.net" (which I assume is just a dummy domain for the purposes of posting here)?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Hi - yes it's a dummy domain. The cookie runs on the main domain i.e. ( not on subdomain ). For now I've referred to using $_SESSION instead - helps for as long as the browser is on. But cookie is the proper way for this feature..
Is the time() correct? If time() on the server is an hour or more behind your computer's clock, it would be invalid.
There's an extension you can get for Firefox that captures http headers (which is what is used to set cookies). You can use that to check if the proper headers are being sent to your computer.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.