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?
Scriptname of parent script
Moderator: General Moderators
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
Re: Scriptname of 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')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!
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
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.
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.
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
Everah | Please use
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 isCode: 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]- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You set the name of the parent page in the parent page then reference it in the included page:
parent.php
calendar.php
parent.php
Code: Select all
<?php
$page_name = basename(__FILE__);
include 'calendar.php';
?>Code: Select all
<?php
echo $page_name;
?>