Jump to content

how to define the server root?


AeonE

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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.