Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Include And File Locations
Old 02-05-2008, 05:39 AM Include And File Locations
Rajaie's Avatar
Super Talker

Posts: 128
Trades: 0
Hey guys,

I'd really appreciate it if someone could tell me how to have links work correctly when using includes.
but without using the http://localhost/link/subdir.


Here are the files:
http://rajaie.alkorani.googlepages.com/MySite.rar

Last edited by Rajaie; 02-05-2008 at 05:56 AM..
Rajaie is offline
Reply With Quote
View Public Profile Visit Rajaie's homepage!
 
 
Register now for full access!
Old 02-05-2008, 06:00 AM Re: Include And File Locations
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
What is the problem exactly?

Including files has nothing to do with links representation. If you want to avoid problems use URLs relative to site root: /path/to/link instead of links relative to current folder: path/to/link.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-05-2008, 06:28 AM Re: Include And File Locations
Rajaie's Avatar
Super Talker

Posts: 128
Trades: 0
mmm... ****, this is hard to explain. anyways ill try my best.

when i include the navmenu on the index page, the links work as their supposed to.
but then when i include the navmenu from a subdir, the links dont work anymore,
so what im saying is: how do i get the links to work wherever they are on my site?
Rajaie is offline
Reply With Quote
View Public Profile Visit Rajaie's homepage!
 
Old 02-05-2008, 06:30 AM Re: Include And File Locations
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Mtishetsky just answered that:
Quote:
If you want to avoid problems use URLs relative to site root: /path/to/link instead of links relative to current folder: path/to/link.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-05-2008, 06:57 AM Re: Include And File Locations
Rajaie's Avatar
Super Talker

Posts: 128
Trades: 0
I have no idea how to explain it
see for yourslef




Site index code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Wireless Shack</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="includes/iestylesheet.php">
<![endif]-->
<link rel="stylesheet" type="text/css" href="includes/stylesheet.php">
<link rel="shortcut icon" href="images/favicon.ico" />
</head>
<body>
<div id="wrapper">
<a href=#><div id="header"></div></a>
<?PHP include('includes/navmenu.php'); ?>
<div id="main">
<div id="article"> 
<div id="articledetails">Article Details Go Here</div>
<div id="articlecontent">Article Goes Here</div>
<div id="articleimages">Article Images Go Here</div>
</div>
</div>
<div id="footer">
&copy; 2008-2009 The Wireless Shack 
&nbsp;
<a href="aboutus">About Us</a> |
<a href="contactus">Contact Us</a> |
<a href="login">Login</a> 
</div>
</div>
</body>
</html>
/downloads index.php code
Code:
<?PHP include('../includes/navmenu.php'); ?>
navmenu.php code
Code:
<div id="navmenu">
<form>
<input type="text" size="20"> 
<input type="submit" value="Search"> 
</form>
<a href="#" class="button">HomePage</a> |
<a href="../downloads" class="button">Downloads</a> |
<a href="../archives" class="button">Archives</a> |
<a href="../tags" class="button">Tags</a> 
</div>
When you access the menu from the /downloads index.php page, they work fine,
but when you access them from the sites main page, they dont work as supposed to

i've been trying to figure out a solution for hours, please help !

Last edited by Rajaie; 02-05-2008 at 07:18 AM..
Rajaie is offline
Reply With Quote
View Public Profile Visit Rajaie's homepage!
 
Old 02-05-2008, 07:40 AM Re: Include And File Locations
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
It's exactly what we told you.

You are using relative path, and you need to use absolute path.

Change
Code:
../downloads
tho the absolute path from your web site root.
Probably
Code:
/downloads
http://www.google.com/search?hl=en&l...=Google+Search
http://support.internetconnection.ne...le_Paths.shtml
http://www.ibdhost.com/help/path/
http://www.webdiner.com/webadv/begin/paths.htm
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-05-2008, 08:47 AM Re: Include And File Locations
Rajaie's Avatar
Super Talker

Posts: 128
Trades: 0
when i use /downloads it takes me to localhost/downloads and not localhost/mysite/downloads

i believe that this will only work if my site is located in the localhost (www) directory?


EDIT: Nevermind, I just added /mysite/ to the link. Now it works fine.
Thank you so much!!!

Second Edit:

When I try to include a navmenu.php from the downloads/index.php page using: <?PHP include('/MySite/includes/navmenu.php'); ?>
It gives me this error:

Warning: include(/MySite/includes/navmenu.php) [function.include]: failed to open stream: No such file or directory in D:\Wamp\www\MySite\downloads\index.php on line 1

Warning: include() [function.include]: Failed opening '/MySite/includes/navmenu.php' for inclusion (include_path='.;C:\php5\pear') in D:\Wamp\www\MySite\downloads\index.php on line 1


Is their something I don't know about PHP and paths?

Last edited by Rajaie; 02-05-2008 at 09:04 AM..
Rajaie is offline
Reply With Quote
View Public Profile Visit Rajaie's homepage!
 
Old 02-05-2008, 09:32 AM Re: Include And File Locations
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Is their something I don't know about PHP and paths?
Yes.
The php include() path must be relative (or absolute) related to the server file system.
The web path is different in this case.

You can rely on the $_SERVER['DOCUMENT_ROOT'] variable to determine where the web site root folder is located.

So, use something like
PHP Code:
include($_SERVER['DOCUMENT_ROOT']."/include/navmennu.php"); 
to always include the good file, no matter where you are in your site tree.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-05-2008, 09:51 AM Re: Include And File Locations
Rajaie's Avatar
Super Talker

Posts: 128
Trades: 0
It Worked! Thanks a lot!

Added to your talkupation!
Rajaie is offline
Reply With Quote
View Public Profile Visit Rajaie's homepage!
 
Reply     « Reply to Include And File Locations
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29169 seconds with 12 queries