Jump to content

Issue with ereg expression


Dark-Hawk

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/54207-issue-with-ereg-expression/
Share on other sites

<?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  ;)

<?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!

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.