Jump to content

[SOLVED] $_GET Problem


blufish

Recommended Posts

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!  :)

 

Link to comment
Share on other sites

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.
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.