Jump to content

Archived

This topic is now archived and is closed to further replies.

AeonE

how to define the server root?

Recommended Posts

guys, I'have some question to ask
[quote]
eCom
| - eCom.php
|
| -Admin
| |- Admin.php
|
|- User
| |- User.php
[/quote]

where eCom is my TOP directory and Admin/user is a folder under eCom directory,

here's my question, how do I link those 3 together without repeating the hyperlink code? assuming in eCom.php I have created a hyperlink to Admin like this <?php echo "<a href=\"Admin/Admin.php>Admin Page</a>" ?> and of course my Home is <?php echo "<a href=\"eCom.php>Home</a>" ?>

so it looks like this in eCom.php,
[quote]
<?php echo "<a href=\"eCom.php>Home</a>" ?>
<?php echo "<a href=\"Admin/Admin.php>Admin Page</a>" ?>
<?php echo "<a href=\"User/User.php>User</a>" ?>
[/quote]

and for Admin.php,
[quote]
<?php echo "<a href=\"../eCom.php>Home</a>" ?>
<?php echo "<a href=\"Admin.php>Admin Page</a>" ?>
<?php echo "<a href=\"../User/User.php>User</a>" ?>
[/quote]

it works to link them together but...
I want a simple method that allows you to only need to define SERVER root to access files in that root, how you do that? meaning that I can remove this:

[quote]
<?php echo "<a href=\"../eCom.php>Home</a>" ?>
<?php echo "<a href=\"Admin.php>Admin Page</a>" ?>
<?php echo "<a href=\"../User/User.php>User</a>" ?>
[/quote]

for my admin.php , and only add include ('../eCom.php'); inside my Admin.php

what should I write in my eCom.php , please help!!!

many thanks

Share this post


Link to post
Share on other sites
you can always make a file say configs.php. And in the file you can set up your pages

[code]$ecom = "http://ecom.com/ecom.php";
$admin = "http://ecom.com/admin/admin.php";
$users = "http://ecom.com/users/user.php";[/code]

then on the top of each page you can just put in

[code]require('configs.php');[/code]

Then you can reference each page with the variable

[code]<?php echo "<a href=\"$ecom\">Home</a>" ?>
<?php echo "<a href=\"$admin\">Admin Page</a>" ?>
<?php echo "<a href=\"$users\">User</a>" ?>[/code]

And if you need to add some parameters to it then you can do it like this

[code]<?php echo "<a href=\"$ecom\">Home</a>" ?>
<?php echo "<a href=\"$admin\">Admin Page</a>" ?>
<?php echo "<a href=\"$users?id=2\">User</a>" ?>[/code]

There are other ways to get the document root but you would still have to enter in the folders after the root.

Ray

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.