djkirstyjay Posted March 21, 2010 Share Posted March 21, 2010 Good evening folks. I could do with a little assistance with some PHP I am attempting. I apologise in advance if it seems basic, but to me it's a little confusing. I have put a page navigation system on my site using a menu.php include with links such as the following : <ul> <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?main=homepage">Homepage</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?main=about">About Us</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?main=contact">Contact Us</a></li> </ul> I have included the following code in the main body of index.php : <?php if(!isset($_GET['main']) or $_GET['main'] == "") { $loadpage = "homepage.php"; } elseif (is_file($_GET['main'] . ".php")) { $loadpage = $_GET['main'] . ".php"; } else { $loadpage = "includes/error.php"; } include($loadpage); ?> All is working fine for any of the pages in the site root, but if I want to link to a page in a sub folder, this is where it all goes horribly wrong and that's what I need to do... So, say that I want to link to my gallery index page which is located in gallery/index.php, how would I do that? I have tried the following, which seemed logical to me : <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?main=gallery/index">Gallery</a></li> but it didn't work... so I could do with help if anyone can point me in the right direction! Thanks in advance Link to comment https://forums.phpfreaks.com/topic/196062-using-php-for-site-navigation-to-pages-in-subfolders/ Share on other sites More sharing options...
teamatomic Posted March 22, 2010 Share Posted March 22, 2010 try main=/gallery/index you might also echo $loadpage to see if its what you expect But what you should really do is is this: $url='http://myDomain.com'; include("$url/$loadpage"); HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/196062-using-php-for-site-navigation-to-pages-in-subfolders/#findComment-1029801 Share on other sites More sharing options...
DavidAM Posted March 22, 2010 Share Posted March 22, 2010 I don't think you want to include from a URL. That forces a network call instead of just a read from the file system. It is more likely that the value of $_GET['main'] is escaped or url encoded in some way. You need to look at what the value is when you use the subdirectory. If gpc_magic_quotes is on, you will have to stripslashes() on that value before trying to use it. Link to comment https://forums.phpfreaks.com/topic/196062-using-php-for-site-navigation-to-pages-in-subfolders/#findComment-1029808 Share on other sites More sharing options...
djkirstyjay Posted March 22, 2010 Author Share Posted March 22, 2010 Thanks. I have just tried using main=/gallery/index but no joy there. I will look at the other suggestions when I have chance later, as I am currently away from home and accessing remotely. Any more suggestions welcome... Link to comment https://forums.phpfreaks.com/topic/196062-using-php-for-site-navigation-to-pages-in-subfolders/#findComment-1029913 Share on other sites More sharing options...
djkirstyjay Posted March 22, 2010 Author Share Posted March 22, 2010 Thanks to all for the help, as I did as suggested and found out the result of $loadpage only to make myself more confused, as it seemed to be fine... then I discovered that the page I was linking to didn't actually exist yet, hence the error. Now... how silly do I feel after spending hours wondering why it didn't work! Doh! Link to comment https://forums.phpfreaks.com/topic/196062-using-php-for-site-navigation-to-pages-in-subfolders/#findComment-1030103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.