|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding | |
PHP Url Check Script Help?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
4.0ghz
![]() |
Hey,
I am trying to write a simple script in which "Hello world" is echoed back if the url contains index.php?option=A else "POOP" is echoed back. Obviously I am not going to be using "hello world" or "poop" but I am not exactly a beginer with php, but for some reason I am completely stumped when trying to write this? Can anyone offer assistance? For further clarification on what I am trying to do, when I check if it contains index.php?option=A there will be other stuff after the A that will be changing, but index.php?option=A will be constant. Example: index.php?option=A&setting2=B. I don't care about setting2 as long as option=A in the url. I hope this makes enough sense for someone to offer help. I know the script isn't longer then 6-7 lines, I am just stumped on how to query the url and use it like I am intending. Again, any help is much appreciated.
__________________
|
|||||||||||||
|
|
|
|
#2 (permalink) | ||||||||||||||
|
First Time Build
![]() |
are you getting the URL from post/get? or are you assuming it because of the file its accessing?
if the second, Code:
filename = index.php
<?php
if($_GET['option'] !='A')
{
echo "poop";
}else{
echo "hello world!";
}
?>
__________________
8800GT FTW ![]() Quote:
|
||||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
4.0ghz
![]() |
I am trying to get the current page url and check that. Is that what was assumed in post #2? Also does this work if theres more then 1 option? IE. option=A&test=B&randolph=G
__________________
Last edited by Chopes : 07-01-09 at 08:07 PM |
|||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
Ding ding ding ding ding!
![]() |
Yes, what the script will do is check each variable in the get query string.
So you have option=A, test=B, randolph=G. $_GET['option'] is for whatever is after the option, $_GET['test'] is for whatever is after test, and so on. The $_GET is what grabs information from the URL, however the $_POST usually comes from a submitted form. So your code could look like: Code:
<?php
if ($_GET['option'] == 'A') {
echo "hello world!";
}
if ($_GET['option'] == 'A' && $_GET['test'] == 'B') {
echo "Hello world, testing for B.";
}
?>
__________________
Watercooling Loop: MCP655 Vario -> Black Ice GTX360 -> Stinger Diamond Max -> Heatkiller GPU-X² -> MicroRes
|
|||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|