Hello People..

I am using cURL to open up a web page from my page. I am giving my password and email..
but on LIVE HTTP headers a plugin by FF..it shows error 404..
it says so because the new page has a css file named "io.css"
and error 404 comes on the block trying to acess "http://mydomain.name/io.css"..
where do you think the problem might be..
any help is appreciated..!!

here is my curl code,, which i think is fine

$cookie_file = "/xxxxxxxxxxxx";
	$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
	$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
	
	$header[] = "Cache-Control: max-age=0";
	$header[] = "Connection: keep-alive";
	$header[] = "Keep-Alive: 300";
	$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
	$header[] = "Accept-Language: en-us,en;q=0.5";
	$header[] = "Pragma: "; // browsers keep this blank.
	
	$ch=curl_init(); // initialize curl handle 	
	curl_setopt($ch, CURLOPT_URL, "xxxxxxxx"); //set url to POST to 	
    curl_setopt ($ch, CURLOPT_ENCODING, "");
	curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
	curl_setopt($ch, CURLOPT_VERBOSE, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "email=xxxxxxxxxxxxxx");
	curl_setopt($ch, CURLOPT_TIMEOUT, 20);	
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11");
	curl_setopt($ch, CURLOPT_REFERER, "xxxxxxxxx");	
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	
	curl_setopt($ch, CURLOPT_COOKIEJAR,     $cookie_file);
	curl_setopt($ch, CURLOPT_COOKIEFILE,    $cookie_file);	
		
	$buffer = curl_exec($ch);	
	curl_close($ch);
	echo '##'.$buffer;

PLZ HELP

Without looking at your code, here's my code. It works flawlessly, saves cookies, everything. This should save you hours of time figuring out curl and loggin in :)

$cookie_file_path = "cookies/cookiejar.txt"; // Please set your Cookie File path
$fp = fopen("$cookie_file_path","w") or die("<BR><B>Unable to open cookie file $mycookiefile for write!<BR>");
fclose($fp); 
	
    
    $LOGINURL = "http://www.insertsitehere.com/asp/logon.asp";
    $postfields = 'user=username&Passwd=yourpassword';
    $agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
echo "Logged in";

Hey thanks for replying..
my code says "Unable to open cookie file $mycookiefile for write"..
i am doing "./xxx.txt"........i even tried "xxx.txt"
but all give the same result :(
any suggestion ?

Without looking at your code, here's my code. It works flawlessly, saves cookies, everything. This should save you hours of time figuring out curl and loggin in :)

$cookie_file_path = "cookies/cookiejar.txt"; // Please set your Cookie File path
$fp = fopen("$cookie_file_path","w") or die("<BR><B>Unable to open cookie file $mycookiefile for write!<BR>");
fclose($fp); 
	
    
    $LOGINURL = "http://www.insertsitehere.com/asp/logon.asp";
    $postfields = 'user=username&Passwd=yourpassword';
    $agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
echo "Logged in";

windows or linux?

in either case, sounds like nothing to do with cURL. more to do with opening a file or permissions on the file

Its a window..
now it does not show the message...and shows logged in..
but still i am not able to logon to that page..
on "echo $result"..the other website just appears under my page and does not login :(
Can there be any permissions set by the other site that might be blocking me from loggin in..

I have this thing due today..

Its a window..
now it does not show the message...and shows logged in..
but still i am not able to logon to that page..
on "echo $result"..the other website just appears under my page and does not login :(
Can there be any permissions set by the other site that might be blocking me from loggin in..

I have this thing due today..

Could be a few things. Like a session ID. Check the form variables on the submitted page and make sure you are using those.

you suggest making a session ID ?
I have used all variable in form like submit, login etc

Sounds like you are doing what I suggested. I didn't mean make a session variable, just making sure you are passing all variables from the login page. Make sure you are using all hidden variables.


If you are passing all login page variables, and your $cookie_file has data written to it, it is almost 100% sure it will log in.

With your browser(no code involved), make sure a cookie is being set by the web site. Almost assuredly it is. Just double check.

If it is, make sure that your cURL code is writing the same cookie. Open the $cookie_file file with a text editor and make sure it has data in it similar to what you saw in your browser.

my cookie file remains empty , but it still goes on and shows logged in..?
You are being really helpful

if it's empty, that means your cookie wont be saved. Which also means you will be able to "log in" but then wont be able to do anything from there.


The web site you are trying to log into most likely uses a session variable or cookie to keep track that the user is logged in. Since your cookie file is empty, it wont be able to continue on.


Make your cookie file work and you should be good to go.


Try something like this to make sure you can write to the file.

if (!is_writable($cookie_file_path)
{
echo "OMG my cookie file wont let me write to it!";
}

and double check that

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

both use the same file that you checked is_writable on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.