Jump to content

[SOLVED] Preg_Match List: Accepting Slashes / Folder access?


endofradio

Recommended Posts

Hi -

I feel awful to ask such a basic question but I'm at my wits end. I'm currently using this standard script:

 

<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = '1';
}

if (preg_match('/^[a-z0-9_-]+$/i', $id)) {
require('./' . $id . '.php');
} else {
die('Invalid Input');
}
?> 

 

To avoid manipulation of my links. However, I wish to allow the '/' symbol to be used, so that I can call files from a directory under the name 'portfolio' (because I require a $count function on these files, they have to be in a seperate folder). I simply cannot make it work.

 

Thanks to anyone that can solve the problem.

try

<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = '1';
}
$id = 's/adr/index'; //for testing

if (preg_match('/^[a-z0-9_-]+[\/a-z0-9_-]+[a-z0-9_-]+$/i', $id)) { 
//require('./' . $id . '.php');
echo 'OK';
} else {
die('Invalid Input');
}
?> 

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.