simple way to get a dynamic php page to autogenerate a static html one?

3 replies
  • WEB DESIGN
  • |
well... my title pretty much says it all,

Is there a way to do this?

so if i have a php /mysql driven site, can i auto create pages into html for better search engine listings...?
#autogenerate #dynamic #html #page #php #simple #static
  • Profile picture of the author Jahnold
    The simplest way would be to have a central php file:

    pageserve.php

    which you would normally send some get request to such as:

    pageserve.php?pageid=1

    in the top of that you'd have some php like:

    Code:
    if (isset($_GET['pageid'])) { 
        $iPageid = $_GET['pageid']; 
    }
    else {
       $iPageid = $iStatic;
    }
    Then you could have a file elsewhere in the directory structure called something like:

    SEOFriendly.php

    which would just contain:

    Code:
    $iStatic = 4;
    require('pageserve.php');
    Matt
    {{ DiscussionBoard.errors[3366936].message }}
  • Profile picture of the author Evan-M
    Originally Posted by zsawevv212 View Post

    well... my title pretty much says it all,

    Is there a way to do this?

    so if i have a php /mysql driven site, can i auto create pages into html for better search engine listings...?
    something like this will look for any php files added to filelist.php and then will recreate the page with the same name and a .html extension. I think thats what you want to do ? You could then setup a cron job to run it every x number of min or seconds.

    you should also add some code to check the date of the 2 files and only recreate if the php file date is newer than the .html version, that way it only works when it has to.

    <?php
    $files = file("filelist.txt");
    for($i = 0; $i < count($files); $i++) {
    ob_start();
    include($files[$i]);
    $page = ob_get_contents();
    ob_end_clean();
    if(strpos($files[$i], ".php") > -1) {
    $file = fopen(substr($files[$i], 0,strlen($files[$i])-4) . ".html",'w');
    fputs($file, $page);
    fclose($file);
    }
    }
    ?>
    Signature

    Evan-M

    Easily The Worlds Best Wordpress Popup plugin

    Visit Website Design Firm For All Your Wordpress Coding Needs

    {{ DiscussionBoard.errors[3367083].message }}
  • Profile picture of the author SteveJohnson
    Originally Posted by zsawevv212 View Post

    well... my title pretty much says it all,

    Is there a way to do this?

    so if i have a php /mysql driven site, can i auto create pages into html for better search engine listings...?
    SEs really don't care whether the page they're crawling is an existing file or a dynamically-produced page - why are you wanting to go to all this trouble for nothing?
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[3368054].message }}

Trending Topics