Jump to content

Archived

This topic is now archived and is closed to further replies.

mr_zhang

[SOLVED] Fetching caller URL??

Recommended Posts

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)
[code].....
<? include('main.php'); ?>
......[/code]

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.com/Sub1/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,

Share this post


Link to post
Share on other sites
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)
[code]
<?php
$URL = $_SERVER['PHP_SELF'];

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

?>
[/code]

Share this post


Link to post
Share on other sites
Bingo! :D

Thanks man.

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

Thanks again. Thanks a million.

[quote author=ksteuber link=topic=113086.msg459376#msg459376 date=1162105360]
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)
[code]
<?php
$URL = $_SERVER['PHP_SELF'];

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

?>
[/code]
[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.