SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Curl Cookie problem

    okay, im trying to make a script to login on a site, then click some links on the site and fill some forms. but after the login, it lose the cookie, says cookie not found

    my code is following

    PHP Code:
    <?php

     
     
    // Settings

        
    $account "finlove"// Please set your BSG id 
        
    $password "xxxx"// Please set your BSG id password
        
    $cookie_file_path "/tmp/curl_cookies"// Please set your Cookie File path
        
    $reffer "link/bsgid/main.php?login=1";
        
    $POSTFIELDS "account=$account&password=$password";
        
    $LOGINURL "linkbsgid/main.php?login=1";
        
    $agent "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
        
        
    $ch curl_init(); 
        
    curl_setopt($chCURLOPT_URL,$LOGINURL);
        
    curl_setopt($chCURLOPT_USERAGENT$agent);
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1); 
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_COOKIEFILE'cookie.txt');
        
    curl_setopt($chCURLOPT_COOKIEJAR'cookie.txt');
        
    $result curl_exec ($ch);
        
    curl_close ($ch);
        
    // 2- Post Login Data to Page linkbsgid/main.php?login=1


        
    $ch curl_init(); 
        
    curl_setopt($chCURLOPT_URL,$LOGINURL);
        
    curl_setopt($chCURLOPT_USERAGENT$agent);
        
    curl_setopt($chCURLOPT_POST1); 
        
    curl_setopt($chCURLOPT_POSTFIELDS,$POSTFIELDS); 
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1); 
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_REFERER$reffer);
        
    curl_setopt($chCURLOPT_COOKIEFILE'cookie.txt');
        
    curl_setopt($chCURLOPT_COOKIEJAR'cookie.txt');
        
    $result curl_exec ($ch);
        
    curl_close($ch);
        print 
    $result;

    // 3- Get Money reward    
        
        
    $ch curl_init();

        
    curl_setopt($chCURLOPT_COOKIEFILE'cookie.txt');
        
    curl_setopt($chCURLOPT_COOKIEJAR'cookie.txt');
        
    curl_setopt($chCURLOPT_URL,"link/rewards.php?s=XXXX&reward1=true");
        
    curl_setopt($chCURLOPT_RETURNTRANSFER,1);
        
    $result1=curl_exec ($ch);
            
    curl_close($ch);
        print 
    $result1;
        
        

    ?>
    i have been trying to solve this problem for long time now but no luck any help please.

  2. #2
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try setting 'CURLOPT_COOKIESESSION' to TRUE

    Failing that:

    Perhaps when you issue a curl_close, it destroys the cookie file?

  3. #3
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    same error.

    i talked with 1 guy who have maded a bot for same game in excel, and he knew other who made bot using curl.

    he said i should use multithread and keep session open all time, but im little bit lost atm.

    the code i made login succsfully but on second page the cookie/session is lost. how do i keep the session open ?

    i know the script should be pretty simple but i just cant get it work

    i want the script to fetch 4 pages and fill forms there.

    [16:40] texgalaxy: the main issue omni had with his was getting multithread to work and for the server to auto login based on time constraints. some hosting companies do not allow software to generate actions from the server. so omni hosts his at home.
    [16:41] texgalaxy: yeah do not close a session. you need to learn multi threading on curl and always keep sessions open

  4. #4
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Lovsan View Post
    same error.

    i talked with 1 guy who have maded a bot for same game in excel, and he knew other who made bot using curl.

    he said i should use multithread and keep session open all time, but im little bit lost atm.

    the code i made login succsfully but on second page the cookie/session is lost. how do i keep the session open ?

    i know the script should be pretty simple but i just cant get it work

    i want the script to fetch 4 pages and fill forms there.
    Well what he probably means is that you do not do a 'curl_close ($ch);' but simply use 'curl_setopt()' to change fields which need changing (URL/POST data etc) and then do 'curl_exec ($ch);' and repeat. Closing your session at the end when everything is done.

    This way COOKIE data should be preserved throughout the CURL session. Providing that it works initially on the first page (which you say it does).

    Good luck and tell us how it works out, I'm interested in doing a similar thing myself.


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
  •