Page 1 of 1

Passing Data Help

Posted: Mon Aug 18, 2008 4:50 am
by rigorouslogik
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

Re: Passing Data Help

Posted: Mon Aug 18, 2008 1:21 pm
by alex.barylski
.htaccess would be a good bet...

Re: Passing Data Help

Posted: Mon Aug 18, 2008 1:33 pm
by Luke
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>

Re: Passing Data Help

Posted: Mon Aug 18, 2008 3:37 pm
by rigorouslogik
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