PDA

View Full Version : (php) getting external html file with php - works/doesn't work irratically



johnnyBoy
July 30th, 2002, 05:05
any idea why this isn't working very well?

i'm trying to get an external html file and one second this'll work,
and the next it won't - completely irratically - it just seems to be
down to complete luck if it works or not

here the code i'm using -

<?php
$urldate=date("d-M-Y",mktime(gmdate("H"),gmdate("i"),gmdate("s"),gmdate("m"),gmdate("d")+2,gmdate("Y")));

$url="http://www.bbc.co.uk/cgi-bin/worldservice/psims/ScheduleSDT.cgi?UTCDay=2&Pg=Pg&Ce=201807%3A27NE%3ALondon&Co=GB%3AUnited+Kingdom%3A0-45&Tz=GB01&Lo=0.0&Ct=17.3&AS=100014-1%3A648+MW%3A2&Ge=All%3AAll&Ft=1&Dy=$urldate&DS=GO%21&Wk=1.0";

echo 'add to url: ',$urldate,'<br>';
echo 'the url: ','<br>';
?>
____<textarea rows="3" cols="140"><?php print $url; ?></textarea> <br>
<?php

$filetext=join("", file($url));

echo $filetext;
?>

the above code is here (http://www.pinkgoblin.com/~cumminjo/getfile.php)
it puts the exact url that it's using to access the page in a textarea
box so it can be checked.

when it doesn't work i get this text in where a radio programme
listing should be -
"Due to technical problems, this service is not available at the moment.
Please refer to the l...."

and when it does work i get a programme listing.

if it doesn't work and i copy and paste the exact url that my
server just attempted to access into my browser it *always*
works - there's always a programme listing and never 'due
to technical probs...'

why doesn it not sometimes work when the php server
accesses the file? why is therea difference? is there anything
that can be done about it?

thanks :)

biggulp
July 30th, 2002, 07:04
<?php include("http://www.bbc.co.uk/cgi-bin/worldservice/psims/ScheduleSDT.cgi?UTCDay=2&Pg=Pg&Ce=201807%3A27NE%3ALondon&Co=GB%3AUnited+Kingdom%3A0-45&Tz=GB01&Lo=0.0&Ct=17.3&AS=100014-1%3A648+MW%3A2&Ge=All%3AAll&Ft=1&Dy=01-Aug-2002&DS=GO%21&Wk=1.0"); ?>

johnnyBoy
July 30th, 2002, 07:50
ok i'll give that a go.

thanks v. much

johnnyBoy
July 30th, 2002, 07:56
no difference - works exactly the same way as i had before. :( but thanks for the suggestion

biggulp
July 31st, 2002, 06:03
1st of all ur URL dun even work...

johnnyBoy
July 31st, 2002, 11:41
?
you mean the url that's reproduced in the textarea box at the top of the page that i've linked to above??

if that is the case – hang on, so you've copied and pasted that url into your address bar in your browser and it doesn't work? if that is the case then that will help me get to the bottom of this - because that url works everytime for me when i access it directly in my browser. - but then i used my browser in the first place to get the url - so maybe that url is specific to my browser or something?

but if it doesn't work for you in your browser then that helps me. or at least it shows up a problem where i didn't think there was one. whatever problem you're getting is likely to be the problem that my php server is getting.

so could you confirm please - you've clicked and gone to the page that i've linked to above. copied and pasted the url that's in the "the url:" textarea box, into your address bar and you get a bbc page but where the programme listing is supposed to be it says "Due to technical problems, this service is not...." ? or is it not working in another way for you?

biggulp
August 2nd, 2002, 05:46
no it doesn't work

xsnetwork
August 2nd, 2002, 05:53
The thing in the url which doesn't work is the "Dy=$urldate" if you take that out, or just change it to "Dy=" it works

johnnyBoy
August 2nd, 2002, 10:42
$URLDATE IS A PHP VARIABLE AND GETS SUBSTITUTED FOR A DATE FORMATED LIKE THIS: 04-Aug-2002

SO "$URLDATE" DOESN'T LITERALLY GET INCLUDED IN THE URL

TO SEE THE ACTUAL URL THAT IS USED SEE THE TEXTAREA BOX AT THE TOP OF MY LINKED TO PAGE - NOTICE THAT HAS THE DATE 2 DAYS ON FROM NOW. NOT $URLDATE.

copying and pasting the url in that textarea box is the only way to see if the url works or not. even manually substituting '$urldate' is not a good idea because you might ask for a date that isn't available.


the question is - why is it that when my php server accesses the url and puts all the html text into the $filetext variable, that html sometimes contains the programme listing, and sometimes doesn't?

and you think there's something wrong with the url - well there isn't (well not for me inanycase) because everytime i paste the url that is in the textareabox (which is the exact one that my php server accesses) into my browser address bar it successfully gives me an html page *with* programme listings - *every*time. never gives "due to technical probs...."

there is something about the way my php server accesses the page - it sometimes works and sometimes doesn't (sometimes being a few seconds gap)

johnnyBoy
August 2nd, 2002, 10:51
Originally posted by biggulp
no it doesn't work

did you -

A) paste the url from the text box on the top of the page that i linked to, into your browser address bar?

B) paste the url from the php code into your address bar?

C) just go to the link that i linked to?

if the answer is B i know it doesn't work - it's not surprising because it's got a php variable in it.

if the answer's C, i know - that's the problem. sometimes it does. sometimes it doesn't. that's the reason i'm posting this question.
why? and why does it always work when i access the same url that that php code did but via my browser. what's the differnece with via browser and via php server?

if the answer's A could you please be a little more specific - does it not work in the same way as i described - a whole bbc page but in the middle "technical problems..." or does it not work in another way?

biggulp
August 3rd, 2002, 00:22
I copy and pasted from the textbox but it doesn't work.

johnnyBoy
August 3rd, 2002, 07:14
biggulp> oh. that's very strange as it works for me fine - but then i used my browser on my particular system to get that url in the first place, so i'm thinking it must have some info in it that conflicts with something when someone else uses it? hmmm.. also when you say it doesn't work do you mean you get the "sorry due to technical ...."? is that what you get?

urm.. could you do me a favour!? :)

go to this page -
http://www.bbc.co.uk/cgi-bin/worldservice/psims/ScheduleSDT.cgi

do the location bit.

after that click on the GO that's next to this popup "Select daily schedule: " (just leave it on the default day)

then copy the url from your address bar of the page that you're on after clicking go.

and paste it in a reply here?


if you could do that it would be really appreciated as i think it might help get to the bottom of this

the fact that that url doesn't work for you must mean there's something specific about it to my setup. well that's what i'm thinking inanycase

also if anyone else could paste that url in a reply here it'd be great :) i know it's a bit cheeky but if you don't ask, you don't get!

:)

biggulp
August 4th, 2002, 05:17
I can't even search for the city as it gives me an error. anyway, you should clear your browser's cache

johnnyBoy
August 4th, 2002, 06:55
ok thanks for your help biggulp


can anyone else help me here - what i'm concerned with is how my php server grabs some html using the above code -

it works half of the times i try and fails the othe half. one second it'll work and one second it won't.

i use the above code that grabs the bbc page in a larger script everyday to populate a database with the radio programme listings from the external page it's grabbing from. the code works successfully but sometimes only after several attempts. - and this is what i'm trying to work out - why doesn't it work first time, everytime?

i'm just wondering if anyone has any ideas as to why my php server grabs the page only successfully sometimes?