mr_zhang Posted October 29, 2006 Share Posted October 29, 2006 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, Quote Link to comment https://forums.phpfreaks.com/topic/25450-solved-fetching-caller-url/ Share on other sites More sharing options...
ksteuber Posted October 29, 2006 Share Posted October 29, 2006 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 Link to comment https://forums.phpfreaks.com/topic/25450-solved-fetching-caller-url/#findComment-116162 Share on other sites More sharing options...
mr_zhang Posted October 29, 2006 Author Share Posted October 29, 2006 Bingo! :DThanks 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] Quote Link to comment https://forums.phpfreaks.com/topic/25450-solved-fetching-caller-url/#findComment-116284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.