Development Blog

April 3, 2012
Retrieve previous and current directory name with PHP.
PHP


These methods are very helpful when I had to turn on the navigation buttons base on the page location. As you can see the "2012" button on the left sidebar is lit up.


How to retrieve previous directory name or page name with PHP referral.

RAW
<?php

$previousurl = $_SERVER['HTTP_REFERER'];
$portfoliourl = 'http://www.pinpointdesign.com/';
$lastpagename = str_replace($portfoliourl, '', $previousurl);

if ($lastpagename == 'development/') {
    echo "You came from our top page: " . $lastpagename;
  }
else {
    echo "There's no referral page.";
  }

?>


RESULT
There's no referral page.



How to declare your directory name in PHP.

RAW
<?php

if (strpos($_SERVER["PHP_SELF"], 'development/') > 0) {
  $subpath = 'development';
}
    	
echo $subpath;
?>


RESULT
development
Home | Portfolio | Expertise | Clients | People | Contact | Privacy Policy | Copyright Policy
Copyright © 2024 Pinpoint Design LLC. All Rights Reserved.