RE: comparable Perl "unless" in PHP?
| From: | Nold, Mark | Date: | Fri, 03 Nov 2000 00:50:51 +0000 |
| Subject: | RE: comparable Perl "unless" in PHP? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-23494@lists.php.net to get a copy of this message | ||
----------------------------------------------------------------------------
-----------------
Disclaimer: The information contained in this email is intended only for the
use of the person(s) to whom it is addressed and may be confidential or
contain legally privileged information. If you are not the intended
recipient you are hereby notified that any perusal, use, distribution,
copying or disclosure is strictly prohibited. If you have received this
email in error please immediately advise us by return email at
postmaster@normandy.com.au and delete the email document without making a
copy.
----------------------------------------------------------------------------
-----------------
The only thing i can think of is the ! operator (or maybe its an
expression...)
$login = "foo";
if(!($login == "foo" || $login == "bar" )){
echo "Not allowed";
exit();
}
echo "Allowed";
You can do lots of things like
$login != "foo" // login doesnt equal foo (dont have an eq and ne for
strings though.
!$login // $login is false, not set or null or zero
!($login > 10) //$login is not greater than 10, doesnt mean its less than
ten though
This should do the trick. Of course the tests could easily be regular
expressions (but in your example prabaly not needed.
Personally id stick all the allowed users in an array or a DB table and
check against that.
eg:
$users["foo"] = true;
$users["bar"] = true;
$users["me"] = true;
$users["you"] = true;
if($users[$login] != true){
echo "Not allowed";
exit();
}
Bit more extensible...
Mark Nold
markn@enspace.com <mailto:markn@enspace.com>
Senior Consultant
Change is inevitable, except from vending machines.
-----Original Message-----
From: Brian Tully [mailto:btully@gstockco.com]
Sent: Friday, November 03, 2000 2:54 AM
To: PHP
Subject: comparable Perl "unless" in PHP?
hi there -
as a recent migrant form Perl to PHP I've been going crazy trying to figure
out how to use Perl's "unless" statement in PHP - or at least a workaround.
For example, with Perl I was able to restrict access to certain pages using
something like this:
$login = $ENV{REMOTE_USER};
unless ($login =~ /^foo$|^bar$/) {
print $query->redirect("../no_access.html");
}
or - If I had a form with many fields I could do something to the effect of
unless ($field1 && $field2 && $field3 && $field4 && $field5) {
print "you did not complete all fields.\n";
}
can someone please enlighten me as to how I could achieve this same
functionality within PHP? I've searched through several books to no avail -
the only thing I could find remotely similar was the "isset" function but
that only seems to work with a single value and not groups.
Any help would be greatly appreciated. I'd hate to have to go back to Perl
so soon in the game ;)
Brian