cUrl

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

cUrl

Post by ol4pr0 »

Hi,

I have the following question, have been busy googling and searching around but couldnt find what i need.

iniate cUrl
post fields and login -- works fine untill here.

-------- kinda confused on how to do the following.
Now the using same curl session to open another url inside the protected site.
and post other fields
logout .
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I am not exactly clear what you are asking. You may need to pass headers or maintain a cookie during the cURL session. Look in the cURL docs about those things.
(#10850)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Ok let me see if i can explain better


first page, has user and password -- this is no problem i pass have the curl follow redirect

Now i am in the main page after i logged in.
Now how do switch location once being here ?

menu has - link 1 , link 2 , link 3
I want to go to link 2, and from here use curl again to submit some data and logout !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Extract link 2 from the returned page data then request it via the same curl resource.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Let me see if i understand you correctly.

I know the link, ofcourse i could do a preg_match which is no problem at all.

So what are saying basicly.

curl_init(login page)
post fields
curl_init(second link)
post fields

I have tried something simular locally but, that didnt really work at all.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Keep trying. You may need to tweak the settings you place with cURL.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

jejeje,,

I will, now do i , or do i not close first curl session or do i just use the same curl sessoin with the new url ?

eg: $c = curl_init(firsturl)
$c = curl_init(secondurl)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If memory serves, it doesn't really matter either way as long as you set it up the same if you close it.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Ok, tried several options and cant figure this one out.

Code: Select all

$url = "full_url_login.php"; 
$ch = curl_init($url);     
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_USERPWD, "user:pass");  
$url = "url2_afterlogin.php"; 
$ch = curl_init($url);     
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$result = curl_exec($ch);  
curl_close($ch);  
echo $result; // echos 1, i am not sure if i am in second url. with fopen(sometext.txt) the file turns up empty
Am i missing something ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You didn't set it up the same.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Excuse me, ?

ps: dont u ever sleep
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"user:pass" need to be passed for each request more than likely.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Done that, no luck.

I am not trying to create some lame hotmail grabber. Just trying to automate creating email aliases.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You only need 1 call to curl_init(). Right now, you are overwritting the previous curl session.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

OK,

And how am i suppose to do that, changnig links using Curl.
Post Reply