Page 1 of 1
Scriptname of parent script
Posted: Mon Apr 09, 2007 3:02 pm
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?
Posted: Mon Apr 09, 2007 3:08 pm
by feyd
Why does it need to know which script called it?
Re: Scriptname of parent script
Posted: Mon Apr 09, 2007 3:21 pm
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')
Posted: Mon Apr 09, 2007 3:23 pm
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.
Posted: Mon Apr 09, 2007 3:38 pm
by andym01480
Everah | Please use 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
Everah | Please use 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]
Posted: Mon Apr 09, 2007 6:20 pm
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