FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Question about something





Diablosblizz
Hi, personally, I am a noob a PHP therefor I need a little bit of php help. I would like to add a mini error for if the script cannot connect to the server.

Heres my php code (I did not script it):

Code:
<?
$open = fsockopen("IP GOES HERE","PORT GOES HERE");
if ($open) {
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
$read = fread($open,1000);
$text = explode("content-type:text/html",$read);
$text = explode(",",$text[1]);
} else { $er="Connection Refused!"; }
?>
</div>
<?
if ($text[1]==1) { $state = "Up"; } else { $state = "Down"; }
if ($er) { echo $er; exit; }
echo "<font face=verdana size=1>
Current Song: $text[6]<BR>
Listeners: $text[0] of $text[3] ($text[4] Unique)
";?>


This code is for getting the current song and listeners on my radio server. Now I was wondering if it was possible to change it a little bit so if the server was offline it would show a error like:

Error, the radio server is offline, please try again at a later time.

Thanks for all your help!
chris20
This should work for that purpose...

However, if you get a connection refused, as in the server is completely off, it will just say Connection Refused!, if you want to change that, just change where it says } else { $er="Conection Refused!"; } to what you want it to say inbetween the quotes.

Code:

<?
$open = fsockopen("IP GOES HERE","PORT GOES HERE");
if ($open) {
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
$read = fread($open,1000);
$text = explode("content-type:text/html",$read);
$text = explode(",",$text[1]);
} else { $er="Connection Refused!"; }
?>
</div>
<?
if ($text[1]==1) { $state = "Up"; } else { $state = "Down"; }
if ($er) { echo $er; exit; }
if ($state == "Up") {
echo "<font face=verdana size=1>
Current Song: $text[6]<BR>
Listeners: $text[0] of $text[3] ($text[4] Unique)
} else {
echo "Error, the radio server is offline, please try again at a later time.";
}
";?>
Diablosblizz
First off, your php code, does not work. If you have read over the php code there are two <?php starts, not a whole one. And second, when the server is unacciable nothing shows up, not even "Connection Refussed". Thanks for you help.
chris20
Php code is allowed to have as many starts and stops in it as you want. There is a name for that, but I forgot what its called. For example...

<?php
if (1==1) {
?>
this is text that will appear ONLY if 1 equals 1, and in this universe, it does
<?php
} else {
echo "this is text that will appear ONLY if 1 doesnt equal 1, not going to happen";
}


in this example, that text isnt going to appear unless 1 equals 1, it works here just as it works in ANY other php script you may have seen in your life


im not sure about the rest of it as to why it isnt working because i dont have enough information to pursure it

sorry
Related topics
I Have a question . Is it the server support Chinese?
Question before requesting free hosting
question abt posts/mth
Kinda dumb question regarding DNS
A question
UT2004 U like the game? Do u have any question post here.
Question about DNS!
Question about Domain!
another uni.cc question
Question
Question abt lang. support...
question!!!!!!
A question about Naruto
C++ Question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.