Web Hosting Talk







View Full Version : PHP Layout Includes Help


WebDivx
05-19-2007, 01:55 PM
I just switched hosts and my site has totally gotten messed up.

I have one of those urls that go like this my http://mysite.com/?file=MyFile
Ok, so you go to my site, mysite.com and the php calls mainpage.html. Everything looks fine and dandy. BUT when I go to another page, say Page 2 (http://mysite.com/?file=Page2) the same content from my main page comes up as opposed to the Page 2 stuff. It use to work find on my old host, but not with my new host Godaddy. Here is the code I use to use

<?php
$page = $HTTP_GET_VARS['file'];
$extension = "txt";
if ( !$page || $page == "" )
{ include "/my/path/mainpage.html"; }
else ( file_exists( "/my/path/$page.$extension" ) )
?>

How can I fix this? Does anybody have another code that is Godaddy compatible? Help is much appreciated!

Engelmacher
05-19-2007, 02:04 PM
For starters HTTP_GET_VARS is deprecated and you're pretty much just asking for security problems by failing to validate your input. Secondly, you should probably use empty() to test for $page's existence. And lastly, your conditional statement makes absolutely no sense. file_exists() isn't going to output anything to the browser as you seem to think it will, and you aren't even checking the return value. Frankly I don't believe this particular chunk of code ever "worked."

WebDivx
05-19-2007, 02:12 PM
For starters HTTP_GET_VARS is deprecated and you're pretty much just asking for security problems by failing to validate your input. Secondly, you should probably use empty() to test for $page's existence. And lastly, your conditional statement makes absolutely no sense. file_exists() isn't going to output anything to the browser as you seem to think it will, and you aren't even checking the return value. Frankly I don't believe this particular chunk of code ever "worked."

i dunno... it did what i wanted to do for a year. but, can you please suggest an alternative code?

Renard Fin
05-19-2007, 07:48 PM
That should do the job.


$page = $_GET['page'];
$dir = 'pages/';
$ext = '.php';

// remove evil others chars than alpha-numeric chars
$page = preg_replace("[^A-Za-z0-9]", "", $page);

if ( file_exists($dir . $page . $ext))
{
require ($dir . $page . $ext);
}

KiranHost
05-20-2007, 04:08 PM
Switching the line "$page = $HTTP_GET_VARS['file'];" to "$page = $_GET['file'];" should do the trick.