Point ahref to links.php(which controls all links)possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bhempel
Forum Newbie
Posts: 8
Joined: Wed Aug 12, 2009 1:26 pm

Point ahref to links.php(which controls all links)possible?

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Point ahref to links.php(which controls all links)possible?

Post by Ollie Saunders »

Sure, it's possible, almost trivial actually if you're willing to use header redirects.
bhempel
Forum Newbie
Posts: 8
Joined: Wed Aug 12, 2009 1:26 pm

Re: Point ahref to links.php(which controls all links)possible?

Post 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
Post Reply