Jump to content

Recommended Posts

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 :)

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.

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... :D

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!  ::)  :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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