|
Posted by shimmyshack on 03/21/07 17:07
On 20 Mar, 21:00, "Thorak" <diving...@gmail.com> wrote:
> Im having a wierd problem with one of my php scripts opening a socket
> connection with session variables. My page is continualy returning
>
> Fatal error: Maximum execution time of 30 seconds exceeded in "bla bla
> bla" line 43
> line 43 is: $html .= fgets($fp, 4096);
>
> The thing is this code below works for me if i remove the line:
>
> $Headers .= "Cookie: ".$Cookie."\r\n";
>
> problem is then i don't have my session data filling in the form
> fields. As soon as I add this line so that the form fields can get the
> information needed then i get this Maximum execution error.
>
> I know im getting a result for: $Cookie = $_SERVER["HTTP_COOKIE"]
> cause of the echo that is returned and does match the echo of the
> session on all my other scripts.
>
> I have tried using things like: stream_set_timeout($fp, 60); to
> control this - but they dont seem to do anything. And changing the:
> $fp = fsockopen($URL, 80, $errno, $errstr, 30); to $fp =
> fsockopen($URL, 80, $errno, $errstr, 120);
>
> /*
> //==================================
> //==============================
> */
> session_start();
>
> $URL = "vinyl-design"; // localhost network connection
> $Cookie = $_SERVER["HTTP_COOKIE"]; // gives
> "PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1"
>
> $Page = 'interface2/order_details.php';
>
> $fp = fsockopen($URL, 80, $errno, $errstr, 30);
>
> // check if the website is found
> if(!$fp) {
> echo 'Failed opening socket connection!<br>'.$errstr.'('.
> $errno.')';
>
> }
>
> else {
> // write to the http server
> $Headers = "GET /".$Page." HTTP/1.1\r\n";
> $Headers .= "Host: ".$URL."\r\n";
> $Headers .= "Content-Type: text/html\r\n";
> $Headers .= "Cookie: ".$Cookie."\r\n";
> $Headers .= "Connection: Close\r\n\r\n";
> fwrite($fp, $Headers);
>
> // read the website
> while(!feof($fp)) {
> stream_set_timeout($fp, 60);
>
> // store the html into a variable
> $html .= fgets($fp, 4096);
>
> $info = stream_get_meta_data($fp); // get any error
> information
> while reading the data
>
> if ($info['timed_out']) {
> echo 'Connection timed out while trying to
> read data!';
> }
> }
> fclose($fp);
>
> }
>
> echo $html;
>
> /*
> //==============================
> //==================================
> */
Use a proper fully qualified domain name not some vinyl-server host.
change the hosts entry and use the REAL host you are going to use.
Try sending a list of proper headers.
Why are you sending
$Headers .= "Content-Type: text/html\r\n";
and
$Headers .= "Connection: Close\r\n\r\n";
typically thats what the server sends your user agent,
and also do you know what requirements the servrer application has in
terms of headers, use a proxy and browse round while logged in and
then copy the headers that are sent by your browser into your script.
They might look something like
$eol = "\r\n";
$Headers = "GET /".$Page." HTTP/1.1".$eol;
$Headers .= "Host: ".$URL.$eol;
$Headers .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT
5.1; en-GB; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3".$eol;
$Headers .= "Accept: */*".$eol;
$Headers .= "Accept-Language: en-GB,en,fr-MC;q=0.9,fr;q=0.9,it-
IT;q=0.9,it;q=0.8,fr-FR;q=0.8,de-DE;q=0.8,de;q=0.7,en-US;q=0.7,pl-
PL;q=0.6,pl;q=0.6,zh-SG;q=0.6,zh;q=0.5,pt-PT;q=0.5,pt;q=0.5,hu-
HU;q=0.4,hu;q=0.4,sv-FI;q=0.4,sv;q=0.3,es-ES;q=0.3,es;q=0.3,nl-
NL;q=0.2,nl;q=0.2,nl-BE;q=0.1,it-CH;q=0.1,en-ZA;q=0.1,en-us;q=0.0".
$eol;
$Headers .= "Accept-Encoding: gzip,deflate".$eol;
$Headers .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7".$eol;
$Headers .= "Keep-Alive: 300".$eol;
$Headers .= "Proxy-Connection: keep-alive".$eol;
$Headers .= "Referer: http://".$URL."/".$Page.".$eol;
$Headers .= "Cookie: PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1".$eol.
$eol;
also be careful when posting your session ID, if your IP can be
guessed, people can easily make a connection to your application if
you allow public connections and use it as you, with annoying results.
[Back to original message]
|