Question:

How to use PHP instead of frames?

by Guest59130  |  earlier

0 LIKES UnLike

At first, I used iframes, but I hear that frames are a no-go. And now I hear PHP is the way to go. I have index.php. I have a specific div in my index.php that contains my main content and that is to be changed when someone clicks one of my four navi links (home, content, tutorials, site). I want to do this without reloading the entire page. Anyone have any ideas how to do this? I'm new to PHP, but I'm pretty fluent in CSS and HTML. Thanks. (:

 Tags:

   Report

2 ANSWERS


  1. Without frames, the only way to do this -- without reloading the page -- would be via JavaScript, either as an AJAX control or simply populating ALL your pages in script then showing/hiding them as necessary. (But the second option will greatly increase the size and download time of your page.)

    Otherwise, you would have to reload the page every time the user clicks a link.


  2. You can do something like this to start out. It's very basic. The entire page will still load to the user

    browsing your site, but you wont have multiple files on your site with the same code, so it will be

    easier to maintain. The only way if you really don't want your page to load again is to use AJAX.

    Each link will be like this

    index.php (this is home)

    index.php?page=content

    index.php?page=tutorials

    index.php?page=site

    Create a folder called content and put just the information that was originally in iframe into files like

    content.php, site.php, etc.

    The index.php file will look like this where your iframe once was:

    <?

    //sets the default page to home

    $page_content = "./content/home.php";

    //if loading a different page, which one?

    if(isset($_GET['page'])){

    switch($_GET['page']){

    case "content":

    $page_content = "./content/content.php";

    break;

    case "tutorials":

    $page_content = "./content/tutorials.php";

    break;

    case "site":

    $page_content = "./content/site.php";

    break;

    }

    }

    //load the contents into my site

    include($page_content);

    ?>

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.