How To Create a New Php Page with PHP
Some times You should not make a new php page with php …there are much better ways to do it
Other than using fopen() but if you are stuck here is the code …run it on a local testing server !
and you will see it works ! basically this scrip takes input from a form then creates a new php file with the supplied data …note if you are going to use this it is an open invitation for a hacker to Kill your website / app …because it will allow you to embed <?php Executable script so beware!
<?php
// This script creates a new php file
if ($_POST["sub"]) {
$thename = $_POST["filename"];
$thelink = $_POST["link"];
$sub = $_POST["sub"];
//error_reporting(0);
$i=1;
while($file = fopen("$thename"."$i.php", "r")) { fclose($file); $i++; }
if($file = fopen("$thename"."$i.php", "w")) {
// the html of the page with the value of link
$html = "<html>\n<body>\n $thelink \n</body>\n</html>";
if(fwrite($file, $html) === false) { echo "Could not write"; exit; }
fclose($file);
$newfile="$thename"."$i.php";
// this is the redirect to the new file but you can change this
header("Location: $newfile");
/* Do Some thing with a database
$con = mysql_connect($host, $user, $pass) or die ("could not connect");
mysql_select_db($db) or die ("$db Does not exist");
*/
}
}
else {
echo "<form method=post action='".$_SERVER["SCRIPT_NAME"]."'>\n";
echo "The New File Name: <input name='filename'>\n";
//echo " Ad link: <input name='link'>";
echo "<br/> Ad Html Code<br/><textarea name='link' cols='40' rows='3' id='link'> </textarea>";
echo "<br/><input type='submit' name='sub' value='Submit'>\n</form>\n";
echo "<br/>Example copy this and paste it in to the above html box <br/> <p align='center'><p align='center'><br>
<a target='_blank' href='http://secure.hostgator.com/cgi-bin/affiliates/clickthru.cgi?id=taggart99'><br>
<img src='http://www.hostgator.com/affiliates/banners/hostgator-300x250.gif'/><br>
</a></p></p>";
}
?>











