Jump to content

retrive the php file name that is currently executed on web server.


yingzhao

Recommended Posts

Hi all,

 

Not sure whether what I asked for is doable in php, since I am relatively new to php.

 

I have a child.php, which has the following line of code.

 

===================

echo '<a href="child.php?blah=new">do something</a>';

===================

 

I want to change this line of code to something like this.

 

===================

echo '<a href="' . $page . '?blah=new">do something</a>';

===================

 

So that when the child.php is execute on the server, child.php becomes the value for $page.

 

And in my other parent.php, I would like to use line of code to improve code reusability as.

 

===================

include_once 'child.php';

===================

 

But when parent.php is executed, parent.php becomes the value for $page.

 

How is this done in php coding?

 

Many thanks,

Take a look at the $_SERVER superglobal variable, mainly $_SERVER['PHP_SELF']:

 

http://php.net/manual/en/reserved.variables.server.php

 

It'll probably contain some more things depending on your actual URLs so you might need to prep it through some explode() to remove unwanted data such as the local directory if the PHP_SELF returns something like: "new/site/file.php"

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.