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
https://forums.phpfreaks.com/topic/108111-solved-_get-problem/
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
https://forums.phpfreaks.com/topic/108111-solved-_get-problem/#findComment-554127
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
https://forums.phpfreaks.com/topic/108111-solved-_get-problem/#findComment-554132
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.