Php - If Url Is Clean, Show This
- luke-stealth-man
-
luke-stealth-man
- Member since: Jul. 8, 2005
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
Is it possible in PHP to show something only if the URL is a certain way.
For example, if this url is flash.php I want to echo something. However, if the URL has a ? after it (flash.php?) or more (flash.php?id=1) I don't want to echo anything. Any ideas?
So basically only echo something if the page is flash.php, not anything else (flash.php?a=true).
- yhar
-
yhar
- Member since: Apr. 2, 2008
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
What you could do is the following;
<?php
$id = $_GET['id'];
if(empty($id)){
$id = "Nothing";
}
So that will say, if "ID" is empty, IE it doesn't exist it will be set to "Nothing" if it contains something it keeps that.
So flash.php?id=100 would set id to "100" and flash.php would set id to "Nothing".
Then you could add something like;
if ($id = "Nothing"){
include ("nothing.php"){
}else{
include ("$id");
}
Syntax and code probably have problems, but you get the idea? :)
THIS IS CITRICSQUID POSTING
- BoneIdol
-
BoneIdol
- Member since: Aug. 14, 2006
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
At 6/5/08 02:20 PM, luke-stealth-man wrote: Is it possible in PHP to show something only if the URL is a certain way.
For example, if this url is flash.php I want to echo something. However, if the URL has a ? after it (flash.php?) or more (flash.php?id=1) I don't want to echo anything. Any ideas?
So basically only echo something if the page is flash.php, not anything else (flash.php?a=true).
<?php
if (sizeof( $_GET )){
die();
}
?>
<html>
<head>
.... Sufficiently advanced incompetence is indistinguishable from malice.
- luke-stealth-man
-
luke-stealth-man
- Member since: Jul. 8, 2005
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
At 6/5/08 02:41 PM, yhar wrote: So that will say, if "ID" is empty, IE it doesn't exist it will be set to "Nothing" if it contains something it keeps that.
So flash.php?id=100 would set id to "100" and flash.php would set id to "Nothing".
Thanks, but I want it the other way round. If id is empty, it includes something. Else it does nothing.
- authorblues
-
authorblues
- Member since: Jun. 21, 2005
- Offline.
-
- Forum Stats
- Member
- Level 12
- Blank Slate
At 6/6/08 04:36 AM, luke-stealth-man wrote: Thanks, but I want it the other way round. If id is empty, it includes something. Else it does nothing.
well, as a programmer, you now have all the details you need to do this yourself. please dont look for a handout. your inability to take a concept and modify it in SMALL ways to work to your satisfaction suggests that you lack the fundamental skills required of programmers.
- plasmaz
-
plasmaz
- Member since: Feb. 13, 2007
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
At 6/5/08 05:37 PM, BoneIdol wrote:At 6/5/08 02:20 PM, luke-stealth-man wrote: Is it possible in PHP to show something only if the URL is a certain way.<?php
For example, if this url is flash.php I want to echo something. However, if the URL has a ? after it (flash.php?) or more (flash.php?id=1) I don't want to echo anything. Any ideas?
So basically only echo something if the page is flash.php, not anything else (flash.php?a=true).
if (sizeof( $_GET )){
die();
}
?>
<html>
<head>
....
This example works for what you want, you just need to code it in a certain way so it shows what you want.
if (sizeof( $_GET )){ // There is a ? in the URL - luke-stealth-man
-
luke-stealth-man
- Member since: Jul. 8, 2005
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
Thanks guys, i've got it working barring one problem.
The code is in the middle of a page, meaning I want to run the top part of the page, then the code, then the bottom part of the code. A mixture of HTML and PHP.
<?php
if (sizeof( $_GET )){
echo "id is on";
}
else {
echo "id is off";
}
?>
Thats what i've got, but yeah, it runs the by itself rather than that and the rest of the page. Any ideas?
- yhar
-
yhar
- Member since: Apr. 2, 2008
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
At 6/6/08 10:35 AM, luke-stealth-man wrote: Thats what i've got, but yeah, it runs the by itself rather than that and the rest of the page. Any ideas?
Can you explain again please, I'm not 100% sure what you're on about.
Do you mean you want;
TOP HALF OF PAGE LOAD.
Code executed, echos either "id exists" or "Id doesn't exist"
BOTTOM HALF OF PAGE LOADS
Or do you want;
Code executed, echos either "id exists" or "Id doesn't exist"
If ID exists
TOP HALF OF PAGE LOADS
BOTTOM HALF OF PAGE LOADS
Which is it?
THIS IS CITRICSQUID POSTING
- luke-stealth-man
-
luke-stealth-man
- Member since: Jul. 8, 2005
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
At 6/6/08 10:45 AM, yhar wrote: TOP HALF OF PAGE LOAD.
Code executed, echos either "id exists" or "Id doesn't exist"
BOTTOM HALF OF PAGE LOADS
Yes, that's it :)
- yhar
-
yhar
- Member since: Apr. 2, 2008
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
At 6/6/08 10:54 AM, luke-stealth-man wrote: Yes, that's it :)
<html>
<head>
<title> my website </titl>
</head>
<body>
<div style="height:200px; width:400px; background-color:#FF9900;">
<?php
if (sizeof( $_GET )){
echo "id is on";
}
else {
echo "id is off";
}
?>
</div>
</body>
</html>
That will load it in the middle of your page.
Now you can simply add stuff around it, understand?
It's simple :)
THIS IS CITRICSQUID POSTING
- BoneIdol
-
BoneIdol
- Member since: Aug. 14, 2006
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
Just thought I should point out that sizeof just returns the size of the $_GET array. If something that ISN'T id is set it will return a value greater than 0, which equates to true.
If you want to see if only id is set use isset():
if (isset($_GET['id'])){
echo 'id is set';
}else{
echo 'id is not set';
}
If you want it to only have certain $_GET elements, you'll need to combine sizeof and isset. Do a sizeof to make sure the correct number of $_GET elements is set, then test each one with isset().
Sufficiently advanced incompetence is indistinguishable from malice.

