Re: Serving pages based on user input

From: Date: Sat, 23 Aug 2008 23:30:25 +0000
Subject: Re: Serving pages based on user input
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-278573@lists.php.net to get a copy of this message
Prasad Chand schreef:
Hi, I am fairly new to PHP. I would like to serve a page to a user based on his input. Say, I have a page 1 where user has 3 options(drop down menu). Based on his selection I would like a php script to direct him to another page (to pages 2,3,4 based on what he selected). I am unable to figure how to do this in php. Can you please give me some pointers. Is there any function which takes path and directs the user to that page?
millions of them, but not in php itself this is the kind of thing you have to write yourself. you don't really want to redirect the user at all (because it's a completely unecessary round-trip that will cause your server to have to handle another request when you already have the required info needed to display the relevant content), what you want to do is parse the input from the form and then run the relevant code to generate the relevant content. e.g. if (isset($_POST['selected_page'])) { switch ($_POST['selected_page']) { case 'page1': include 'myfirstpage.php'; exit; case 'page2': include 'mysecondpage.php'; exit; case 'page3': include 'mythirdpage.php'; exit; default: die('go away smelly hacker!'); } } else { // output your page selection form here or something. } that's just one lame example, there are as many ways to skin this cat as there are cats. might I suggest you go and read a few basic tutorials because what your asking is as basic as it gets ... namely take some user input and use it to determine what to output ...
Thanks, Prasad


« previous php.general (#278573) next »