I would like to serve a web page based on the name a visitor types into a text box. For example if somebody typed in JohnQ then the would get the web page johnq.php
Does anybody know how to do this with a sample script?
I am sorry if this is a newbie question.
Any help would be great.
Thanks
Rig
Passing Data Help
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Passing Data Help
.htaccess would be a good bet...
Re: Passing Data Help
Umm I'd be careful about letting the user enter anything they like. It would be advisable to have like a whitelist of allowed pages...
Code: Select all
<?php
$allowedPages = array('page1', 'page2', 'page3');
if (isset($_POST['page'])) {
$page = strtolower($_POST['page']);
if (in_array($page, $allowedPages))
header("Location: http://www.example.com/" . $page . ".php"); // obviously you'd want to replace example.com with your domain name
}
?>
<form method="post" action="#">
<input type="text" name="page">
<input type="submit" value="Go!">
</form>-
rigorouslogik
- Forum Newbie
- Posts: 2
- Joined: Sun Jul 30, 2006 3:24 pm
Re: Passing Data Help
Thanks for all the help. I tried the script adding allowed pages and changed to my website name. When running the script I get an error "Warning: Cannot modify header information - headers already sent" On Line 6 .
Any ideas? This is my first php/forms project. So I am sorry for being such a newbie.
Thanks
Rig
Any ideas? This is my first php/forms project. So I am sorry for being such a newbie.
Thanks
Rig