PHP Help
#1

I never learned how to do this and cant find a tut to save my life.

I want to make it so that it pings forum.rokzlive.com, and if it gets a reply it says
Код:
Forum: Online

Click HERE To Go To The Forum!
and if it does not...

Код:
Forum: Offline
Reply
#2

hmm didn't do sumin like this but I quickly made sumin which atleast worked with samp

PHP код:
<?php
$url 
"http://example.com";
if(!
file_get_contents($url))
{
    echo 
'Offline';
}
else echo 
'Online';
?>
if it isn't able to get file contents from the url it returns FALSE means its offline
if else its online

what I'm not sure about is if the site doesn't have an index.html or .php
if it works then
but I'm quite sure you are able to test that with an empty folder ^^then just
make the url

http://example.com/emptyfolder

if it doesn'T work tell me I'll try to get another way after school

Edit:
tested it with files.sa-mp.com
which doesn't have no index and it worked so yea
it should work for you :]
Reply
#3

I tried this...

Код:
<?php
$url = "http://forum.rokzlive.com";
if(!file_get_contents($url))
{
    Forum: <b><strong><span style="color: #008000;">Offline</span></strong></b>
    <br /><br />
}
else
{
    Forum: <b><strong><span style="color: #008000;">Online</span></strong></b>
    <br /><br />
    <a href="http://forum.rokzlive.com">Click Here to go to the forum!</a>
    <br /><br />
}
?>
And it errors.
Heres my error.


Parse error: syntax error, unexpected ':' in C:\Documents and Settings\David\Application Data\NuSphere\PhpED\projects\noname2.php on line 5


But theres many other errors when i remove that :, whats wrong>
Reply
#4

You must output HTML code with echo.

PHP код:
<?php
$url 
"http://forum.rokzlive.com";
if(!
file_get_contents($url))
{
    echo 
'Forum: <b><strong><span style="color: #008000;">Offline</span></strong></b>
    <br /><br />'
;
}
else
{
    echo 
'Forum: <b><strong><span style="color: #008000;">Online</span></strong></b>
    <br /><br />
    <a href="http://forum.rokzlive.com">Click Here to go to the forum!</a>
    <br /><br />'
;
}
?>
Reply
#5

Oww lol i did not realize i left that out
Reply
#6

Now if the host is not up i get this.

If did this when i turned my forum webserver off for a sec.

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\AdminSite\index.php on line 21

Warning: file_get_contents(http://forum.rokzlive.com) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\AdminSite\index.php on line 21
Reply
#7

PHP код:
<?php
$fgtHandle 
= @file_get_contents("http://forum.rokzlive.com");
if(!
$fgtHandle)
{
    echo 
'Forum: <b><strong><span style="color: #008000;">Offline</span></strong></b>
    <br /><br />'
;
}
else
{
    echo 
'Forum: <b><strong><span style="color: #008000;">Online</span></strong></b>
    <br /><br />
    <a href="http://forum.rokzlive.com">Click Here to go to the forum!</a>
    <br /><br />'
;
}
?>
The '@' sign before a function prevents HTML error outputting, so it will return true or false still.
Reply
#8

thanks now even i learned sumin new
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)