Having trouble wrapping this up into a viable statement
I want to check on a users status before allowing a script to be run.
$myzone can only be 1 variable, but it can be here, there or where.
if ($myzone !== ("here") or ("there") or ("where")) { die: }
This does not work however, it will kill the script regardless if one
of the statments is actually true.
However, this WILL work if only one operator is checked:
if ($myzone !== "here") { die: }
If $myzone is "here" the script is allowed to run. If it's anything
else, it dies, as it is supposed to. However, I want to check if
$myzone is several options. That is my delima. 3 1324
Uleric <Ul****@gmail.comwrote:
Having trouble wrapping this up into a viable statement
I want to check on a users status before allowing a script to be run.
$myzone can only be 1 variable, but it can be here, there or where.
if ($myzone !== ("here") or ("there") or ("where")) { die: }
This does not work however, it will kill the script regardless if one
of the statments is actually true.
However, this WILL work if only one operator is checked:
if ($myzone !== "here") { die: }
If $myzone is "here" the script is allowed to run. If it's anything
else, it dies, as it is supposed to. However, I want to check if
$myzone is several options. That is my delima.
Unfortunately, this is not how conditionals work.
You first statement breaks down like:
$myzone !== ("here") -can be true or false
or
("there") -a string, which cast to a boolean will always be true, no
further evaluation will be done, conditions are met, code die()s .
You could use a lengthy version:
if (
$myzone !== "here" ||
$myzone == "there" ||
$myzone == "where"){ die: }
Then again, I don't understand you logic. The script is only allowed to
run when it's 'here', so why exactly fo you want to check the rest? If
$myzone == 'here', it cannot be anything else, unless your trying
something more complex then the example offcourse, in which case I'd be
interested in what exactly.
--
Rik Wasmus
On Wed, 31 Jan 2007 17:35:25 -0800, Rik <lu************@hotmail.comwrote:
Uleric <Ul****@gmail.comwrote:
>Having trouble wrapping this up into a viable statement
I want to check on a users status before allowing a script to be run. $myzone can only be 1 variable, but it can be here, there or where.
if ($myzone !== ("here") or ("there") or ("where")) { die: }
This does not work however, it will kill the script regardless if one of the statments is actually true.
However, this WILL work if only one operator is checked:
if ($myzone !== "here") { die: }
If $myzone is "here" the script is allowed to run. If it's anything else, it dies, as it is supposed to. However, I want to check if $myzone is several options. That is my delima.
Unfortunately, this is not how conditionals work.
You first statement breaks down like:
$myzone !== ("here") -can be true or false
or
("there") -a string, which cast to a boolean will always be true, no
further evaluation will be done, conditions are met, code die()s .
You could use a lengthy version:
if (
$myzone !== "here" ||
$myzone == "there" ||
$myzone == "where"){ die: }
Then again, I don't understand you logic. The script is only allowed to
run when it's 'here', so why exactly fo you want to check the rest? If
$myzone == 'here', it cannot be anything else, unless your trying
something more complex then the example offcourse, in which case I'd be
interested in what exactly.
There is an error in both snippets of code "die:" is used, you need end
the statement with a semi-colon ";"
if ($myzone == 'there' || $myzone == 'where') die;
Concerning the logic, $myzone !== 'here' is not even needed, becauseif
$myzone equals 'there' or 'where' it can't be 'here'. I agree, though, it
seems like the OP is actually doing something more complex. Also, only the
first boolean comparison checks against type, which seems unnecessary here.
--
Curtis, http://dyersweb.com
Uleric wrote:
if ($myzone !== ("here") or ("there") or ("where")) { die: }
Try:
if ($myzone!='here' && $myzone!='there' && $myzone!='where') die;
Or, using De Morgan's Laws (boolean algebra law concerning the
relationship between NOT, AND and OR) you could alternatively use:
if (!( $myzone=='here' || $myzone=='there' || $myzone=='where' )) die;
Or, to make your code read a bit more sanely (but might actually run
slower!):
$allowed_states = array('here', 'there', 'where');
if (!in_array($myzone, $allowed_states)) die;
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Powell |
last post by:
Has anyone here ever done a case where you have a select multiple form
element and you have to do both server-side and client-side validation?
I am honestly not sure how to do it in Javascript (I...
|
by: Darren Dale |
last post by:
Hello,
def test(data):
i = ? This is the line I have trouble with
if i==1: return data
else: return data
a,b,c,d = test()
|
by: Scotter |
last post by:
Okay I think my title line was worded misleadingly. So here goes again.
I've got quite 20 identical MDB files running on an IIS5 server.
From time to time I need to go into various tables and add...
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.09.2004
Hello,
I need to implement a library containing a hierarchy of classes
together with some binary operations on objects. To fix attention,
let me assume that it is a...
|
by: Niels Dekker - no reply address |
last post by:
The book "C++ Coding Standards" by Herb Sutter and Andrei Alexandrescu
warns against potential memory leaks when having multiple calls to
operator new within a single statement. (Item 13, page...
| |
by: lduperval |
last post by:
Hi,
I`m trying to do date calculations in three types of time zones: local,
GMT and specified. The issue I am facing is that I need to be able to
specify a date in the proper time zone, and I`m...
|
by: Matthew Louden |
last post by:
I want to know why C# doesnt support multiple inheritance? But why we can
inherit multiple interfaces instead? I know this is the rule, but I dont
understand why. Can anyone give me some concrete...
|
by: Mark |
last post by:
why doesn't .NET support multiple inheritance?
I think it's so silly!
Cheers,
Mark
|
by: Olie |
last post by:
This post is realy to get some opinions on the best way of getting fast
comunication between multiple applications. I have scowered the web for
imformation on this subject and have just found...
|
by: Zytan |
last post by:
I want multiple instances of the same .exe to run and share the same
data. I know they all can access the same file at the same time, no
problem, but I'd like to have this data in RAM, which they...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |