note 72608 modified in ref.curl by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 19:19:44 +0000 |
| Subject: | note 72608 modified in ref.curl by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155224@lists.php.net to get a copy of this message | ||
Using curl to take snapshots of the current page for emailing the HTML is a clever little idea. (ie:
Email this page to a friend)
<?php
//to be explained below!
session_write_close();
$pageurl = "http://www.site.com/content.php?PHPSESSID=123XYZ
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $pageurl );
$html = curl_exec ( $ch );
curl_close($ch);
//then you need to fix pathing to absolute
$search = "/(src|href|background)=\"[^:,^>,^\"]*\"/i";
preg_match_all ( $search, $html, $a_matches );
//you can figure out the rest ! but thought the reg expression is useful as well
?>
But here is the catch, you may want to make sure curl connects to the server under the same session
as the browser. So naturally you pass the session cookie through the curl system either by the
cookie jar system, or through the query string in the path.
This is where you will get stuck. PHP will need write access to the same session file
simultaneously!! causing serious hanging issues!
This is why you should close off your session before you make curl take a page snapshot!
--was--
Using curl to take snapshots of the current page for emailing the HTML is a clever little idea. (ie:
Email this page to a friend)
//to be explained below!
session_write_close();
$pageurl = "http://www.site.com/content.php?PHPSESSID=123XYZ
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $pageurl );
$html = curl_exec ( $ch );
curl_close($ch);
//then you need to fix pathing to absolute
$search = "/(src|href|background)=\"[^:,^>,^\"]*\"/i";
preg_match_all ( $search, $html, $a_matches );
//you can figure out the rest ! but thought the reg expression is useful as well
But here is the catch, you may want to make sure curl connects to the server under the same session
as the browser. So naturally you pass the session cookie through the curl system either by the
cookie jar system, or through the query string in the path.
This is where you will get stuck. PHP will need write access to the same session file
simultaneously!! causing serious hanging issues!
This is why you should close off your session before you make curl take a page snapshot!
http://php.net/manual/en/ref.curl.php