TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-17-2005, 11:10 PM   #1 (permalink)
The Wanderer
 
Join Date: May 2005
Location: Maine|USA
Posts: 17
Thanks: 0
Ogden2k is on a distinguished road
Default 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?
__________________
TechieHQ
Send a message via AIM to Ogden2k
Ogden2k is offline  
Reply With Quote
Old 09-18-2005, 02:10 AM   #2 (permalink)
The Wanderer
 
Tekime's Avatar
 
Join Date: Jul 2005
Posts: 11
Thanks: 0
Tekime is on a distinguished road
Default

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
}
__________________
Only the sane are truly insane.
LinuxHostingTalk | Hardware and Game Reviews | PHP Maine
Tekime is offline  
Reply With Quote
Old 09-18-2005, 07:19 PM   #3 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

still if there are 2 or more choices to be made i always prefer switch
PHP Code:
$page = (isset($_REQUEST['page']))?$_REQUEST['page']:'';
switch(
$page)
{
 case 
'x':
    
//do this
   
break;
 case 
'xy':
   
//do this
  
break;
 default:
  
//do this
  
break;

this is easier to handle than if. i do not know how much execution time difference is in if and switch, however.
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
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 05-31-2006, 10:57 PM   #4 (permalink)
The Wanderer
 
Join Date: May 2005
Location: Maine|USA
Posts: 17
Thanks: 0
Ogden2k is on a distinguished road
Default

Essentially what I'm trying to do is this:
  • site/
    • show data-a
  • site/1/
    • show data-a plus data-b
  • site/2/
    • show data- plus data-c
I hope this clears it up a little bit.
__________________
TechieHQ
Send a message via AIM to Ogden2k
Ogden2k is offline  
Reply With Quote
Old 09-07-2007, 09:52 AM   #5 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

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 on
	RewriteRule ^site/?$ site.php [L]
	RewriteRule ^site/([^\/]+)/$ site.php?szSite=$1 [L]
Now then if we break that down:

Code:
RewriteEngine on
Enables Mod Rewrite.

Code:
	RewriteRule ^site/?$ site.php [L]
RewriteRule is the standard prefix, the next part is a standard regular expression pattern, the next bit, is the location of the page to direct the user to. The "[L]" means "last rule", which you should use on all one line mod rewrites, it is only used for much more complicated rules.

Code:
	RewriteRule ^site/([^\/]+)/$ site.php?szSite=$1 [L]
Again RewriteRule is the standard prefix, the next part is a standard regular expression, everything within the regular expression that is located within ()'s can be used within the rule to direct the user to, in numerical order they are found. So for the next part it redirects the user to site.php?szSite=$1 The $1 looks back for what is located within the ()'s.

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.
bluesaga is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 5.1.2 Released! AlEast News and Announcements 1 01-25-2006 11:56 PM
Hiring PHP Programmer CreativeLogic General 0 11-15-2005 10:36 PM
PHP 4.4.1 Released AlEast News and Announcements 0 11-07-2005 04:35 PM
PHP 5.0.5 Released AlEast News and Announcements 0 09-20-2005 01:31 PM


All times are GMT. The time now is 09:22 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design