To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-05-2003, 07:35 PM   #1
agoe
Junior Member
 
Join Date: Jun 2003
Location: Norway
Posts: 28
User registration

Hi, as the subject states, i've written a user registration-script.

Please comment on any flaws, efficency issues or other things.

you type your nickname and email-adresse, and then a generated password is sent to you. hope the code is readable.

all the html except from the form elements is removed, so don't bother thinking about how it all looks.

also, say if you like or dislike the code

code:
http://anders.ownage.no/code/register.phps
agoe is offline   Reply With Quote
Old 01-19-2004, 09:50 PM   #2
Reformed
Senior Member
 
Join Date: Jul 2003
Location: Sunny AZ
Posts: 116
The first thing I noticed is that you don't have one comment in the entire script. Very important to comment. Otherwise it looks good.
__________________
I'd rather have bottle in front of me
than a frontal lobotomy.
Reformed is offline   Reply With Quote
Old 01-20-2004, 04:20 PM   #3
BuzzLY
2($infinity) && $beyond
 
BuzzLY's Avatar
 
Join Date: Nov 2002
Location: Star Command
Posts: 2,535
Is there some reason why your server doesn't color-code the source code? most phps files are color-coded, and therefore easier to read.
__________________
New to the board? Check out the guidelines
| Color Picker | Blogification |
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
With all its sham, drudgery, and broken dreams, it's still a beautiful world.
BuzzLY is offline   Reply With Quote
Old 01-20-2004, 04:23 PM   #4
planetsim
code | beer > sleep
 
Join Date: Sep 2002
Location: aus
Posts: 4,826
A couple of issues.

register_final($username, $email)

The arguments are from Posted Forms. Now $_POST is a superglobal so having those two arguments are just a waste.

PHP Code:
echo "name: <input type=\"Text\" maxlength=\"20\" name=\"dusername\">";
Can be this

PHP Code:
echo 'name: <input type="Text" maxlength="20" name="dusername">';
Just looks neater to me

PHP Code:
function logoff() {
    
$_SESSION=array();
    
session_destroy();
}
Could be done easier

PHP Code:
function logoff() {
    unset
$_SESSION['session_name'])
}
session_destroy is better used when you use session_register(); and i dont see it in the script and if you are you shouldnt be using $_SESSION.

Also SQL Injections. It doesnt look like you are trying to prevent those at all, which is a huge security risk.

Best link i know for you on how to prevent for them http://www.sitepoint.com/article/794
__________________
Dont be lazy Search
And use the Manual
Webmobo - Open Source News Script | Portfolio / Blog | Against TCPA
planetsim is offline   Reply With Quote
Old 01-20-2004, 09:22 PM   #5
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,122
Quote:
Originally posted by planetsim
PHP Code:
echo "name: <input type=\"Text\" maxlength=\"20\" name=\"dusername\">";
Can be this

PHP Code:
echo 'name: <input type="Text" maxlength="20" name="dusername">';
Just looks neater to me
You could also go further than that, noting that strings can run across more than one line, and there's also the heredoc syntax:
PHP Code:
echo 'name: <input type="Text" maxlength="20" name="dusername">
e-mail: <input type="text" maxlength="50" name="email">
confirm e-mail: <input maxlength="50" type="text" name="cemail">
<input type="submit" name="dsubm" value="next">'
;

echo <<< EOF
name: <input type="Text" maxlength="20" name="dusername">
e-mail: <input type="text" maxlength="50" name="email">
confirm e-mail: <input maxlength="50" type="text" name="cemail">
<input type="submit" name="dsubm" value="next">
EOF;
or even go the whole hog and escape out of PHP completely for the duration.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 01-27-2004, 12:24 PM   #6
lastcraft
Junior Member
 
Join Date: Jan 2004
Location: London
Posts: 3
Hi...

Quote:
The first thing I noticed is that you don't have one comment in the entire script. Very important to comment. Otherwise it looks good.
This comment thing gets out of hand I feel. the main objective is clear maintainable code. Comments that just repeat the function names just add clutter. Here we have well chosen names, making the more obvious comments superfluous.

The really useful comments are things that humans would say. Such things as "To do..." or "This bit really sucks..." or "This can be rather slow when...".

PHPDoc comments are different. They are there so that you don't even have to look at the code. Some repetition is inevitable in this case, but as the point of this forum is code, there is little point in putting PHPDoc blocks in.

yours, Marcus
lastcraft is offline   Reply With Quote
Old 01-27-2004, 12:29 PM   #7
lastcraft
Junior Member
 
Join Date: Jan 2004
Location: London
Posts: 3
Hi...

Quote:
The arguments are from Posted Forms. Now $_POST is a superglobal so having those two arguments are just a waste.
Ouch.

I would go the other way and actually pass all the POST data in from the top level function. Makes everything much easier to test and you can then reuse the code in other places where you happen to use GET. By using any global data anywhere in a function, you are reducing flexibility.

Super purist me .

yours, Marcus
lastcraft is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:50 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.