Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.