The point of this script, is to take the user input (a website) and turn it into it's IP address. This then is turned into a file, readable later in the script. This is my attempt at having these sites available theoretically forever. A collection of what everyone has searched for. I have no idea which part is wrong seeing as I'm fairly new to PHP, but any help would be awesome!
<?php
//Old PHP code that worked but I'm doing something slightly different this time.
//if (isset($_POST['submit'])) {
//if(isset($_POST['site'])) {
//$site = $_POST['site'];
//$ip = "http://".gethostbyname($site);
//print "<a href=".$ip.">".$ip."</a>" or die ($ip);
//}
//}
$ip = $_POST['site'];
$myArray = array();
if (max($myArray) == 0) {
$newFile = $ip.".txt";
$myArray = array(0 => $newFile);
$openWrite = fopen($newFile, 'w') or die("Can't open file");
fclose($openWrite);
print "<a href='http://".$myArray[0]."'>".$myArray[0]."</a>";
}
elseif (max($myArray) > 0) {
if ($ip != $newFile) {
$newFile = $ip.".txt";
$max = max($myArray) + 1;
$myArray = array($max => $newFile);
$maxArray = max($myArray);
$openWrite = fopen($myArray[$maxArray], 'w') or die("Can't open file");
fclose($openWrite);
}
else {
print "<script type='text/javascript'>alert('Entered site already exists.')</script>";
foreach ($myArray as $value) {
print "<a href='http://".$value."'>".$value."</a>";
print "<a onClick='".delete()."'> - Delete</a>";
print "<br />";
function delete() {
//Haven't written this part yet.
}
}
}
}
?>