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!

Recommended Answers

All 2 Replies

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
$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

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

Great, exactly what I was looking for! thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.