vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How do I easily check if one variable equals ANY of a list of values? (https://vborg.vbsupport.ru/showthread.php?t=98680)

JJR512 10-18-2005 12:49 PM

How do I easily check if one variable equals ANY of a list of values?
 
In my Custom HTTP Error Pages hack, I use a variable $e. The value of $e comes from the URL, as in http://www.yoursite.com/forums/httperror.php?e=404.

I have a check in the script that checks for if $e has a value or not, and if not, it's set to 404 (because the 404 page is the accepted generic page to use if the exact error cannot be determined or does not wish to be revealed).

But I'd like to add another check that makes sure $e is set to an acceptable value, and if not, set it to 404.

Is there an easy way to check if $e is set to ANY item in a list like 400, 401, 403, 404, 405, etc.?

Ranma2k 10-18-2005 01:17 PM

Quote:

Originally Posted by JJR512
In my Custom HTTP Error Pages hack, I use a variable $e. The value of $e comes from the URL, as in http://www.yoursite.com/forums/httperror.php?e=404.

I have a check in the script that checks for if $e has a value or not, and if not, it's set to 404 (because the 404 page is the accepted generic page to use if the exact error cannot be determined or does not wish to be revealed).

But I'd like to add another check that makes sure $e is set to an acceptable value, and if not, set it to 404.

Is there an easy way to check if $e is set to ANY item in a list like 400, 401, 403, 404, 405, etc.?

best thing use switch function

PHP Code:


switch($e)
 case 
"400" : do fucntion 
          
break;
  case 
"401" : do function 
         break;
...... 

  case 
"404" 
   default : 
          do function ;
      
breake


or you can store the Value in an array and chek if the value in that array if not set it to 404
use the function inarray to check for it

PHP Code:

$erorr = array("400""401""402""403"....);
if (!
in_array($e,$erorr))
  
$e="404"


JJR512 10-18-2005 01:40 PM

Using the last example, the !inarray bit, if I have an existing IF statement to check the value of $e, can I combine that with this?

This is what I use already:
Code:

if ($e == '' OR !$e)
{
    $e = '404';
}

Can I make the IF statement like this...
Code:

if ($e == '' OR !$e OR !inarray($e,$error))
Assuming I've created the array before the IF statement (of course), will that work?

Ranma2k 10-18-2005 01:54 PM

Quote:

Originally Posted by JJR512
Using the last example, the !inarray bit, if I have an existing IF statement to check the value of $e, can I combine that with this?

This is what I use already:
Code:

if ($e == '' OR !$e)
{
    $e = '404';
}

Can I make the IF statement like this...
Code:

if ($e == '' OR !$e OR !inarray($e,$error))
Assuming I've created the array before the IF statement (of course), will that work?

the if staement should be like

PHP Code:

if (!(in_array($e,$error)) || $e ==''

or for better

PHP Code:

if (!in_array($e,$error) || !isset($e)) 


JJR512 10-18-2005 02:08 PM

I have tried that now, and got the error message...
Quote:

Fatal error: Call to undefined function: inarray() in /home/jjr512/public_html/testbbs/httperror.php on line 51
What's up?

Ranma2k 10-18-2005 02:09 PM

Quote:

Originally Posted by JJR512
I have tried that now, and got the error message...

What's up?

sorry it's

in_array

my mistake

JJR512 10-18-2005 03:17 PM

Thanks! :)


All times are GMT. The time now is 07:10 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01187 seconds
  • Memory Usage 1,739KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (4)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete