Scriptname of parent script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Scriptname of parent script

Post by andym01480 »

I have a self contained calendar script that changes the month in view with a variable "m".

I want to be able to include it within any other php script with preferably just one include statement.

The next and previous links need to be able call the parent script and append the variable m.

The trouble is basname(__FILE__) and $_SERVER['PHP_SELF'] within calendar.php obviously return calendar.php not the name of the parent script!

So how can calendar.php know what script called it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why does it need to know which script called it?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Scriptname of parent script

Post by Weirdan »

andym01480 wrote:The trouble is basname(__FILE__) and $_SERVER['PHP_SELF'] within calendar.php obviously return calendar.php not the name of the parent script!
That depends on how you include the calendar script into your page. It seems you're using <iframe> (thus the $_SERVER['PHP_SELF'] == 'calendar.php')
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

If calendar.php is an include of index.php then the next link would need to be

index.php?m=value

I was wondering whether it was possible for calendar.php to know that it had been an include of index.php, so it could be used in any situation without customising!

That said two pre-written calendar scripts can't be included in other scripts. Those calendar scripts include headers or whatever themselved.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


No. I was trying it out, so index.php is

Code: Select all

<?php
include("calendar.php");
?>

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You set the name of the parent page in the parent page then reference it in the included page:

parent.php

Code: Select all

<?php
$page_name = basename(__FILE__);
include 'calendar.php';
?>
calendar.php

Code: Select all

<?php
echo $page_name;
?>
Post Reply