Page 1 of 1
Point ahref to links.php(which controls all links)possible?
Posted: Fri Aug 21, 2009 2:47 am
by bhempel
Does anyone know if it is possible through the use of php to point a link (<a href="">) to a specific file in which all of the links are controlled? My reason behind this is that, although I already use the include function to minimize the amount of code, I may have links within the body of each page that are the same as on another page. Instead of having to go into each file to edit the url I would like to be able to edit and control the url's within one specific file (links.php).
Brandon
Re: Point ahref to links.php(which controls all links)possible?
Posted: Fri Aug 21, 2009 5:10 am
by Ollie Saunders
Sure, it's possible, almost trivial actually if you're willing to use header redirects.
Re: Point ahref to links.php(which controls all links)possible?
Posted: Fri Aug 21, 2009 6:53 am
by bhempel
I got the answer from "robnet" who suggested I use constants similiar to described below.
home.php
Code: Select all
?php require_once('pages.php'); echo "<a class='alt' href=". www_register.">Register</a>"; ?>
?php require_once('pages.php'); echo "<a class='alt' href=". www_process.">Login</a>"; ?>
and, pages.php
Code: Select all
<?php
define('www_root','http://localhost/youinfer_/');
define('www_register',www_root.'register.php');
define('www_process',www_root.'login.php');
?>
This worked great and allows me to control all links within pages.php. However, now I'm having trouble using the same piece of code for the forms (login.php and register.php).
I tried the below code, but that did not work; it just redirected me to home.php.
Code: Select all
Code: Select all
<?php require_once('pages.php'); echo "<form action=". www_process.">"; ?>
Also how might you do this if you are already inside with the php brackets?
EXAMPLE
Code: Select all
<a href="http://localhost/youinfer_/userinfo.php ?user=<?php echo $session->username; ?>"> Profile</a>
Any ideas?
Brandon