Edited by docmonkey, 12 June 2011 - 11:17 AM.
4 replies to this topic
#1
Posted 12 June 2011 - 10:34 AM
I'd like to use a switch statement (or something better if anyone has some advice) to run a bit of code if i'm on one page, and different code if i'm on another. What is the best way to do this? Looking for best practices here...
|
|
|
#2
Posted 12 June 2011 - 04:20 PM
It varies greatly on what the contents of your page are going to be, however you can freely switch on $_GET['page'] if that were so your wish. You should be sure to sanitize the input if you are going to be displaying or working with the GET variable however.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 14 June 2011 - 04:30 PM
You can use the $_SERVER['PHP_SELF'] to determine which page you are viewing! Though you get the extension along with it so you may want to substring it and get rid of the extension!
For example:
will return the name of the file that is viewed!
Hope this helps you :)
For example:
substr($_SERVER['PHP_SELF'], 1, strpos($_SERVER['PHP_SELF'], ".php") - 1);
will return the name of the file that is viewed!
Hope this helps you :)
#4
Posted 17 June 2011 - 02:40 PM
#5
Posted 17 June 2011 - 02:46 PM
Yes, SCRIPT_NAME should be used at the very least - however I see no practical reason for the script to retrieve its name (you name it something specific for a reason, usually.)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









