soryn4u Posted July 19, 2009 Share Posted July 19, 2009 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 ??? Quote Link to comment https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/ Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/#findComment-878060 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 They work on the HTTP protocol only so if you run the cron job via HTTP, cookies will work. Quote Link to comment https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/#findComment-878067 Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 if you run the cron job via HTTP via HTTP? Is this possible? But then how will it then store a cookie in his temporary directory so his browser can read it? Quote Link to comment https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/#findComment-878074 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Place the file within document root, then call it sort of like this: wget http://something/script.php --save-cookies cookies.txt --load-cookies cookies.txt -O /dev/null Quote Link to comment https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/#findComment-878078 Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 Place the file within document root, then call it sort of like this: wget http://something/script.php --save-cookies cookies.txt --load-cookies cookies.txt -O /dev/null Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/166501-cookies-and-cronjob/#findComment-878083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.