473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IF Statement Help Dependent on URL

2
Hello,

I'm trying to display content on the page dependent on what the URL states. I'm pretty new to PHP as I used to develop in Coldfusion and it could be done.

Basically I want the following:

IF URL = http://www.mysite.com/thepage.php

Then display this.. Hello

ELSE

Display this... Bye


Sorry for showing the example in such a crude format but just wanted to get my point across.

Any help would be much appreciated.

Thanks in advance,
Andy
Oct 3 '09 #1
3 1528
Dormilich
8,658 Expert Mod 8TB
to get the URL use the $_SERVER variable
Expand|Select|Wrap|Line Numbers
  1. $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'];
  2. // or
  3. $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['PHP_SELF'];
  4. // or
  5. $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['SCRIPT_NAME'];
of cause you can also use parts of the url, so that the if statement becomes simpler
Oct 3 '09 #2
Markus
6,050 Expert 4TB
Well, technically, if the script 'thepage.php' is being run, you know that http://host/thepage.php must be the location. Unless you're using URL rewrites, of course (and possibly other things).
Oct 3 '09 #3
TheServant
1,168 Expert 1GB
When you say dependent on what the URL states, do you mean page requested? You can use mod_rewrite to send all requests to a master page which will work out which page was requested and display info. accordingly... Is that what you were after?
Oct 4 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

47
by: Andrey Tatarinov | last post by:
Hi. It would be great to be able to reverse usage/definition parts in haskell-way with "where" keyword. Since Python 3 would miss lambda, that would be extremly useful for creating readable...
35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
2
by: Little PussyCat | last post by:
Hello, I hope you can help me. We have a SQL Server 2000 database at work, (which works with a VB6 frontend) which grew to a considerable size, so one of my past colleagues sent me this...
2
by: Paul Reddin | last post by:
Hi, (V8.1 Fp2) Our application uses JDBC batch to execute mutiple insert statements and we saw a strange thing this morning. There were 4 SQL Insert statements in the batch, and we know the...
81
by: candy | last post by:
hi all, Is there is any way in the C language by which I can get the address of a statement? For eg,consider the following simple program: 1. #include<stdio.h> 2. 3. int main(void){ 4. ...
5
by: Phuff | last post by:
Hey all, I need some direction help. I have a switch case statement that is seemingly my only option right now, but its too large and not easy to maintain the code. Here goes... I have part...
26
by: a.mil | last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff and I encountered the following problem: When I have a for loop like this: b=b0; for (a=0,i=0;i<100;i++,b--) { if (b%i)...
7
by: ll | last post by:
Hi, It's been a while since I've worked with javascript time comparison, and I was wondering how I can say "if time < 15:30"? The semicolon looks out of place to me, and indeed it has caused an...
2
by: puzzlecracker | last post by:
See it a lot but haven't learn the difference between this two in the context of template. Would someone explain it please? Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.