I need help with 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

Post Reply
Snix
Forum Newbie
Posts: 4
Joined: Fri Nov 16, 2007 6:39 pm

I need help with curl...

Post by Snix »

Hi there,

please if somebody can help me with a simple curl example, all i need is that the script to do the following:

enter on a website - http://example.com/index.php
get the cookies from that page
save cookie to cookie.txt
after that using the cookies enter on the http://exemple.com/newpage.php
clear cookie from file.


I will appreciate your help.

Many Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

We won't do your work for you. What have you tried so far?
Snix
Forum Newbie
Posts: 4
Joined: Fri Nov 16, 2007 6:39 pm

Post by Snix »

feyd wrote:We won't do your work for you. What have you tried so far?
Yes I have tried.

Code: Select all

<?php

$cookie_file = 'cookies.txt';
$url_1 = 'http://example.com/index.php';
$url_2 = 'http://exemple.com/newpage.php';

$ch = curl_init($url_1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);


curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, $url_2);

curl_exec($ch);
curl_close($ch);


file_put_contents($cookie_file, null);

?>
On my home computer I have apache installed and every time when I open my browser I would like this script to open automatically the ebay page and log me in. I tried to modify this script for using ebay, but i receive an error that my browser is rejecting cookies.


Thanks
Snix
Last edited by Snix on Sat Nov 17, 2007 9:57 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That appears to be fine. Does it function as you expect?
Snix
Forum Newbie
Posts: 4
Joined: Fri Nov 16, 2007 6:39 pm

Post by Snix »

feyd wrote:That appears to be fine. Does it function as you expect?

Is not working, because the ebay use ssl, and i really don't know how to make it... sorry, newbie here.

I will appreciate your help.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Dig through the user comments on http://php.net/curl_setopt, there are quite a few examples of sending to SSL enabled sites.
Snix
Forum Newbie
Posts: 4
Joined: Fri Nov 16, 2007 6:39 pm

Post by Snix »

Jcart wrote:Dig through the user comments on http://php.net/curl_setopt, there are quite a few examples of sending to SSL enabled sites.
I've just made it... many thanks.
Post Reply