...

View Full Version : Full Path Links



Goober
12-26-2003, 10:52 PM
I want to give all my links the full path to the desiered page. (instead of <a href="myfile.php">, use <a href="http://www.site.com/myfile.php">. Incase I change domains or something like that I want to use a variable of some some sort that give my links the full path.

Something like this maybe?:



<?php

$link_path = "http://www.mysite.com";

?>

Then maybe...


<html>
<head>
<title>Title</title>
</head>
<body>

<a href="{$link_path}/myfile.php</a>

</body>
</html>

but I don't think this will work, so what should I do?

Nightfire
12-26-2003, 11:16 PM
Two ways I'd do it are:



<?php
define("SITEURL","http://yourdomain.com");
?>

<html>
<head>
<title>Title</title>
</head>
<body>

<a href="<?php echo SITEURL; ?>/myfile.php</a>

</body>
</html>

Or


<?php
$siteurl = "http://yourdomain.com";
?>

<html>
<head>
<title>Title</title>
</head>
<body>

<a href="<?php echo $siteurl; ?>/myfile.php</a>

</body>
</html>

me'
12-27-2003, 12:08 PM
Or even (a bit shorter and easier to read, IMO)
$domain = "www.site.com";

...

<a href="<?=$domain?>/myfile.php">

Goober
12-28-2003, 03:27 AM
actually i just thought of a new one...

you can simply define the variable and then print the html code in the php code like this:



<?php

$site_url = "http://www.mydomain.com"

echo (

<html>
<head>
<title>Title</title>
</head>
<body>

<a href="{$site_url}/myfile.php</a>

</body>
</html>

);
?>


im not actually sure if that would work but it might. :p

firepages
12-28-2003, 03:51 AM
it would work for sure , but in general you would try and avoid echo()ing everything unless you actually needed to , sometimes functions or classes will return a block of HTML to be printed , but when doing so inline you are just making more work for the PHP interpreter which basically ignores everything that is not inside <?php ?> tags.

the difference in efficiency is minimal but it exists.

bcarl314
12-28-2003, 03:52 AM
Alternatively, you could use



<?php
print "<a href=\"http://".$_SERVER['HTTP_HOST']."/myFile.php\">Link</a>";
?>


the $_SERVER['HTTP_HOST'] will always be http://mydomain.com



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum