alejandro52 Posted September 15, 2010 Share Posted September 15, 2010 I have some links created dynamicaly with php. But i have the following problem. When i am in the root folder ieg. localhost/myPage/index.php the links work fine because they link in a file named entry.php. but when i am in a folder ieg. localhost/myPage/users/authors.php and i click the links they try to go to localhost/myPage/users/entry.php and i want them to link not inside the folder but to the root folder localhost/myPage/entry.php. Quote Link to comment Share on other sites More sharing options...
mraza Posted September 15, 2010 Share Posted September 15, 2010 can you show some code? Quote Link to comment Share on other sites More sharing options...
alejandro52 Posted September 15, 2010 Author Share Posted September 15, 2010 Can you understand what i am saying? The links go to <a href="entry.php"/> wehre entry.php is located inside localhost/mypage/ and when i click on thef from a file inside localhost/mypage/anotherfolder/index.php the link won't work cause it takes me to localhost/mypage/anotherfolder/entry.php and i want to go to localhost/mypage/entry.php Quote Link to comment Share on other sites More sharing options...
alejandro52 Posted September 15, 2010 Author Share Posted September 15, 2010 echo "<div><a href=\"auth.php?auth_id=".$row["auth_id"]. "\" class='sidebar_name'>".$row["fname"]. " " .$row["lname"]."<a/><br/>"; This takes me to localhost/mypage/auth.php?auth_id=".$row["auth_id"]. this is a sidebar menu , o use it with a dreamweaver template throughouth the site. when i click it from /localhost/mypage/user/staff.php it takes me to /localhost/mypage/user//auth.php?auth_id=".$row["auth_id"] where it should take me to /localhost/mypage/auth.php?auth_id=".$row["auth_id"] Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 15, 2010 Share Posted September 15, 2010 Maybe define a sitepath and place that infront of your variabe page part. That way you can move the files on your computer but if you keep the same map structure, you only have to edit the sitepath. Quote Link to comment Share on other sites More sharing options...
mraza Posted September 15, 2010 Share Posted September 15, 2010 you can use it with DOCUMENT_ROOT $dcroot = getenv("DOCUMENT_ROOT"); $dcroot . "/mypage/user/auth.php"; Quote Link to comment Share on other sites More sharing options...
Adam Posted September 15, 2010 Share Posted September 15, 2010 If you don't specify a path for the links, they'll default to the same directory. You need to specify either the relative path from the current directory: href="../entry.php" Relative from the document root: href="/myPage/entry.php" Or an absolute URL: href="http://localhost/myPage/entry.php" Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 15, 2010 Share Posted September 15, 2010 mraza, may i ask if that is a secure way, or does it has the same downside as a $_SERVER var. I really don't know so i thought i ask thx for this btw Quote Link to comment Share on other sites More sharing options...
alejandro52 Posted September 15, 2010 Author Share Posted September 15, 2010 SO if i have my site say at http://www.mysite.com it yould be ok to name my url link href=" http://www.mysite.com/entry.php' or would this slow the site responce? Quote Link to comment Share on other sites More sharing options...
mraza Posted September 15, 2010 Share Posted September 15, 2010 mraza, may i ask if that is a secure way, or does it has the same downside as a $_SERVER var. I really don't know so i thought i ask thanks for this btw please read more about getenv at here http://php.net/manual/en/function.getenv.php and ofc is secure as per my knowledge a comment from php.net This function is useful (compared to $_SERVER, $_ENV) because it searches $varname key in those array case-insensitive manner. For example on Windows $_SERVER['Path'] is like you see Capitalized, not 'PATH' as you expected. So just: <?php getenv('path') ?> Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 15, 2010 Share Posted September 15, 2010 Thanks I read it ;-) Quote Link to comment Share on other sites More sharing options...
Adam Posted September 16, 2010 Share Posted September 16, 2010 SO if i have my site say at http://www.mysite.com it yould be ok to name my url link href=" http://www.mysite.com/entry.php' or would this slow the site responce? Yeah that's perfectly fine, it won't make any difference with speed. All it is a path so that the browser knows where to go. I'm not sure what mraza's suggesting with using the server's document root, but $_SERVER['DOCUMENT_ROOT'] (which ever way it's accessed) is the server's file system path to the document root, not the browser's / publically accessible path. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.