0

hey all, just starting with php, and was wondering if i could create a new web page by using a variable from a php script in a php script. For example, the user enters a word, and then a web page is created that is called that word. so user enters "daniweb" and the page is called "daniweb.php". also, if possible could i include content on this newly created page, such as a php script? thanks for any suggestions!

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by david cashin
0

What you are looking for is file writing/reading operations. For this you use fopen along with the w parameter which tells PHP you want to write to the file (and create it if it doesn't already exist).

$name = $_GET['name']; //Or where-ever you get the file name
//Sanatize
$name = str_replace('\\', '', $name);
$name = str_replace('/', '', $name);

//Open the file
$f = fopen('safedir/'.$name.'.php' , 'w');
//Write to the file
fwrite($f, "Hello World! Your code or HTML should go here.");
//Close file
fclose($f);

//Next, redirect to the new file
header("Location: safedir/{$name}.php");

Edited by FlashCreations: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.