cprowitt Posted May 28, 2009 Share Posted May 28, 2009 I'm very very new to php and i've been using this code from a tut i found online for one of my pages. I have a feeling there is a very simple solution for what I want to do. The code explains itself so i'll get right into it... <?php // 1. Define an array of allowed $_GET values: $pass = array('p01s01','p02s01','p03s01','p04s01','p06s01','p07s01','p10s01','p12s01','p14s01'); // 2. If the page is allowed, include it: if (in_array($_GET['id'], $pass)) { include ('includes/AprilStories/' . $_GET['id'] . '.php'); } // 3. If there is no $_GET['id'] defined, then serve the homepage: elseif (!isset($_GET['id'])) { include ("includes/blank.php"); } // 4. If the page is not allowed, send them to an error page: else { // This sends the 404 header: header("HTTP/1.0 404 Not Found"); // This includes the error page: include ("includes/error.php"); } ?> I simply want to use regex for the very first part of the code where it defines an array of allowed $_GET values. Right now i have every page 'id' listed. I'd like to simplify that with regex so it will match "p[:digit:]{2}s[:digit:]{2}" I've tried everything and still cant get it to work....i think im trying to put the ereg in the wrong place. also here is the url for the page im trying to use regex on... www.obsrep.com/businessjournal thanks! Quote Link to comment https://forums.phpfreaks.com/topic/160022-solved-using-regex-define-an-array-of-allowed-_get-values/ Share on other sites More sharing options...
cprowitt Posted May 28, 2009 Author Share Posted May 28, 2009 the url is wrong.... www.obsrep.com/businessjournal/stories.php is the right url additionally i was trying to put the ereg() in the array()....not sure if that was right Quote Link to comment https://forums.phpfreaks.com/topic/160022-solved-using-regex-define-an-array-of-allowed-_get-values/#findComment-844167 Share on other sites More sharing options...
cprowitt Posted May 29, 2009 Author Share Posted May 29, 2009 ended up doing this... <?php // Define allowed $_GET values and if allowed, include it: if (preg_match( '/p\d{2}s\d{2}/', $_GET['id'] ) && file_exists('includes/AprilStories/' . $_GET['id'] . '.php')) { include ('includes/AprilStories/' . $_GET['id'] . '.php'); } // If there is no $_GET['id'] defined, then serve the homepage: elseif (!isset($_GET['id'])) { include ("includes/blank.php"); } // If the page is not allowed, send them to an error page: else { // This sends the 404 header: header("HTTP/1.0 404 Not Found"); // This includes the error page: include ("includes/error.php"); } ?> ...if anyone cares Quote Link to comment https://forums.phpfreaks.com/topic/160022-solved-using-regex-define-an-array-of-allowed-_get-values/#findComment-844882 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.