tags:

views:

364

answers:

2

hello, i am new to cron jobs and i have done much searching on this topic but i couldn't understand it fully. can cron jobs access cookies or session variables?

thanks!

+2  A: 

A cron job won't be able to access cookies, since by definition it is not being invoked from a web browser request. Only the web browser stores a cookie, which contains the session id. No web browser, no cookie, no session.

Having said that, if you do know the session id somehow, you should be able to start the session manually by feeding the id into session_id() before using session_start().

deceze
And that is only if the session still exists. A cron job running, say, hour or days later will probably try to load a session that doesn't exists anymore.
Carlos Lima
A: 

There is a project called pseudo cron that i suppose would be able to access session and/or cookies. But it would make no sense to me.

Peter Lindqvist
Not really. By running from an actual request, it "sees" the cookies from the person requesting the page at that exact moment, not the cookies from the person whose cron-job you're running.The same restriction @deceze cite would apply here. You'd need to know beforehand the *session_id* and use it to start a session. Which them makes pseudo-cron not a good option unless you can't use cron.
Carlos Lima
Yes, you're right. But I thought it was relevant since the question made no reference to which particular session to access. But given you want to access a session with a known session id the answer from deceze would be accurate.
Peter Lindqvist