Jump to content

Can someone translate this PHP code for me?!


oliverj777

Recommended Posts

Please translate:

 

$req_user = trim($_GET['user']);
if(!$req_user || strlen($req_user) == 0 ||
   !eregi("^([0-9a-z])+$", $req_user) ||
   !$database->usernameTaken($req_user)){
   die("Username not registered");

$req_user_info = $database->getUserInfo($req_user);

 

Thanks

its just checking whether the $_GET['user'] function

It's not a function

is

1) Set

nope - that would be isset($_GET['user'])

 

2) have some value (not empty)

nope - that would be !empty($_GET['user'])

 

What it actually does is strips all whitespace (spaces, tabs, linebreaks) from the beginning and the end of $_GET['user'] and then checks if there's anything left.

 

3) Alphanumeric

correct - although using a deprecated method. preg_match or filter should be used

 

4) match with database username

probably

 

If any of the above is false, die ...

 

if not call $database->getUserInfo($req_user); (probably get user info from database)

 

its just checking whether the $_GET['user'] function

It's not a function

that was a honest typing mistake ... corrected in 2 mins, but u got me within that .. ;)

 

is

1) Set

nope - that would be isset($_GET['user'])

What do you think (!$_GET['user']) can be used for?

 

2) have some value (not empty)

nope - that would be !empty($_GET['user'])

 

What it actually does is strips all whitespace (spaces, tabs, linebreaks) from the beginning and the end of $_GET['user'] and then checks if there's anything left.

 

Did I said anything much different? (except strips function, which I presumes he knows)

is

1) Set

nope - that would be isset($_GET['user'])

What do you think (!$_GET['user']) can be used for?

 

First off being set (as you first proposed) and having a value are two entirely different things. isset() is - obviously - the function to test if a variable is set. If you want to check if the string variable has a value you would use empty().

 

(!$_GET['user']) checks to see if the value resolves to the boolean false. That is a terrible method of testing if a variable is set and/or has a value. If the user entered the value '0' that would return false even though the variable is set and has a non-empty value.

Archived

This topic is now archived and is closed to further replies.

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