Jump to content


Photo

[SOLVED] Fetching caller URL??


  • Please log in to reply
2 replies to this topic

#1 mr_zhang

mr_zhang
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 29 October 2006 - 03:30 AM

Hi guys,

I'm trying to build a small PHP script. Let's call main.php. I want the program to react based on the url of the caller (I use include function).

e.g. of caller (index.php)
.....
<? include('main.php'); ?>
......

now, the index.php can be:
- http://www.Domain.com/index.php
- http://www.Domain.com/Sub1/index.php
- http://www.Domain.com/Sub2/index.php
- http://www.Domain.co.../Sub1/index.php, etc.

I guess i'm searching for a function that enables php to get the complete url of itself in an online web server. Or do you have a similar suggestion?

Regards,

#2 ksteuber

ksteuber
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationCalifornia, USA

Posted 29 October 2006 - 07:02 AM

Let me see if I got this straight (I'm not sure I really understand the question).
You're looking to make a script that figures out what the URL of the page it has been included in is, and then uses that information to decide what to do next?

I think you want something like this:
(main.php)
<?php
$URL = $_SERVER['PHP_SELF'];

if ($URL == "/index.php")
echo "You are on the main page";

?>


#3 mr_zhang

mr_zhang
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 29 October 2006 - 03:24 PM

Bingo! :D

Thanks man.

Genius. I've would never thought that it is inside the special variable.

Thanks again. Thanks a million.

Let me see if I got this straight (I'm not sure I really understand the question).
You're looking to make a script that figures out what the URL of the page it has been included in is, and then uses that information to decide what to do next?

I think you want something like this:
(main.php)

<?php
$URL = $_SERVER['PHP_SELF'];

if ($URL == "/index.php")
echo "You are on the main page";

?>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users