bicho83 Posted March 18, 2007 Share Posted March 18, 2007 Ok, I am gonna try explaining my problem once again: You guys have seem websites where the URL has something like: somewebsite.com/?pageid=whatever right? Well I want to set up a website like that (because I don't want to rewrite the whole structure of the website in each and every content page). I don't know how to do that, but I know I am getting closer each time, and any help would be greatly appreciated. My Content pages are stored in a /content folder inside the root. My links are set up like this (for example): ./?page=privacy_policy I know I have to mess around with my index.php and declare some function. Every time somebody replies with some gibberish code that doesn't work (they assume things that I don't know). I have little knowledge of PHP. Link to comment https://forums.phpfreaks.com/topic/43212-solved-help-setting-up-dynamic-content-with-php/ Share on other sites More sharing options...
jokur Posted March 18, 2007 Share Posted March 18, 2007 If for instance you were trying to display content/privacy_policy.htm, it could be as simple as: <?php include('content/'.$_GET['page'].'htm'); ?> Link to comment https://forums.phpfreaks.com/topic/43212-solved-help-setting-up-dynamic-content-with-php/#findComment-209816 Share on other sites More sharing options...
JasonLewis Posted March 18, 2007 Share Posted March 18, 2007 here is a good way of doing it, like suggested above. you create your layout so it is coded but leave the content blank. then in that area place this code: $ext = ".php"; //the file extensions. if(!isset($_GET['page'])){ $page = "news"; }else{ $page = $_GET['page']; } $page = "content/".$page.$ext; if(!file_exists($page)){ echo "The requested page could not be found."; }else{ include($page); } then to access your links you would go: www.site.com/index.php?page=privacy_policy or www.site.com/?page=privacy_policy Link to comment https://forums.phpfreaks.com/topic/43212-solved-help-setting-up-dynamic-content-with-php/#findComment-209824 Share on other sites More sharing options...
shaunrigby Posted March 18, 2007 Share Posted March 18, 2007 More dynamic option would be to use a database, assign a unique ID to each page and create a function to find the page content with that ID number and include it... Link to comment https://forums.phpfreaks.com/topic/43212-solved-help-setting-up-dynamic-content-with-php/#findComment-209963 Share on other sites More sharing options...
bicho83 Posted March 18, 2007 Author Share Posted March 18, 2007 Jokur, your line of code freaking solve my tedious problem. Thanks so much man, you rock!!!!!!! Link to comment https://forums.phpfreaks.com/topic/43212-solved-help-setting-up-dynamic-content-with-php/#findComment-210174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.