Dom
Member
Registered: 13th Sep 03
User status: Offline
|
Anyone know whether this looks about right?
It should request a variable via 'p' (eg: UKXX1822), grab the XML page (eg: http://weather.yahooapis.com/forecastrss?p=UKXX1822&u=c) and then spit it back out (with the content type set to text/xml). So when requesting the page, it should be exactly the same as if you requested it from yahoo.
code:
<?php
$place = $_REQUEST["p"];
If ($place != "") {
$content = file_get_contents('http://weather.yahooapis.com/forecastrss?p='.$place.'&u=c');
if ($content !== false) {
header('Content-Type: text/xml');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($content))
print($content);
}
}
?>
Cheers 
edit -
these are the headers returned from the yahoo servers -
HTTP/1.x 200 OK
Date: Mon, 11 May 2009 09:50:35 GMT
Cache-Control: max-age=1200
Expires: Mon, 11 May 2009 10:10:35 GMT
Vary: Accept-Encoding
Content-Type: text/xml;charset=UTF-8
Content-Encoding: gzip
X-Pad: avoid browser bug
Age: 0
Transfer-Encoding: chunked
Connection: keep-alive
Server: YTS/1.17.16
[Edited on 11-05-2009 by Dom]
|
Sam
Moderator Premium Member
Registered: 24th Dec 99
Location: West Midlands
User status: Offline
|
Try changing this:
code: If ($place != "") {
to this:
code: If ($place) {
Does it work then?
[Edited on 11-05-2009 by Sam]
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
I would be checking $place is set first - echo it.
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
cheers for the help, have managed to sort it
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
quote: Originally posted by Ian
I would be checking $place is set first - echo it.
Wouldn't you use isset() to do that?
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
If you trust isset(), yes
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
!empty() is probably a safer bet.
|
Sam
Moderator Premium Member
Registered: 24th Dec 99
Location: West Midlands
User status: Offline
|
Or a combination of both...
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
I echo on live code, I'm hardcore.
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
But if you echo'd wouldn't it throw an error when you're setting the headers?
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
Yeah comment that while you're developing.
|