blufish Posted May 31, 2008 Share Posted May 31, 2008 So I have a page like http://www.frozenoven.com/index.php when someone goes here I want it to check if $_GET['where'] is set, if not I want it to go to http://www.frozenoven.com/index.php?where=home heres part of the code I was attempting at: if (isset($_GET['where'])) { if (file_exists($_GET['where'])) { echo file_get_contents($_GET['where']); } if (!file_exists($_GET['where'])) { echo "<h1 align=center>404 File not Found!</h1><p>Either the file you are looking for does not exist or you typed the url wrong.</p><p align=center><a href='http://www.frozenoven.com'>Home</a>"; } } else { echo ("<script type='text/javascript'>window.location='http://www.frozenoven.com/index.php?where=home';</script>"; } Thanks in advance for the help! Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted May 31, 2008 Share Posted May 31, 2008 The way I'd do it is have a folder called 'pages'. Then have the following: <?php $pages = array('home', 'about', 'help'); // Basically, a list of allowed pages if(isset($_GET['where']) && in_array($_GET['where'], $pages)) { echo file_get_contents('pages/'. $_GET['where'] .'.php'); // Change .php to your page extension } else { echo file_get_contents('pages/home.php'); // Else, echo home page. } ?> Quote Link to comment Share on other sites More sharing options...
Prismatic Posted May 31, 2008 Share Posted May 31, 2008 You're working yourself into a redirect loop here. You're checking if where=home, then redirecting to index.php?where=home, which will run your check again, redirecting you again. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted May 31, 2008 Share Posted May 31, 2008 Oh yeah, I missed that. Sure you don't want to ignore the redirect? Quote Link to comment Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 Oh yeah, I missed that. Sure you don't want to ignore the redirect? If I don't redirect I get an error because it can't find a file file to show. You're working yourself into a redirect loop here. You're checking if where=home, then redirecting to index.php?where=home, which will run your check again, redirecting you again. I'm checking to see if someone is at page: http://www.frozenoven.com/index.php When they should be at: http://www.frozenoven.com/index.php?where=home That's not a loop. Quote Link to comment Share on other sites More sharing options...
Prismatic Posted May 31, 2008 Share Posted May 31, 2008 <?php if(!$_GET['where']) { header("Location: index.php?where=home"); } ?> Quote Link to comment Share on other sites More sharing options...
blufish Posted May 31, 2008 Author Share Posted May 31, 2008 this is supposed to load whatever page is set at where like http://www.frozenoven.com/index.php?where=jokes Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted May 31, 2008 Share Posted May 31, 2008 if $_get(where) = ('') then echo // page not found else echo //blah i know its not in php form that because i don't understand the brackets stuff. Quote Link to comment 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.