简体   繁体   中英

PHP - Snoopy POST request + maintain SESSION?

Using Snoopy I make a request, but it seems that a different SESSION is used for the POST? When I echo the results of the request the SESSION is set but after clicking any link the page returns to a non SESSION-set state.

Currently i'm using this code to make the request

$dashboard = new Snoopy;

$dashboard->referer = "URL";
$dashboard->httpmethod = "POST";
$dashboard->submit("URL", $_POST);

echo $dashboard->results;

I don't have the ability to use cURL as I have no control over the server.

I have a feeling its due to Snoopy making a new SESSION_ID for the HTTP POST? i've seen bits but nothing concrete on how to maintain SESSION between these requests?

You need to call the session_start function in submitting url file.

so , session can maintain as you want.

If you don't pass the SESSIONID to the page you are calling with Snoopy (this would be true for any other way of doing that HTTP request) , then, when generating that page, PHP will :

  • try to start a session
  • as no session id has been received, an new session will be started
  • which will be distinct from the one used in your first script.


If you want both scripts to share the same session, you will at least have to pass the session id to the second script -- which is generally done using a cookie (see the cookies you have for your site, in your browser) .

Basically : the script that's called via Snoopy has to receive the session id, the same way the script that's called by your browser receives it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM