Sessions problem

Discussion in 'PHP' started by RxDx, Aug 1, 2010.

  1. #1
    Hello,

    I was fetching a data from membership area(using username and pw of course). I used a session ID that I got with Firebug but when it changes my script stops working.
    I need this sessionID to load up site contents and download a few files from server.
    However, I am stuck, because I don't know how to extract it.
    My code is :

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "loginpage.php"); // login
    curl_setopt($ch, CURLOPT_POSTFIELDS, "D=$D"); // variable with username and pw
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
          curl_setopt($ch, CURLOPT_HEADER, 0); 
    $reply2 = curl_exec($ch);
    curl_close($ch);
    PHP:
    What am I doing wrong? The cookie is not saved anywhere I guess and I cannot use it later to load up things I really want to get...
     
    RxDx, Aug 1, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Just asking, don't you need to use full http://domain urls ?

    
    <?php
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "http://www.domain.com/loginpage.php");
    
    curl_setopt ($ch, CURLOPT_POST, 1);
    
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=something&password=something");
    
    curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $login = curl_exec ($ch);
    
    curl_setopt($ch, CURLOPT_URL, "http://www.domain.com/membership_area.php");
    
    $members = curl_exec ($ch);
    
    curl_close ($ch);
    
    ?>
    
    PHP:
    $members, contains the HTML output of the membership_area.php page.
     
    MyVodaFone, Aug 1, 2010 IP
  3. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    I just change URLs so that no one would see actual site.
    Thanks for help. This works, but, again, it sends a variable from LOGIN.php to script/server.php containing information on WHAT to load, and sends sessionID to it. However, I have no idea how to extract it...
    Here is the cookie it POSTS to server.php

    	dp_C_dp_sid=0282d4809401ef4454e75aebd87f366c; RPC_dp_sid=0282d4809401ef4454e75aebd87f366c; dp_C_auth=9bc6b4fabc32b0ec8aa0663cbc5d2b6f; gpf_language=en-US
    PHP:
    I need to get either dp_C_dp_sid or RPC_dp_sid.

    This post request generates after I press login button and browser proceeds to member area.
     
    RxDx, Aug 1, 2010 IP
  4. Tonic-_-

    Tonic-_- Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Is it a actual session or cookie? If there is a option to stay logged in, do it with your browser if using Firecookie goto the cookie tab an export cookies from this site to a file.

    You could then use something like this.

    
    $cookie = "/home/xxxxx/cookie.txt";
    $url = "www.example.com/member.php";
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $html = curl_exec ($ch); 
    curl_close ($ch);
    
    PHP:
    I mean if its a session you can export it using FireCookie/FireBug and modify it to never expire and keep logging in so long as you don't log into the actual account again.
     
    Tonic-_-, Aug 1, 2010 IP
  5. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You are a genius! Thanks!
     
    RxDx, Aug 2, 2010 IP