Tuesday, January 8, 2013

Empty $_SESSION after PHP redirect using GET or CURL (not browser)


Empty $_SESSION after PHP redirect between 2 scripts, the first script is called using GET or CURL (not browser)


1- Call "script1" using GET or CURL
2- "Script1" starts/fills session X, does some logic, redirect to "Script2"
3- In "Script2", print_r($_SESSION) is empty


I found that the SESSION in "Script2" is a NEW session, let's call it:Session Y , since Session X was not transferred in HTTP header in the redirect

So it seems that the SESSION information transfer in headers was being done by the browser and it is not done by GET or CURL command line, 

So we need to do it instead

Step 1:

In Script #1, change the redirection to be 


SID is a constant containing the following


Step 2:

In script #2, start the script with the following


So you are telling the script to load Script1's session

That's it

Final note 

You may have a different issue too, check this post



Redirect PHP command line new $_SESSION  GET session_id start_session browser PHPSESSID cookie  CURL  Set-Cookie HTTP header

No comments:

Post a Comment