yingzhao Posted April 24, 2008 Share Posted April 24, 2008 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, Quote Link to comment Share on other sites More sharing options...
awpti Posted April 24, 2008 Share Posted April 24, 2008 __FILE__ Quote Link to comment Share on other sites More sharing options...
Aeglos Posted April 24, 2008 Share Posted April 24, 2008 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" Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 24, 2008 Share Posted April 24, 2008 This snippet should work: <?php $file = $_SERVER['PHP_SELF']; //it will be like "files/index.php" $file = explode('/', $file); echo $file = $file[count($file) - 1]; // show the last value of the array ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.