file() mit externer URL


listigerLurch

Grünschnabel
Hi

folgendes script habe ich von hier.

PHP:
<?php

	$titleFile = "titles";
	$titleFileDelimiter = ",";
	
	if(file_exists($titleFile)) {
		$titleData = file($titleFile);
		$titleArrayCounter = 0;
		for($a=0;$a<count($titleData);$a++) {
			$titleArrayTemp = explode($titleFileDelimiter,$titleData[$a]);
			$unfriendlyTitleArray[$titleArrayCounter] = $titleArrayTemp[0];
			$titleTypeArray[$titleArrayCounter] = $titleArrayTemp[1];
			$friendlyTitleArray[$titleArrayCounter] = $titleArrayTemp[2];
			$titleArrayCounter++;
		}
	} else {
		echo "The file containing rank feed heading definitions was not found (".$titleFile.").";
		exit();
	}

	function parseRank($rankFile, $unfriendlyTitleArray, $titleTypeArray, $friendlyTitleArray) {
		$rankData = file($rankFile);
		if(substr($rankData[4],2,2) == "-1") {
			echo "No account with that name was found.<br><br>\n\n";
			makeForm($_GET['accountName']);
			exit();
		}
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<root>\n";
		$badSymbols = array("\n", "\r");
		for($i=1;$i<4;$i+=2) {
			$rankHeadingLine = str_replace($badSymbols, '', explode("\t",$rankData[$i]));
			$rankDataLine = explode("\t",$rankData[$i+1]);
			for($k=1;$k<count($rankHeadingLine);$k++) {
				$headingData = makeFriendlyHeading($rankHeadingLine[$k], $unfriendlyTitleArray, $titleTypeArray, $friendlyTitleArray);
				$contentData = makeFriendlyContent($rankHeadingLine[$k], $unfriendlyTitleArray, $rankDataLine[$k], $titleTypeArray);
				echo "  <".$rankHeadingLine[$k]." friendly=\"".$headingData."\">".$contentData."</".$rankHeadingLine[$k].">\n";
			}
		}
		echo "</root>\n";
	}
	
	function makeFriendlyElapsedTime($time = 0) {
		$hours    = (int)floor($time/3600);
		$minutes  = (int)floor($time/60)%60;
		$seconds  = (int)$time%60;
		if($hours > 0 && $hours < 10) {
			$txt = "0".$hours.":";
		} else if($hours > 10) {
			$txt = $hours.":";
		} else {
			$txt = "00:";
		}
 		if($minutes > 0 && $minutes < 10) {
			$txt .= "0".$minutes.":"; 
		} else if($minutes > 10) {
			$txt .= $minutes.":";
		} else {
			$txt .= "00:";
		}
		if($seconds>0 && $seconds < 10) {
			$txt .= "0".$seconds;
		} else if($seconds > 10) {
			$txt .= $seconds;
		} else {
			$txt .= "00";
		}
		return($txt);
	}

	function makeFriendlyHeading($rawContent, $unfriendlyTitleArray, $titleTypeArray, $friendlyTitleArray) {
		for($j=0;$j<count($unfriendlyTitleArray);$j++) {
			if(trim($rawContent) == trim($unfriendlyTitleArray[$j])) {
				return(trim($friendlyTitleArray[$j]));
				exit();
			}
		}
		return(trim($rawContent));
		exit();
	}

	function makeFriendlyContent($headingContent, $unfriendlyTitleArray, $rawContent, $titleTypeArray) {
		for($l=0;$l<count($unfriendlyTitleArray);$l++) {
			if(trim($headingContent) == trim($unfriendlyTitleArray[$l])) {
				if(trim($titleTypeArray[$l]) == "T") {
					return(trim(date("Y-m-d", $rawContent)));
					exit();
				} else if(trim($titleTypeArray[$l]) == "E") {
					return(trim(makeFriendlyElapsedTime($rawContent)));
					exit();
				} else if(trim($titleTypeArray[$l]) == "%") {
					return(trim($rawContent."%"));
					exit();
				}
			}
		}
		return(trim($rawContent));
		exit();
	}

	function makeForm($oldAccount) {
		echo "You can download this script for non-commercial use by clicking <a href=\"./bf2-xml_parser.zip\">here</a><br><br>\n\n";
		echo "<form action=\"./index.php\">\n\n";
		echo "Enter BattleField 2 <b>account name</b>: <input type=\"text\" name=\"accountName\" value=\"".$oldAccount."\">\n\n<br><br>";
		echo "<input type=\"submit\" value=\"Submit\">\n\n";
		echo "</form>";
	}

	if(isset($_GET['accountName'])) {
		$badSymbols = array("\n", "\r", "?", "&");
		$accountName = str_replace($badSymbols, '', trim($_GET['accountName']));
		if($accountName <> trim($_GET['accountName'])) {
			echo "The account name you entered was malformed, please try again.\n\n<br><br>\n\n";
			makeForm(trim($_GET['accountName']));
			exit();
		}			
		$rankURL = "http://bf2web.gamespy.com/ASP/getplayerinfo.aspx?nick=".$accountName."&info=&debug=tx
&nocache=".rand(500, 32768) * rand(500, 32768);
		parseRank($rankURL, $unfriendlyTitleArray, $titleTypeArray, $friendlyTitleArray, $allowLocalRankFile, $allowXMLSave);
	} else {
			makeForm('');
	}

?>

Wenn ich das Script ausführe, kommt folgende Fehlermeldung:
Warning: file(): URL file-access is disabled in the server configuration in /home/xxx/public_html/page/test/index.php on line 22

Warning: file(http://bf2web.gamespy.com/ASP/getplayerinfo.aspx?nick=ebclowrider&info=&debug=tx&nocache=15117498): failed to open stream: no suitable wrapper could be found in /home/xxx/public_html/page/test/index.php on line 22

Leider hab ich keinen Zugriff auf die Serverkonfiguration... Gibt es eine Möglichkeit das Script umzuschreiben damit dass auch so funktioniert? Ich denke ich muss eine andere Funktion als file() haben oder?

Gruss & Danke
 
Zuletzt bearbeitet:

Sven Mintel

Mitglied
Wo genau steigst du da nicht durch?

In dem Beispielcode musst du nur eine Adresse deiner Wahl eingeben, und schon hast du ein lauffähiges Skript:
Code:
<?php
$fp = fsockopen ("www.tutorials.de", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
   while (!feof($fp)) {
       echo fgets($fp,128);
   }
   fclose($fp);
}
?>
 

Neue Beiträge

Forum-Statistiken

Themen
272.360
Beiträge
1.558.632
Mitglieder
187.834
Neuestes Mitglied
jordanx0206