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,

Link to comment
Share on other sites

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"

 

 

 

Link to comment
Share on other sites

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.