Jump to content

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,
Link to comment
https://forums.phpfreaks.com/topic/25450-solved-fetching-caller-url/
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]
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.