This is a discussion on Serving pages based on user input within the PHP General forums, part of the PHP Programming Forums category; You can read about the header function. http://is2.php.net/manual/en/function.header.php Ólafur Waage 2008/8/...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
You can read about the header function.
http://is2.php.net/manual/en/function.header.php Ólafur Waage 2008/8/23 Prasad Chand <prasad.chand@gmail.com>: > 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? > > Thanks, > Prasad > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > |
|
|||
|
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? Thanks, Prasad |
|
|||
|
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 > |
|
|||
|
Ólafur Waage schreef:
> You can read about the header function. > > http://is2.php.net/manual/en/function.header.php hi Ólafur, his situation doesn't require a redirect (he only thinks it does), and redirects suck when used unecessarily. (plenty of info on the web about why this is so ... hunt for a 'rant' by the formidable Richard Lynch in the archives of this list for instance) > > Ólafur Waage > > 2008/8/23 Prasad Chand <prasad.chand@gmail.com>: >> 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? >> >> Thanks, >> Prasad >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > |
|
|||
|
At 2:03 PM -0700 8/23/08, Prasad Chand wrote:
>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? > >Thanks, >Prasad Why use PHP for this? Standard html with css works quite well for this and is by far more common. I see no need to bring the php sledgehammer to drive this thumbtack. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
At 1:21 AM +0100 8/24/08, Ashley Sheridan wrote:
>On Sat, 2008-08-23 at 20:07 -0400, tedd wrote: >>At 2:03 PM -0700 8/23/08, Prasad Chand wrote: >> >> >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? >> >>Why use PHP for this? >> >>Standard html with css works quite well for this and is by far more common. >> >>I see no need to bring the php sledgehammer to drive this thumbtack. >> >> >Standard HTML and CSS will not do, you'd have to use JavaScript to >guarantee it all works correctly on the browser, but this is a bit >like using a dozen thumbs for one thumbtack! If you do it entirely >on the client-side, then each time a visitor wants any of the >"pages", the whole lot is sent to the browser, which is a real bad >idea! I was addressing providing the user with pages and not the drop-down menu thing. If you want to entertain a drop-down menu, please review this: http://sperling.com/examples/menuh/ That uses html, css, and javascript -- and while I show how to do it, I would not recommend it for anyone. Besides, there's no way that php can deliver a drop-down menu because the user's action are client-side. I've thought about using php with ajax, but why? It won't work any better. But, without the drop-down issue, then css and html will deliver pages quite nicely, like this: http://sperling.com/index.php My right side navigation is totally css and html. If you don't want right navigation, then there's a lot more possibilities, check out: http://css.maxdesign.com.au/listamatic/ All of these are designed to provide the end-user with the topic (i.e., page) of their choice -- all without php. Now, is this something that I'm not getting? Because all of this is pretty obvious to me. Where am I wrong? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
At 9:55 PM -0700 8/23/08, Prasad Chand wrote:
>This is off-topic, but the reason I was touchy about includes was >because it could create seo problems. > >http://forums.digitalpoint.com/showthread.php?t=31519 Bzzzzttt -- nope -- two different types of "includes". The link above is discussing having data included the url and not php includes. The advice/code that Jochem gave you was using php includes which is a completely different critter. I use php includes for all my sites and don't have any problem whatsoever with SEO. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
On Sun, 2008-08-24 at 01:32 +0200, Jochem Maas wrote:
> Ólafur Waage schreef: > > You can read about the header function. > > > > http://is2.php.net/manual/en/function.header.php > > hi Ólafur, > > his situation doesn't require a redirect (he only thinks it does), > and redirects suck when used unecessarily. (plenty of info on the web > about why this is so ... hunt for a 'rant' by the formidable Richard Lynch > in the archives of this list for instance) Oh dear, not this BS again. If the content is different then perform a redirect. Do you really want your login page to be indexed as your homepage? Lynch's arguments on this were weak. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP |
|
|||
|
At 10:02 PM -0700 8/23/08, Prasad Chand wrote:
>Thanks for that information. But in my case I need to serve pages >based on selection of US states. There are 50 of them, so generating >pages dynamically would have been a nice idea. Really, there are 50 of them!?!? :-) You don't have to generate 50 pages dynamically to do it -- try this: http://webbytedd.com/bbb/map/ That demo is done with just pure css -- no php nor javascript. Plus each one of those States can be linked to another page -- AND-- it is user friendly, validates, accessible, and SEO friendly. What more could anyone want? If you don't know php, then I think the best way to ask a question on this list by telling us what you want to do rather than asking specific php questions trying to do something they way you think it might work. Cheer, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
Jochem Maas wrote:
> 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 for your reply Jochem. I will keep your advice in mind. This is off-topic, but the reason I was touchy about includes was because it could create seo problems. http://forums.digitalpoint.com/showthread.php?t=31519 Thanks again, Prasad > > >> >> Thanks, >> Prasad >> > |