Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP 404-checking


ghost's Avatar
0 0

Hi there!

I have a little problem I would like to find a solution for. My school server keeps school-pictures of every student on some webserver And I wrote some php to make a list of it. The numbers are built like this: xxxx and start somewhere in 2xxx. Not all numbers are taken by a student, so not all numbers wear a picture. To make the page a lot emptier (and neater) I decided to do some error-checking on the images, so no image means no entry on the page. I tried to do this by using sockets and asking for the headers. Only problem is; Sockets are heavy. At this moment my school server is.. ehm .. down.. :| (shh!)

This is how it all goes wrong:

<?php
while(1)
{
$socket= fsockopen("xx.xx.xx.xx", 80, $errno,$errdesc) or die("Can't open socket");
$request = "HEAD <<Random Filename>> HTTP/1.0\r\n\r\n";
fputs($socket, $request) or die("Can't send request");
fclose($socket);
}

/*
    - Create a socket to the victim server
    - Request the header of a random file
    - close the socket
    
    Sockets are a heavy load for servers.
    This will go on processing, making requests,
    until the server stops responding, 
    which usually doesn't take too long.
    Running this code once or twice 
    will stop the server from working.
    
    This code created so you don't make the same mistake.
    If you choose to use this file in a non-legal way,
    I take zero responsibility.
*/ 
?>

My question for you: Do you have a suggestion on how to find out if the student exists, without creating too much serverload?

I thank you already :)

-Tov-


Mr_Cheese's Avatar
0 1

why not use cURL or file_get_contents and have it sleep for 1 second after each attempt?


ghost's Avatar
0 0

-Tov- wrote: I have a little problem I would like to find a solution for. My school server keeps school-pictures of every student on some webserver And I wrote some php to make a list of it.

-Tov-

Oh you little pervert… :p


ghost's Avatar
0 0

It's for finding a number to a face, and through the number to find a name :)

And yes, you could find out some more.. :P


ghost's Avatar
0 0

Mr_Cheese wrote: why not use cURL or file_get_contents and have it sleep for 1 second after each attempt?

Thanks! I think that will solve the problem!

I will post some more if I tried it :) (doing so now)


ghost's Avatar
0 0

New problem; If it can't find the file it gives an error in my html-document. This also happens with readfile, which is then just supposed to give a FALSE back. It doesn't seem to do so, also making my if-check not working.

Code:

<HEAD>
<TITLE>Leerlingenlijst RSG Tromp Meesters</TITLE>
</HEAD>
<BODY>
Some text..
<?php
$fp = fsockopen( "**.**.**.**", 80, $errno,$errdesc);
if(!$fp)
{
fclose($fp);
echo("<B>Image server down!</B>");
}
else
{
fclose($fp);
for($n=2000; $n <= 5000; $n++)
{
$context=array('http' => array ('header'=> 'Range: bytes=1024-', ),);
$xcontext = stream_context_create($context);
$str=file_get_contents("http://**.**.**.**/Files/server/fotos/$n.jpg",FALSE,$xcontext);
if(!$str)
{
echo("<A NAME=\"$n\">\n");
echo("<TABLE>\n");
echo("<TR><TD ALIGN=\"left\">Leerlingnummer:</TD><TD ALIGN=\"left\">$n</TD></TR>\n");
echo("<TR><TD ALIGN=\"left\">Foto:</TD><TD ALIGN=\"left\"><img src=\"http://**.**.**.**/Files/server/fotos/$n.jpg\"></TD></TR>\n");
echo("<TR><TD ALIGN=\"left\">Rooster:</TD><TD ALIGN=\"left\"><A HREF=\"http://rsgtrompmeesters.nl/page/inhoud/m-roosterservice/Dagrooster/Leerlingroosters/Lee_M_1_$n.htm\">Rooster</A></TD></TR>\n");
echo("</TABLE>\n<HR>\n");
sleep(1);
}
}
}
?>

Warning: readfile(http://.../Files/server/fotos/2000.jpg) [function.readfile]: failed to open stream: HTTP request failed! HTTP/1.1 404 File not found in *****/test/leerling.php on line 33

Same goes with file_get_contents.