...

View Full Version : Little problem with a script. (Getting info from a server with fopen) - Please help!



Chicano
02-13-2003, 03:02 AM
Ok, I have this tiny script, which will basically check to see if a file exists on my server - if it does exist, it returns with an "Online" if it dosnt (Or if it cannot find the file actually) It returns with an "Offline" ... this is so, on my webpage, I can let people know when my server is online or offline - automatically.

The script worked fine, then, suddenly, it stopped working ... I really don't think I have modified it at all.

(I have it in a little iframe on my main page)

So, this is the page with the script:


<html>
<head>
<style>
body {background:black;color:orange}
#Off {color:red;text-align:center}
#On {color:lime;text-align:center}
</style>
</head>
<body topmargin="0" leftmargin="0">
<center>
<h2>
<?php

$file = @fopen("ftp://testserver:servertest@myserver.address.org/test.html", "r");
if (!$file) {
echo '<b id=Off>&nbsp; &nbsp; Offline</b>';
exit;
}else{
echo '<b id=On>&nbsp; &nbsp; &nbsp;Online</b>';
}
?>
</body>
</html>

It DOES return an "Online" when the server is online -- it just dosnt return the Offline when the server is offline.

Any help greatly appreciated!!!

(btw, originally, I had it as
$file = fopen
but, it returned a text error saying that test.html could not be found or something, so, I was told to put the @ efore the fopen so it wouldnt return any error)

Nightfire
02-13-2003, 06:29 PM
A much easier way


if(file_exists("ftp://yoursite.com/file.txt")){
echo 'Server online';
}else{
echo 'Server offline';
}

Chicano
02-13-2003, 08:16 PM
Thank you Nightfire for your response, but it didnt seem to work...

This is what I have:

<html>
<body topmargin="0" leftmargin="0">
<center>
<h2>
<?php

if(file_exists("ftp://testuser:testpass@myserver.dyndns.org/test.txt")){
echo 'Server online';
}else{
echo 'Server offline';
}

?>
</h2>
</body>
</html>


It now dosnt ever seem to check --- nothing appears on my server's logs.
It simply promptly responds with Server Offline ...
I created test.txt and everything.
Anyway, have any ideas? Thanks!

Chicano
02-15-2003, 07:10 AM
*bump*

firepages
02-15-2003, 04:59 PM
for an FTP server you are better off trying the FTP functions ?


<?php
$server='ftp.your_domain.com';
$user='username';
$pass='password';
$con = @ftp_connect($server,21);
$login = @ftp_login($con, $user, $pass);
if ((!$con) || (!$login)) {
echo "FTP offline or bad user/pass";
ftp_close($con);
} else {
echo "FTP online";
}
?>

Chicano
02-17-2003, 09:22 AM
Thank you so much! It works fast and lovely.
I really appreciate it!

It said warning blah blah blah when the server was offline, so I just added a litle @ sign before the ftp_close($con); and it fixed it great =)

THANKS!

firepages
02-17-2003, 12:40 PM
DOH! , actually I got the ftp_close in the wrong place ~

glad it helped though .



<?php
$server='ftp.your_domain.com';
$user='username';
$pass='password';
$con = @ftp_connect($server,21);
$login = @ftp_login($con, $user, $pass);
if ((!$con) || (!$login)) {
echo "FTP offline or bad user/pass";
} else {
echo "FTP online";
ftp_close($con);
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum