Jump to content

how to display a webpage logged in via a cURL request in an iframe


arianhojat

Recommended Posts

Bascially i use cURL to log into a website, but i want to display that website in an iframe on my php page.

 

anyway to do this?

 

iframe's src is the web address but i need to login to the webpage be4.

 

I will test later, but maybe the curl code which logs in will set the cookie, and i dont need to worry about it and can just supply url to want to goto. Any params I need to worry about for the cookie?

 

Link to comment
Share on other sites

I actually wrote the code to do this the other day. Have this as your iframe's src page:

 

iirc, you'll need to make a cookie.txt file that has 777 permission

 

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

$url = 'the login pages url ';
$cookieFile = 'cookie.txt';
$ch = curl_init();   
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);   
curl_setopt($ch, CURLOPT_HEADER, 1);   
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");   
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);       
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);   
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'the post fields go here, ie username and password');
$result = curl_exec ($ch);
curl_close ($ch);

$url = 'the page you want to load once you are logged in.';
$ch = curl_init();   
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);   
curl_setopt($ch, CURLOPT_HEADER, 0);   
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");   
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);       
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);   
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec ($ch);
curl_close ($ch);

print $result;

?>

Link to comment
Share on other sites

Hey jesirose,

had a few questions...

 

1. this is the easy question i think:

why set HEADER to 1 1t first, i assume cause cookies are stored in session and you want them to goto login script :), so you have to explicitly say so? other curl cookie examples i saw didnt have HEADER set to 1, so i assume this was to be explicit.

 

2. next question :) :

just curious why did u set Header to 0 so it doesnt send header to next url once logged in?

just wondering why it hurts to include header?, in fact it seems like you should so u can 'pass along on cookie info' to next page so the next page knows you are signed in. no yes?

 

and

3. i guess maybe the SSL optins i wasnt sure what they were for either.:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 

 

 

thanks so much for your help!.

Ari

 

Link to comment
Share on other sites

To answer the header questions, I don't really know. I hacked this together from the comments on php's manual and some other examples around the net. You could try messing with the header lines to see how it affects the code when you change it to 0 or 1.

 

the SSL is because my original example was an https page - you can remove those if your login page is not on ssl, https.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.