Jump to content

New here armed with a php question


mynamesleo

Recommended Posts

Hi all  ;) I am new to the forum, googled php help and was located here!

I am a complete beginner in PHP, I know some basic [i]html[/i] though.

[b]Question[/b]

On my site I want it to load a page within a page, so I can keep the logo and "naviation" links at the top without having to have that code in every page on the site. A guy a while back did this for me bud sadly my FTP got wiped and I lost all the files.

I remember it was something like; site.com/?p=home, site.com/?p=contact, etc.. etc...


Hope this is enough information for you to know what I mean

Thanks in advance

Link to comment
Share on other sites

Of course there are many ways to do this, a simple example though. Call this index.php. then name all your other file contact.php, home.php etc etc...

[code=php:0]
// put your header code here.

<?php
if (isset($_GET['p'])) {
  $file = $_GET['p'].'php';
  if (file_exists($file)) {
    include $file;
  }
}
?>

// put your footer code here.
[/code]

Simply call your site via http://yoursite/index.php?p=home
Link to comment
Share on other sites

Actually I had to edit it on this line:

  [code]$file = $_GET['p'].'php';[/code]

Had to add a . in 'php'

[code]$file = $_GET['p'].'.php';[/code]


Ok now I wanted it to default to home.php whenever the site is visited (site.com) instead of index, I got this so far:

[code]
<?php



if (isset($_GET['p'])) {
  $file = $_GET['p'].'.php';
} else {
include "home.php";
}



if (file_exists($file)) {
    include $file;
  }


?>
[/code]


It seems to work, but is the code OK? I am just starting out in php but program in Visual Basic  ::)
Link to comment
Share on other sites

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.