0

I am searching 3 days for an answer and I cannot find one because I always find some obstacles.

I need to load a web page (the reason for this is to accept a cookie) and then at the same time read the source code of the new page without hitting it again. The reason for this is that the page is dynamic so the content will change.
I have tried to do this using iFrame(document.body.innerHTML) but the fact that these pages run on different servers I hit cross-site scripting issues.
I have also tried writing a php script using get_contents but this doesn't allow the cookie to be stored in my local.

This is driving me crazy.... Any suggestion will be helful! Need to use PHP or Javascript for this and any other suggestion will be useful as well.

Nidis
  • 145
  • 1
  • 10

2 Answers2

0

When you are on the page document.body.innerHTML will give you the page source.

Edit: I didn't realize you were loading it like that. See this SO question.

Community
  • 1
  • 1
Kyeotic
  • 19,697
  • 10
  • 71
  • 128
  • The page I want to load is not mine so I cannot add this to the page. If I use this from another page I will get cross-site scripting errors – Nidis Jun 28 '12 at 15:51
  • How is this going to help me. If I understood well this will reutrn the contents but not hit the page. – Nidis Jun 28 '12 at 16:12
0

It can be done using cURL in PHP.

A rough implementation:

$ch = curl_init('http://www.google.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$data = curl_exec($ch);
preg_match('/^Set-Cookie: (.*?);/m', $data, $cookies);

var_dump($cookies);
var_dump($data);

$data will contain the entire response, so we need to parse out the cookie headers ourselves.

If available on your system, HttpRequest would make this easier.

pixelistik
  • 7,541
  • 3
  • 32
  • 42