![]() |
PHP conditional help
Hi, I need to have a conditional where it basically does this:
if page address is x than show this if page address is xy than show this etc... How would I go about doing this? |
I'm not completely sure I know what you mean by page address. But for example, if you have:
www.example.com/index.php?page=x and www.example.com/index.php?page=xy Then you can create a conditional statement like: if((!empty($_REQUEST['page'])) && ($_REQUEST['page'] == 'x')) { // Show page x } elseif((!empty($_REQUEST['page'])) && ($_REQUEST['page'] == 'x')) { // Show page xy } But more likely, you'll want to accept multiple values for 'page' and pull them from a database or file. Then you'd want to simply check for page, validate page with whatever parameters you require, then load page from DB or disk, and display. if(!empty($_REQUEST['page'])) { // Do whatever with $_REQUEST['page'] } else { // Default behavior } |
still if there are 2 or more choices to be made i always prefer switch
PHP Code:
and also i prefer to be precise,, user $_GET for querystrings and user $_POST for post i know $_REQUEST provides a wider range for script, as both methods can be used to do same thing, but, in that case post data can always be overridden by get data, unless get comes first and then post (which i presume is default). i also think cookies are included in $_REQUEST (no t sure), and if they are then again its the same problem hope this helps |
Essentially what I'm trying to do is this:
|
What you are looking for, my friend is Mod Rewrite, this is not PHP, however it is DIRECTLY related, a lot of applications use this facility.
To do what you want to do you would have something like: Code:
RewriteEngine onCode:
RewriteEngine onCode:
RewriteRule ^site/?$ site.php [L]Code:
RewriteRule ^site/([^\/]+)/$ site.php?szSite=$1 [L]Now lets add an example: I try to go to www.domain.com/site/abc/ the rewrite rule will allow me to use www.domain.com/site.php?szSite=abc without me knowing that i am actually using that page, the browser will only ever display www.domain.com/site/abc/ and the user/search engine can not find out what url they are actually viewing unless they are told, or you redirect them there mistakenly. |
| All times are GMT. The time now is 07:52 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0