javascript - How should I use PHP $_GET and variables to fill my template page with content from other files? -
i'm new php , web development, , i'm trying figure out how design site little copy-and-pasted code possible. essentially, want each page use same layout, header menu, , footer; difference between each page stuff inside 'content_container'. simplified version of i'm working right now:
<?php $content = htmlspecialchars($_get["content_url"]);?> <body> <div id="main_container"> <?php require 'header.html';?> <div id="content_container"> <?php include $content;?> </div> <?php require 'header.html';?> </div> </body> all of site's 'content' stored in pages (about.html, social.html, etc.) should somehow loaded 'content_container' div of index.php 'template' page. way, should easy maintain , update site's content without touching template @ all. before this, tried using ajax load in content asynchronously wasn't able link directly individual pages through method, using php $_get seems better option.
i have idea of want do, unfamiliarity web development , syntax of php kind of roadblock me right now. so, how can use php $_get populate page content file? edit 1: or, going problem wrong way, , should doing instead?
edit 2: mere sake of learning, i'd kind of prefer see how kind of thing done using php (or js, if possible). know there lots of template libraries/frameworks out there, want understand how implement these kind of things on own if can.
so if understand you sending url variable this: http://www.yoursite.com/?content_url=http://www.yoursite.com/pages/about.html , plan want fetch url of file located, , include files contents current page.
i think missunderstand how people commonly use variables, , recommend not proceed in way doing it. bad several reasons. it's bad load content ajax, because google not able index content.
now answer: if still want use $_get load content page. this:
example url: http://www.yoursite.com/?page=about
php code:
<?php //check if variable "page" set "about", load about.html if($_get['page'] == "about"){ $content = file_get_contents("http://www.yoursite.com/pages/about.html"); } ?> you can read file_get_contents here http://php.net/file_get_contents
please note not "best" way solve urls websites. answer of how can achieve asking for. if want more advanced solution should mod_rewrite , .htaccess.
Comments
Post a Comment