Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-18-2005, 12:49 PM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.?
Reply With Quote
  #2  
Old 10-18-2005, 01:17 PM
Ranma2k Ranma2k is offline
 
Join Date: Dec 2001
Location: Earth
Posts: 586
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"
Reply With Quote
  #3  
Old 10-18-2005, 01:40 PM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #4  
Old 10-18-2005, 01:54 PM
Ranma2k Ranma2k is offline
 
Join Date: Dec 2001
Location: Earth
Posts: 586
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)) 
Reply With Quote
  #5  
Old 10-18-2005, 02:08 PM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #6  
Old 10-18-2005, 02:09 PM
Ranma2k Ranma2k is offline
 
Join Date: Dec 2001
Location: Earth
Posts: 586
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 10-18-2005, 03:17 PM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:56 PM.


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.05363 seconds
  • Memory Usage 2,235KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete