jadedmonkeys Posted May 7, 2010 Share Posted May 7, 2010 Hello folks, It's my first post here. I am currently working on a page where I have made a header and a footer and have a bunch of html text files that I'd like displayed in a DIV called 'stage' for example. since I have only 3 unique php files with their own header/footer and about 50 of these html text files I'd like to figure out a way to get a URL sort of like. example.com/main.php?content=textfile1.html example.com/nav.php?content=textfile2.html where the php file is the header/footer file with a DIV named 'stage' inside of it and I'd like to display the html in textfile1.html inside the stage div. I'm thinking of using php include but i dont know how that would work since I'd have to already specify what I want to include in the php whereas in this case I'd like to specify what I want to include from the URL. I don't know where to do begin on this. Thank you in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/201023-php-include-help/ Share on other sites More sharing options...
ChaosKnight Posted May 7, 2010 Share Posted May 7, 2010 Try this: <?php if(isset($_GET['content'])){ $content = $_GET['content']; } include($content); ?> Quote Link to comment https://forums.phpfreaks.com/topic/201023-php-include-help/#findComment-1054697 Share on other sites More sharing options...
kenrbnsn Posted May 7, 2010 Share Posted May 7, 2010 Try this: <?php if(isset($_GET['content'])){ $content = $_GET['content']; } include($content); ?> You really should validate any input coming from the URL or you will get burned. <?php $valid_content = array('content1.html','content2.html','content3.html'); //put all of the valid filenames in the array if (isset($_GET['content']) && in_array($_GET['content],$valid_content) && file_exists($_GET['content'])) { include($_GET['content']); } else { include('default_contents.html'); // show default page } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/201023-php-include-help/#findComment-1054704 Share on other sites More sharing options...
gwolgamott Posted May 7, 2010 Share Posted May 7, 2010 Guess I'm a little lost on what you mean, but do you mean something like this... Needs to be customized to your needs, but it's a start for you.... if you need help sifting through that let me know. Just assuming you can take out of that what you need. URL IS SOMETHING LIKE THIS ---> /index.php?page=Employee <?php // Check if page has been requested if (!isset($_REQUEST['page'])) { $page = '/main.html'; } else { // request page here $page = $_REQUEST['page']; $page = ('/'.$page.'html'); } // End if page has been requested // Check to see if page exists if (file_exists($page)) { // Page exists // Show page include("$page"); } else { // Page doesn't exist echo 'Sorry, the page that you are trying to access does not exist.'; } // End if page exists ?> Quote Link to comment https://forums.phpfreaks.com/topic/201023-php-include-help/#findComment-1054707 Share on other sites More sharing options...
ChaosKnight Posted May 7, 2010 Share Posted May 7, 2010 Also, you shouldn't use filenames like that in the URL, rather use a switch statement and use related references such as: content=home, instead of content=home.html. It's never a good idea to send too much info about how the files are structured and make it visible for everyone to see... Quote Link to comment https://forums.phpfreaks.com/topic/201023-php-include-help/#findComment-1054756 Share on other sites More sharing options...
jadedmonkeys Posted May 9, 2010 Author Share Posted May 9, 2010 Awesome, I was able to incorporate all of the suggestions and it worked. Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/201023-php-include-help/#findComment-1055496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.