The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. October 16, 2019, 04:48:10 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Curl and Cookies  (Read 2241 times)
Keebler
Rookie
**
Offline Offline

Posts: 18


View Profile
« on: August 10, 2009, 05:15:11 PM »

So I actually copied a old code I found on this site, which logged into facebook.

Code:
<?php
  $cookie_file_path 
"cookie.txt";
   
       
    
$fp fopen($cookie_file_path,'wb');   
    
fclose($fp);
   
    
$agent "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7";
    
$reffer "http://www.facebook.com/login.php";
       
       
         
$ch curl_init();
        
curl_setopt($chCURLOPT_URL,"https://login.facebook.com/login.php");   
        
curl_setopt($chCURLOPT_USERAGENT$agent);
        
curl_setopt($chCURLOPT_COOKIEFILE$cookie_fie_path);
        
curl_setopt($chCURLOPT_COOKIEJAR$cookie_file_path);
        
curl_setopt($chCURLOPT_REFERER"http://www.facebook.com/login.php");
        
curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
curl_setopt($chCURLOPT_HEADER1);
        
curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
        
curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
        
curl_setopt($chCURLOPT_POSTFIELDS"charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&locale=en_US&email=&pass=&pass_placeholder=&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&lsd=");
       
          
$html curl_exec($ch);
          echo 
$html;
?>

I am running the script locally off a xampp server I set up. and I cant get the cookie.txt file to be populated with any data.

any ideas as to what I am doing wrong or what I need to do different because its on xampp?
Logged

No links in signatures please
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: August 11, 2009, 05:10:50 AM »

In windows, you need to give the full path to the cookie file, I think.

I am not positive, but I think I heard that somewhere. I don't use Windows so I'm kind of guessing.
Logged

hai
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #2 on: August 11, 2009, 06:13:48 AM »

I do this all the time with perl and I just use a path like you have.

In your code, I see open and close, but don't you need some sort of "read"?

Also, 'wb' is write only, binary?


Also, you should be able to open the cookie file with a text editor and see if
it has anything in it.


Bompa
Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
Keebler
Rookie
**
Offline Offline

Posts: 18


View Profile
« Reply #3 on: August 11, 2009, 09:53:54 AM »

In windows, you need to give the full path to the cookie file, I think.

I am not positive, but I think I heard that somewhere. I don't use Windows so I'm kind of guessing.

Ah. This was basically correct. I had the script in a subfolder of my Xampp htdocs folder. So instead of cookies.txt in the script, I needed foldername/cookies.txt

Thanks.

I appreciate the help.
Logged

No links in signatures please
Keebler
Rookie
**
Offline Offline

Posts: 18


View Profile
« Reply #4 on: August 11, 2009, 03:52:54 PM »

This question also has to do with Cookies and Curl etc.


How exactly did you set it so that you could go to one page, say: facebook.com, get the cookie, and then go to another page to login

Do you have to curl_exec and then close curl after every url you visit? Then set a new url and visit exec that one?

Logged

No links in signatures please
krustee
Rookie
**
Offline Offline

Posts: 33


View Profile
« Reply #5 on: August 23, 2009, 06:07:33 AM »

This question also has to do with Cookies and Curl etc.

How exactly did you set it so that you could go to one page, say: facebook.com, get the cookie, and then go to another page to login

Do you have to curl_exec and then close curl after every url you visit? Then set a new url and visit exec that one?

If you wanted to log into two sites in the same script you need to set two different locations for the respective cookies and then just reference to the correct one when calling curl.

I think this answers your question. Just  came back to this forum after receiving perkisets mail.
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!