CURL Login

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
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

CURL Login

Post by SidewinderX »

Ive created a script to login to a site which works fine, but when I login, that site has an iframe I want to grab data from. The problem is the iframe displays a 404 error because the file it is looking for is account.php which is not on my server, but the server i am logging into.

Using my script, how can I get access to the file thats in the iframe?

Code: Select all

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/");
curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/");

curl_setopt($ch, CURLOPT_URL, $host."/myaccount.php?");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "login_username=".$username."&login_password=".$password."");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_exec($ch);
curl_close ($ch);


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

Post by feyd »

Provide a full path to cURL.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

Well $host is the full name of the place I'm trying to login to, in essence

$host = "http://www.extreme-hq.com/test";

Is that what you mean?
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

Well I know the answer feyd posted above is the correct one (when is he ever wrong :?: :P ) But as usual I have no idea what he means, usually I can figure it out by playing with it and googleing for a while but I'm stumped, can someone translate / elaborate on that for me?

Thanks
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

What is the URL that you are trying to CURL?

Post by afbase »

What is the URL that you are trying to CURL?
^^^^^I believe this is what feyd was asking^^^^^


I'm no expert but maybe you need to put a "?" at the end of your $host url
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

No, I'm not asking anything.

There are two URLs involved in this problem:
  1. the login
  2. the frame
You must supply a fully-qualified URL to cURL so it may load each.

The resulting page from calling the login URL should be analyzed by the script to verify a correct login. Only upon success should it continue to attempt to fetch the frame providing that server with the produced credentials in any cookies it may have set.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

Where / How do you supply a fully-qualified URL to cURL so it can load each?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Note the CURLOPT_URL in the code you've posted in this thread already.
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Post by afbase »

why not set the host as follows?

Code: Select all

$host = "http://www.extreme-hq.com/test/myaccount.php?";
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

And why are you tacking on a ? to the url when you are posting the variables?
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

afbase wrote:why not set the host as follows?

Code: Select all

$host = "http://www.extreme-hq.com/test/myaccount.php?";
I suppose I could, but that dosnt change much, just makes it better looking afaik
AKA Panama Jack wrote:And why are you tacking on a ? to the url when you are posting the variables?
I have no idea, I suppose it is redundant but the login part works, does that effect the iframe?
Post Reply