Jump to content

Recommended Posts

Basically what I am trying to achieve is making sure any $page called originates from my server, but if no $page is defined, to include a default page I have set up. This is my code, and I cannot figure out what's wrong with it.

 

<?php
  $path = 'pages/';
  $extension = '.txt';

  if ( preg_match("#^[a-z0-9_]+$#i",$page) ){
    $filename = $path.$page.$extension;
    include($filename);
  }
if (!$page)
include 'pages/main.txt';
?>

 

An example URL I am using is www.mywebsite.com/index.php?$page=pages/tester

What am I doing wrong?

That would only happen if register_globals = On in the php.ini file, which it definitely should not.

 

You need to assign the value from the $_GET array to the variable you want to use. i.e. $page = $_GET['page'] or use $_GET['page'] directly.

Thank you very much, that fixed the problem. At first it wasn't working, then I realized that my urls were looking like index.php?page=pages/blah, after deleting pages/ from the url, everything worked fine. I greatly appreciate your help.

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.