[thelist] Function for listing a page's URL

Brian Cummiskey Brian at hondaswap.com
Thu Feb 10 13:04:50 CST 2005


Dominick Cancilla wrote:
> I'd like to add a function to my Website's footer that would list the page's
> URL (as a reminder to credit the page if it is quoted elsewhere). 

This should do the trick for you:


//---------page start --------------------
<?php
function pathfinder() {
     $root = 'http://www.yourdomain.com';
     $prefix = 'Be Nice- Link this page if you use it: ';
     $url = $_SERVER['REQUEST_URI'];

	$crumb = $prefix.$root.$url;

     return $crumb;
}

?>

<html>
<head>
<title>blah</title>
</head>

<body>
	<?php echo pathfinder(); ?>
</body>
</html>

//---------page end --------------------


please note- that this MUST be on a .php page.  inserting this into 
index.html, for example, will simply print out the text- not execute.

so, if you're site is big-- this may be a big problem for you, changing 
all your pages to a .php extention, as well as losing all your links, 
search engine listings as so forth....

an advanced option is to configure html to process as a .php
take a look here: http://www.desilva.biz/php/phpinhtml.html

This creates a lot of server overhead though, as everything will get 
processed for no good reason sometimes (html doesn't need to be parsed 
by php)


The other option is to do it with JS...  but this could be browser 
dependent, and the user may have JS off, thus making the script not execute.


//---------------- page start------------------

<html>
<head>
<title></title>

<script type="text/javascript">

var currentURL = document.location.toString();
var thepathtext = "Be Nice- Link to us: ";

var thepath = thepathtext + currentURL;

</script>

</head>

<body>
	<script type="text/javascript">
		document.writeln(thepath);
	</script>
</body>
</html>

//---------------- page end ----------------------


If this doesn't help you, I give up :D

Good luck.

-Brian


More information about the thelist mailing list