Connecting Tech Pros Worldwide Forums | Help | Site Map

Script help

Joker7
Guest
 
Posts: n/a
#1: Mar 29 '08
Hi,
I have been using the code below for sometime and it works fine for most of
my need apart from this.
Im using it to request a page from (see code) and it keeps returning:

"Warning: file_get_contents(http://s.afnt.co.uk/df/df.aspx?a=13548&q=westend
show tickets&n=10&t=itpd1.xsl&r=) [function.file-get-contents]: failed to
open stream: HTTP request failed! HTTP/1.1 400 Bad Request in
/home/sites/test/call.php on line 46
Request failed"

Any help\pointers with this would be great.

<?php

error_reporting(E_ALL);
define('CACHEDIR', './');
$request = 'http://s.afnt.co.uk/df/df.aspx?a=13548&q=westend show
tickets&n=10&t=itpd1.xsl&r=';
$cache_filename = 'info.htm';
$cache_fullpath = CACHEDIR.$cache_filename;
$cache_timeout = 60;
$response = request_cache($request, $cache_fullpath, $cache_timeout);
if ($response === false) {
die('Request failed');
}
echo htmlspecialchars($response, ENT_QUOTES);
$file = "/home/sites/test/info.htm";

if (! chmod($file, 0776)) {
echo ("Unable to change file permissions");
}
function request_cache($url, $dest_file, $timeout=60) {
if(!file_exists($dest_file) || filemtime($dest_file) < (time()-$timeout)) {
$data = file_get_contents($url);
if ($data === false) return false;
$tmpf = tempnam('/tmp','YWS');
$fp = fopen($tmpf,"w");
fwrite($fp, $data);
fclose($fp);
rename($tmpf, $dest_file);
} else {
return file_get_contents($dest_file);
}
return($data);
}

?>


Superb hosting & domain name deals http://dn-22.co.uk
The Handyman http://www.looker.me.uk

--
Superb hosting & domain name deals http://dn-22.co.uk
The Handyman http://www.looker.me.uk



Joker7
Guest
 
Posts: n/a
#2: Mar 29 '08

re: Script help


To restore balance to the world Joker7 wrote in
TssHj.175295$8Z.97779@newsfet10.ams
Quote:
Quote:
>Hi,
>I have been using the code below for sometime and it works fine for
>most of my need apart from this.
>Im using it to request a page from (see code) and it keeps returning:
>>
>"Warning:
>file_get_contents(http://s.afnt.co.uk/df/df.aspx?a=13548&q=westend
>show tickets&n=10&t=itpd1.xsl&r=) [function.file-get-contents]:
>failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
>in /home/sites/test/call.php on line 46
>Request failed"
>>
>Any help\pointers with this would be great.
>>
><?php
>>
>error_reporting(E_ALL);
>define('CACHEDIR', './');
>$request = 'http://s.afnt.co.uk/df/df.aspx?a=13548&q=westend show
>tickets&n=10&t=itpd1.xsl&r=';
>$cache_filename = 'info.htm';
>$cache_fullpath = CACHEDIR.$cache_filename;
>$cache_timeout = 60;
>$response = request_cache($request, $cache_fullpath, $cache_timeout);
>if ($response === false) {
>die('Request failed');
>}
>echo htmlspecialchars($response, ENT_QUOTES);
>$file = "/home/sites/test/info.htm";
>>
>if (! chmod($file, 0776)) {
> echo ("Unable to change file permissions");
>}
>function request_cache($url, $dest_file, $timeout=60) {
>if(!file_exists($dest_file) || filemtime($dest_file) <
> (time()-$timeout)) { $data = file_get_contents($url);
> if ($data === false) return false;
> $tmpf = tempnam('/tmp','YWS');
> $fp = fopen($tmpf,"w");
> fwrite($fp, $data);
> fclose($fp);
> rename($tmpf, $dest_file);
>} else {
> return file_get_contents($dest_file);
>}
>return($data);
>}
>>
Quote:
>>>
>>
>>

It script did not like the gaps in the url ..

Thanks
Chris


Closed Thread