1

Ok here's my code

        $ref = $_GET['ref'];
        if (file_exists('views/'.$ref.'.php')) {
            $this->prepare($ref);
        } 
        elseif (!file_exists('views/'.$ref.'.php')) {
        echo 'Page you are requesting doesn´t exist';
        }

I'm currently having issues if users try to do ?ref=con or ?ref=com1 etc, file_exists will always return true. Is there a work around for this?

teorius
  • 35
  • 4
  • You could move to a Un*x server where this doesn't happen. There is likely also some registry patch to disable those old DOS compatibility device filenames. Or try one of those NT fs prefixes http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx – mario Apr 30 '11 at 18:53
  • @mario: you should make that an answer. I had no idea those were reserved filenames. – Chris Eberle Apr 30 '11 at 20:34

2 Answers2

2

Probably because those files actually exist. I'd be more worried about the potential for abuse. You should filter your inputs.

Also the elseif is unnecessary. else would suffice just fine.

Chris Eberle
  • 47,994
  • 12
  • 82
  • 119
0

Please try using: is_file http://php.net/manual/en/function.is-file.php

zokibtmkd
  • 2,173
  • 1
  • 22
  • 24