Jump to content

cookies and cronjob


soryn4u

Recommended Posts

dosent work cookies with cronjob?

 

i make a file cookie.php

 

and i put this code

 

<?php
setcookie("user", "ADMIN");

if (isset($_COOKIE["user"]))
    
    echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
   echo "Welcome guest!<br />";
?>

 

and i run cronjob

 

*/1 * * * * public_html/cookie.php

 

 

and the result is : Welcome guest!<br >

that means the cookie not set up!!

 

How to make cookie works with cronjob ???

Link to comment
https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/
Share on other sites

You have to look at it this way: If I add a cookie to my cookie jar can you then eat my cookies? (Yes if you know where I live and where I keep the cookie jar) ;) The same goes for what you are trying to do, your cron job does "nothing" (it does something but not the expected behavior as you see it) when it comes across the cookie.

 

"Certain functions, such as those dealing with cookies, are not really applicable for command-line use, but others such as database access and XML parsing certainly are." -- http://articles.techrepublic.com.com/5100-10878_11-6043428.html

 

The reason for this is because you probably don't understand what a cookie actually is. A cookie holds a piece of information for a given domain on your local hard drive (usually in the temporary internet files). This cookie is created whenever your browser receives a Set-Cookie response header and is removed when it's time-to-live (TTL) expires, all managed by your browser. And because your browser is in no way involved in the cron-job process it will also never store a cookie. And thus by declaring this line of code:

setcookie("user", "ADMIN");

did you in theoretical terms make your cron-job (read server) an administrator ;)

Link to comment
https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/#findComment-878060
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.