The purpose of my script is for the user to enter either a player name or clan name and the script checks to see if the player or clan has played any games by seeing if the corresponding html log file exists.
The previous version worked with fopen() on a local server, but most php hosts have this option disabled. So I am trying to do the same thing with fsockopen(), but I am running into a 404 error on the second check . If you input a valid player name, it works properly, but if you enter an invalid player name or a valid clan name it throws the 404 error.
<?php
//player name
$test=$POST['name'];
//clan name
$clan=$POST['name'];
//convert to proper case for html page check
$clan=strtoupper($clan);
$test=strtolower($test);
$test=ucfirst($test);
$domain="games2.westwood.com";
$pfile="/ra2gamelogs/$test.html";
$cfile="/ra2gamelogs/clan_[$clan].html";
$url="http://games2.westwood.com/ra2gamelogs/$test.html" ;
$urlclan="http://games2.westwood.com/ra2gamelogs/clan_[$clan].html" ;
$fileplay = fsockopen ($domain, 80);
if ($fileplay) {
fwrite($fileplay, "GET $pfile HTTP/1.0\r\n");
fwrite($fileplay, "Host: $domain\r\n\r\n");
}
if (!feof($fileplay)) {
header("Location: $url");
}
else {
$fileclan = fsockopen ($domain, 80);
if ($fileclan) {
fwrite($fileclan, "GET $cfile HTTP/1.0\r\n");
fwrite($fileclan, "Host: $domain\r\n\r\n");
if (!feof($fileclan)) {
header("Location: $urlclan");
}
}
fclose($fileplay);
if (!$fplayexist){
echo "<p><b>Sorry, Player $test has not played any tournament games yet.</b>\n";
}
if (!$fclanexist){
echo "<p><b>Sorry, Clan $clan has not played any clan games yet.</b>\n";
}
?>