Jump to content

php links don't work


alejandro52

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/213486-php-links-dont-work/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/213486-php-links-dont-work/#findComment-1111357
Share on other sites

  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"]

Link to comment
https://forums.phpfreaks.com/topic/213486-php-links-dont-work/#findComment-1111360
Share on other sites

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"

Link to comment
https://forums.phpfreaks.com/topic/213486-php-links-dont-work/#findComment-1111378
Share on other sites

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') ?>

 

Link to comment
https://forums.phpfreaks.com/topic/213486-php-links-dont-work/#findComment-1111400
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/213486-php-links-dont-work/#findComment-1111593
Share on other sites

Archived

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

×
×
  • 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.