get source of page in another domain

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
cwings
Forum Newbie
Posts: 5
Joined: Sun Jan 29, 2006 10:58 pm

get source of page in another domain

Post by cwings »

i have the code
<?php
$cwings="";
$str_in = file_get_contents("http://www.somesite.com/somepage");
$cwings = substr($str_in, 0, 15000);
echo $cwings;
?>
for somesite.com/somepage i want to be able to echo the value of the page for when your logged in, otherwise it just echos the signin page for the site. is there a way to make it get the source of a page that your logged into and with your own session and echo it back?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

You will need to send a login cookie with http://www.php.net/curl
cwings
Forum Newbie
Posts: 5
Joined: Sun Jan 29, 2006 10:58 pm

Post by cwings »

but is there a way to echo it if your already logged into somesite.com without having to relogin with a new cookie?
like getting it from a current session
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

The reason that page sees you as logged in is because of the session cookie. If you do not send a cookie that page will not see you as logged in
cwings
Forum Newbie
Posts: 5
Joined: Sun Jan 29, 2006 10:58 pm

Post by cwings »

could i make a temporary session cookie?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

log into the site from your browser, grab the cookie with javascript:alert(document.cookie);


This is the cookie you want to send with CURL
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

cwings wrote:could i make a temporary session cookie?
All session cookies are temporary.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

onion2k wrote:
cwings wrote:could i make a temporary session cookie?
All session cookies are temporary.
Unless appended to the url :wink:
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Jcart wrote:
onion2k wrote:
cwings wrote:could i make a temporary session cookie?
All session cookies are temporary.
Unless appended to the url :wink:
Is that a session cookie, or is it a session ID?
cwings
Forum Newbie
Posts: 5
Joined: Sun Jan 29, 2006 10:58 pm

Post by cwings »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


can you tell me why this doesnt work

Code: Select all

<?php
$id = "username";
$pw = "password";
$postfields = "username=$id&password=$pw";
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "/temp/cookie");
curl_setopt($ch, CURLOPT_COOKIE, "/temp/cookie");
curl_setopt($ch, CURLOPT_URL,
"http://somesite.com/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");
$cwings="";
$filename = curl_setopt($ch, CURLOPT_URL, "http://somesite.com/page_that_can_only_be_seen_if_logged_in");
$str_in = file_get_contents($filename);
$cwings = substr($str_in, 0, 50000);
echo $tween;
curl_exec ($ch);
curl_close ($ch); 
?>
it just returns the login page


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
cwings
Forum Newbie
Posts: 5
Joined: Sun Jan 29, 2006 10:58 pm

Post by cwings »

nevermind, i figured it out. thanks for your help though
Post Reply