SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHPSESSID to login automatically

    Hi

    I am wanting to use file_get_contents() or curl to save a page. But i want it to work even if the user is logged in.

    I have tried the following, none of which have worked:

    1.) appending PHPSESSID=123 to the url for file_get_contents() - it seems that curl/file_get_contents have some security setting against this...
    2.)
    Code:
    session_start();
    session_id($sessionId);
    session_write_close(); //needed because otherwise it hangs
    file_get_contents($url);
    what is the standard way of doing this?

    Thanks

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Session ids change from session to session, that being said. A session is just another way of using cookies, if you do not believe that turn cookie support off in your browser and try using a session variable...
    You always have the option of using :
    bool setcookie ( string name [, string value [, int expire[, string path [, string domain [' int secure ]]]]] )
    When you visit the next page in your site or reload the current page the values set by the above function are available in $_COOKIE['mycookie'] or $HTTP_COOKIE_VARS['mycookie']
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok..i eventually manage to get it working like this:

    Code:
    $cookieStr = 'cookieVal1='.$value.';cookieVal2='.$value2.';etc='.$cookieVal;
    $c = curl_init($location);
    curl_setopt($c, CURLOPT_VERBOSE, 1);
    curl_setopt($c, CURLOPT_COOKIE, $cookieStr); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $html = mysql_real_escape_string(curl_exec($c));
    curl_close($c);
    As the user is logged in, i pass the user's user_id to this script and use that to get their information from the database and set the cookie values properly.

    Not the most secure way of doing things i must admit...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •