johncollins Posted January 13, 2009 Share Posted January 13, 2009 hi. im new here as im currently learning php and thought this might be a good place to get some help on the things im unsure of. i want to make a web site with only one page but instead of the page changeing when i click on a link i want a php include to change or some other method of changing the page content. the method im currently using is the include is as followes. include "$page.php"; This variable is then (or rather is is supposed to but doesnt...) be changed when i click on a link as follows, <a href="mysite.com/welcome.php?page=secondpage"> then a picture is here instead of text... This doesnt seem to work... any ideas as to where im going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/ Share on other sites More sharing options...
timmah1 Posted January 13, 2009 Share Posted January 13, 2009 <?php $page = mysql_real_escape_string($_GET['page']); if($page =="firstpage"){ include("firstpage.php"); } if($page =="secondpage"){ include("secondpage.php"); } ?> and so forth Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736178 Share on other sites More sharing options...
killah Posted January 13, 2009 Share Posted January 13, 2009 <?php $page = $_GET['page']; swith($page) { case '$page': include($page); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736180 Share on other sites More sharing options...
uniflare Posted January 13, 2009 Share Posted January 13, 2009 <?php Switch($_GET['page']){ default: echo("Homepage. <a href='./?page=2'>Page 2</a>. <a href='./?page=guestbook'>Guestbook</a>"); break; case 2: echo("<a href='./?'>Homepage</a>. Page 2. <a href='./?page=guestbook'>Guestbook</a>."); break; case "guestbook": echo("<a href='./?'>Homepage</a>. <a href='./?page=2'>Page 2</a>. Guestbook."); break; } ?> Be careful with input from clients, ie. anything in the url, or form data. ($_GET,$_POST,$_COOKIE,$_REQUEST) even some $_SERVER['REMOTE_ADDR'] type globals can be compromised; Using predefined page names or numbers eliminates including or displayed malicious code. Save the above code to test.php and load it up. Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736181 Share on other sites More sharing options...
waynew Posted January 13, 2009 Share Posted January 13, 2009 Be sure to set a default in your switch statement. Bring it to a 404 folder. I often find that this style of website is easier to maintain by creating a folder for the processes of each page and a folder for the body of each page. That way you can easily just include files based on the $_GET value being received. Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736244 Share on other sites More sharing options...
waynew Posted January 13, 2009 Share Posted January 13, 2009 <?php $page = mysql_real_escape_string($_GET['page']); if($page =="firstpage"){ include("firstpage.php"); } if($page =="secondpage"){ include("secondpage.php"); } ?> Why are you cleaning $_GET['page']? Unless you're planning on using $page in a query, there's absolutely no point in trying to escape it. Also, if there isn't a connection in existence, this will cause a nasty looking warning. Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736247 Share on other sites More sharing options...
killah Posted January 13, 2009 Share Posted January 13, 2009 <?php $page = $_GET['page']; if(file_exists($page.'.php')) { include($page.'.php'); } else { echo 'Page not found.'; } ?> You could use that. But then your url's will need to either be: http://www.domain.com/?page=firstpage OR http://www.domain.com/index.php?page=firstpage And you need to use the according file name without the .php or .txt or .html or what so ever. Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736248 Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 <?php $page = $_GET['page']; if(file_exists($page.'.php')) { include($page.'.php'); } else { echo 'Page not found.'; } ?> You could use that. But then your url's will need to either be: http://www.domain.com/?page=firstpage OR http://www.domain.com/index.php?page=firstpage And you need to use the according file name without the .php or .txt or .html or what so ever. To add to this, use basename on the get data, to avoid them changing directories on you: <?php $page = basename($_GET['page']); if(file_exists($page.'.php')) { include($page.'.php'); } else { echo 'Page not found.'; } ?> That will be more secure. Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736282 Share on other sites More sharing options...
johncollins Posted January 13, 2009 Author Share Posted January 13, 2009 wow omg... look at all the replies... well i see where iv gone wrong.. an if statement seems so obvious now xD thanks for the help everyone.. il post when i get it working Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736349 Share on other sites More sharing options...
johncollins Posted January 13, 2009 Author Share Posted January 13, 2009 thanks all. got it working with <?php $page = mysql_real_escape_string($_GET['page']); if($page =="firstpage"){ include("firstpage.php"); } if($page =="secondpage"){ include("secondpage.php"); } ?> . now to sort my login script xD Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736362 Share on other sites More sharing options...
killah Posted January 13, 2009 Share Posted January 13, 2009 Let's just say by using your script.. We have 100 page's. 100 x 3 => 300. 300 Line's of code. To find fiftyforthpage.php and remove it. Very self complicated. And time taking. Using: <?php $page = basename($_GET['page']); if( file_exists($page.'.php') ) { include($page.'.php'); } else { echo 'Page not found'; } ?> I think you have a better chance at removing a link as simple as removing the link from the place you want to take it away and removing the file. You could even restrict page's by using this code: $errno = array('test','call'); //add more to it if u like if( in_array($errno, $page.'.php') ) { echo 'Page currently disabled.'; } Just my 2 cent's. Quote Link to comment https://forums.phpfreaks.com/topic/140670-one-site-one-page/#findComment-736476 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.