Dark-Hawk Posted June 5, 2007 Share Posted June 5, 2007 Alright, I used to use an ereg expression to check a posted variable to create links suchs as index.php?class=blah not entirely sure what you'd call that type of link, but yeah. Creating a webpage for a buddy of mine and I'm suddenly having issues with doing it this way. Here's the code I'm using: <? if ( (!$post) && (!ereg("^(about|gallery|forums|links|contact)$", $class)) ) { ?> Main page content <? } if ($class == "about") { about(); } ?> Just to ensure it wasn't something stupid with about(); I replaced it to just echo something small and it was a no go. I've tried if ($_POST['class'] == "about") and also $HTTP_POST_VARS['class'] and neither of them worked either. If someone has a different way of doing this or can shed some light on why this isn't working, that'd be great and much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/54207-issue-with-ereg-expression/ Share on other sites More sharing options...
redarrow Posted June 5, 2007 Share Posted June 5, 2007 sorry but goto www.php.net or www.w3school.com as a lot has changed from the old style of php example $_POST['varable_name'] and $_GET['varable_name'] and meny more new code statement exist now. also lookup eregi agin ok. Quote Link to comment https://forums.phpfreaks.com/topic/54207-issue-with-ereg-expression/#findComment-268013 Share on other sites More sharing options...
Dark-Hawk Posted June 5, 2007 Author Share Posted June 5, 2007 Yeah I figured thats what it'd be a case of. I'll go read through the manuals on php.net Quote Link to comment https://forums.phpfreaks.com/topic/54207-issue-with-ereg-expression/#findComment-268074 Share on other sites More sharing options...
MemphiS Posted June 5, 2007 Share Posted June 5, 2007 <?php if ((isset($_GET['class'])) && (ctype_alpha($_GET['class']))){ $class = $_GET['class']; $arrayPages = array("about","gallery","forums","links","contacts"); if (!in_array($class, $arrayPages, true)){ echo("Error page doesnt exist."); }elseif (in_array($class, $arrayPages, true)){ if ($class == "about"){ about(); } } ?> This isnt tested just wrote it up quickly sorry if theres an error... You could use the above to check for a valid page name Quote Link to comment https://forums.phpfreaks.com/topic/54207-issue-with-ereg-expression/#findComment-268077 Share on other sites More sharing options...
Dark-Hawk Posted June 5, 2007 Author Share Posted June 5, 2007 <?php if ((isset($_GET['class'])) && (ctype_alpha($_GET['class']))){ $class = $_GET['class']; $arrayPages = array("about","gallery","forums","links","contacts"); if (!in_array($class, $arrayPages, true)){ echo("Error page doesnt exist."); }elseif (in_array($class, $arrayPages, true)){ if ($class == "about"){ about(); } } ?> This isnt tested just wrote it up quickly sorry if theres an error... You could use the above to check for a valid page name Great thanks a lot man. I'll give it a try, no worries if it doesn't work I can figure it out from here. Appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/54207-issue-with-ereg-expression/#findComment-268081 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.