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

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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