Jump to content


Photo

mod_layout and include()


  • Please log in to reply
4 replies to this topic

#1 bugscripts

bugscripts
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 September 2006 - 11:10 PM

[I am asking this for someone else]
Say I want some PHP code executed on all pages in a certain directory.
If I add a PHP include() to the top of all pages with mod_layout, and have this in the included file test.php:
<?php
echo $_SERVER['PHP_SELF'];
?>
On the page test.html (and all other pages, just an example) I get this printed:

/test.php

I want this printed:

/test.html

Thanks for any help! :)

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 19 September 2006 - 12:05 AM

I can think of a couple ways that you can do this. You could ether use preg_replace or an explode function. Here is an example of explode.

$p = $_SERVER['PHP_SELF'];
list($page, $ext) = explode(".", $p);
echo $page . '.html';

This may not be the most efficent way of doing this but it will work.

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 bugscripts

bugscripts
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 September 2006 - 03:28 PM

That's not exactly what I meant. I want it to determine the name of the page mod_layout is including it into, but instead it is giving me the name of the script that is supposed to determine it.

Sorry if I am not making any sense  :)

#4 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 19 September 2006 - 03:36 PM

Hi,

Just use this. Please note that it doesn't work on a windows server only apache.

<?php
echo $_SERVER['REQUEST_URI'];
?>

#5 bugscripts

bugscripts
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 September 2006 - 09:22 PM

That doesn't work, and the other methods of printing the URL that I know of do the same thing.

I tested it with a regular include(), and it works as expected.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users