Jump to content

Archived

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

phpFavs

Session with cURL

Recommended Posts

Hi,

 

I am having trouble with my cURL call because when I run the exec method I loose my current login state in the session.  I have tried the two options below, but they have yet to succeed.  If there is anything else you want me to tell you that will help you understand my issue, please let me know.

 

    $sessionfile = fopen("sessionfile.txt", "w");

    fputs($sessionfile, session_encode( ) );

    fclose($sessionfile);

    $c->setopt(CURLOPT_COOKIEFILE, $sessionfile);

    $c->setopt(CURLOPT_COOKIEJAR, $sessionfile);

 

    $sessName = session_name();

    $_COOKIE[$sessName] = session_id();

    $_COOKIE['aud_logged_in'] = Session::isLoggedIn();

    session_write_close();

    $c->setopt(CURLOPT_COOKIE, $sessName."=".$_COOKIE[$sessName].";");

 

 

Share this post


Link to post
Share on other sites

Do you want to make a curl request back to your own webserver, and use the same session in that curl request?

Share this post


Link to post
Share on other sites

Just a note with sessions... I have notice with PHP sessions cant go between sub domains... So like lets say you login to http://www.mysite.com/home.php and lets say the person who made the site made their home link to http://mysite.com/home.php the session will be lost. So maybe you logged into www.mysite.com but are trying to connect in cURL to mysite.com, I could see the session being lost like that.

Share this post


Link to post
Share on other sites

Just a note with sessions... I have notice with PHP sessions cant go between sub domains... So like lets say you login to http://www.mysite.com/home.php and lets say the person who made the site made their home link to http://mysite.com/home.php the session will be lost. So maybe you logged into www.mysite.com but are trying to connect in cURL to mysite.com, I could see the session being lost like that.

 

You can always do

 

ini_set (' session.cookie_domain', 'yoursite.com');

Share this post


Link to post
Share on other sites

×

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.