SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    how to use same request with curl

    Hi

    i have login via curl ,after successful login i couldnt get home page content via curl once successful login ,it again said to login. how to maintain session and cookie when calling a api via curl. can anyone give a solution .


    PHP Code:

    $ckfile 
    tempnam ("/tmp""CURLCOOKIE");
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_COOKIEFILE$ckfile); 
        
    curl_setopt($chCURLOPT_URL,$url);    
        
    curl_setopt ($chCURLOPT_COOKIEJAR$ckfile);  // The name of a file to save all internal cookies to when the connection closes
        
    curl_setopt($chCURLOPT_HEADER,0); // TRUE to include the header in the output.    
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($ch,CURLOPT_AUTOREFERER,1);
        

        echo 
    $result curl_exec($ch); //execute curl and store data in result 

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Location
    Perundurai, Tamilnadu, India
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try Follow Location as 1, this might fix your problem

    PHP Code:
    curl_setopt($chCURLOPT_FOLLOWLOCATION1); // it will follow with server redirects 

  3. #3
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tamilsuresh View Post
    Try Follow Location as 1, this might fix your problem

    PHP Code:
    curl_setopt($chCURLOPT_FOLLOWLOCATION1); // it will follow with server redirects 
    if i login via one browser it was working fine, if i login via some other brower means it take cookie previously stored in the text and logged with the same user. how to avoid.

    how do to do like separate cookie for each browser. if we login one account via firefox in gmail ,we may login in gmail with another account in chorme or some other browsers. i want to do like that with curl . how to manage cookie and session when calling a url with curl


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
  •