Jump to content


Photo

if page = something.php


  • Please log in to reply
4 replies to this topic

#1 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 24 July 2006 - 06:39 PM

How can I make a code like:

<?php if $page == 'blah.php'; {

echo "blah";}

else{

echo "blahblah"; }

?>

Where $page = the page.  Like if you were at login.php wit would be login.php.

How can I tell it that $page = the filename of the page?

#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 24 July 2006 - 06:41 PM

Try

$page = basename($_SERVER['PHP_SELF']);

Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 24 July 2006 - 06:41 PM

There is a variable called $_SERVER['PHP_SELF'] that gets the current script location.  Be warned, this will return very strange results on shared hosting.  It gives something completely off base on my shared hosting.

EDIT: What does 'basename' do?
EDIT EDIT: php.net/basename shed some light on this, it fixes the problem I mentioned.  Silly me.  Sorry about that.

#4 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 24 July 2006 - 06:43 PM

Ah, ok, thanks.

#5 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 24 July 2006 - 06:43 PM

basename returns the filename component of a path
http://us2.php.net/m...on.basename.php
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users