Miko Posted August 12, 2009 Share Posted August 12, 2009 Hi, I have some trouble with including / requiering files. I have this kind of structure in my htdocs folder: - movie - config - admin - lib So the goal is that when my webapp is ready, I will send it to some friends, colleges etc to test, but off course, not everyone will paste my files it in the same location and not everyone that I know works with windows. So let's say in the root folder 'movie' I have 1file containing anchors and so on. in the admin folder I have index.php file, in this one there is a require("../sidebar.php") (sidebar.php in root of movies). in the sidebar there are some echoes like <a href="view_list.php?bla=blabla"> So when I go to http://localhost/movie/admin/index.php I have my anchor that is like this: http://htdocs/movie/admin/view_list.php?bla=blabla . not really correct huh? should be http://movie/view_list.php?bla=blabla., but when I go to for ex: http://localhost/movie/index.php and I put there a require for the sidebar.php the anchor is shown correctly and that's correct Is there a some kind of global variable in php where that you can tell what the root is, or where to "start"? Quote Link to comment https://forums.phpfreaks.com/topic/169904-solved-relative-path/ Share on other sites More sharing options...
wildteen88 Posted August 12, 2009 Share Posted August 12, 2009 What is the code you're using to generate your links? Quote Link to comment https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896318 Share on other sites More sharing options...
Miko Posted August 12, 2009 Author Share Posted August 12, 2009 the ones in my sidebar.php? <?php echo "<li class=\"list2\"><a href=\"view_list.php?genre=$name_genre&main_id=$id\">".$name_genre."</a></li>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896319 Share on other sites More sharing options...
wildteen88 Posted August 12, 2009 Share Posted August 12, 2009 I do not get what you mean by So when I go to http://localhost/movie/admin/index.php I have my anchor that is like this: http://htdocs/movie/admin/view_list.php?bla=blabla . not really correct huh? should be http://movie/view_list.php?bla=blabla., but when I go to for ex: http://localhost/movie/index.php and I put there a require for the sidebar.php the anchor is shown correctly and that's correct Where is view_list.php located? Quote Link to comment https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896321 Share on other sites More sharing options...
Miko Posted August 12, 2009 Author Share Posted August 12, 2009 sorry, forgot to mention it it is in the root movie Quote Link to comment https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896322 Share on other sites More sharing options...
wildteen88 Posted August 12, 2009 Share Posted August 12, 2009 You'll want to make this your link echo "<li class=\"list2\"><a href=\"/movie/view_list.php?genre=$name_genre&main_id=$id\">".$name_genre."</a></li>"; So if you include sidebar.php in movies/admin/index.php the link should always go to http://localhost/movies/siderbar.php HTML paths are not the same as file paths in PHP. A / at the start of the link will call the requested file from the root of the url, get http://localhost/ Quote Link to comment https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896325 Share on other sites More sharing options...
Miko Posted August 12, 2009 Author Share Posted August 12, 2009 owkay, it works, it was actually that obvious thanks! Quote Link to comment https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896328 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.