PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Dec 05, 2019 7:27 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Mon Jul 09, 2012 11:46 am 
Offline
Forum Newbie

Joined: Mon Jul 09, 2012 8:54 am
Posts: 7
solved thanks. Guys.


Last edited by karolismf on Sun Jul 29, 2012 8:16 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 12:19 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
Lots of code there. For me the two big issues are:

1. Lack of separation between the code that generated the output and the code that contains the business/domain logic

2. Not naming you objects as specific nouns. You have a class called "Check" which is about the most generic term possible. The name does describe what the object is. Likewise you use the work "accounts" which is also general. If they are user accounts then call the table and the object "users". Your naming leads to the wrong separations.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 12:29 pm 
Offline
Forum Newbie

Joined: Mon Jul 09, 2012 8:54 am
Posts: 7
Hmm, for first and secound issue i understood about more than half of it. Sorry, i don't have such great english. so if i understand it right you mean that in forgotPassword i have all code about forgotPassword and there is somecode in Check? it's unnecessary using from two classes code breaking? Hmm, first of all lets fix some things in my code and post fixed. Then we will move forward. here some fixes:
....

okey now look throught it again and tell me if i solved even one of your issue? :) And thanks for help.


Last edited by karolismf on Sun Jul 29, 2012 8:17 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 3:36 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
This kind of discussion would be easier in your native language -- sorry about that.

My main comment is that classes are usually named using nouns and methods named using verbs. That makes class names describe what the object is and the data it contains. Using verbs makes methods describe what they do. It is even better if method names follow the "Tell Don't Ask" style if possible. Good naming comes from good decomposition of the the problem and the domain.


Microsoft
Class Naming:
Method Naming:

Wikipedia
http://en.wikipedia.org/wiki/Naming_con ... ramming%29

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 3:53 pm 
Offline
Forum Newbie

Joined: Mon Jul 09, 2012 8:54 am
Posts: 7
"My main comment is that classes are usually named using nouns and methods named using verbs" Is it something to do with the coding or the code will have holes if i don't fix this problem, or my web security is on risk if i don't change them? :) if no, then please give me your own example how should it look like. I would compere to mine and i think it would be easier for both of us understand each other. And if yes, then i want an example for the best coded example in this situation. :) Thanks. "This kind of discussion would be easier in your native language -- sorry about that. " Np. I am not very good in english far more worse than you, sorry for bad english. :) (readed again, so you suggest to write the class names something diffrent from it's functions? like class forgotPassword/ so we name it arWt4dfWF)?


Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 5:37 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 6:30 pm 
Offline
Forum Newbie

Joined: Mon Jul 09, 2012 8:54 am
Posts: 7
Hmm, well you are half right about forgotpassword.php, my site uses only index and it calls includes if there is string in url like mysite.com/?a=forgot, then it calls a file./// I created html pages for solution if success sending forgotPassword or failed. And ofcourse your new password was send html page. In my website there is only one class that uses the forgotPassword system it's in here. And ofcourse we must count the mailer class, which gets an information of forgotPassword that is filed by user and sends an email. In other words my forgotPassword at website uses two classes one is Class forgotPassword, secound Class Mailer. (My forgot password sends the $_POST['email'] to forgotPassword class - the class first of all filters the text then checks if the users filed information is valid and it isn't empty if that data is valid it checks database if the user filed information matches in database if yes, then in forgotPassword we call secound class name Mailer and call it's public function sendForgot using the information stored from user. Then the function do it's job and mail was send to your email. Then in email i got an mail from my website with a link for forgotPass reset, i use it and it opens my website which uses the include controler with link mysite.com/?something=...&... when pressed link it opens new file with stored information of "mysite.com/?something=...&..." it checks if this thing was really done.(he checks throught database) then he calls in forgotPassword again Class Mailer and this time it uses diffrent Mailer function with information stored from the link. The secound mail gives you new mail with new password.) Like again i didn't understand something in your post it was the last line. :) If you have skype it would be great to write throught it becouse this is long conversation...


Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 10:31 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Tue Jul 10, 2012 5:01 am 
Offline
Forum Newbie

Joined: Mon Jul 09, 2012 8:54 am
Posts: 7
k, now i get it. But why? is it more secure or better for the website and it's function quality?


Top
 Profile  
 
PostPosted: Tue Jul 10, 2012 9:46 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Wed Jul 11, 2012 6:10 am 
Offline
Forum Contributor

Joined: Sat Jan 03, 2009 4:27 pm
Posts: 148
A couple of things:

1) Use curly brackets even when they're not necessary; it's more future proof.

Syntax: [ Download ] [ Hide ]
// Bad
  public function process()
  {
    if( $this->valid_token() && $this->valid_data() )
           $this->register();

    return count( $this->errors )? 0 : 1;
  }

// Good
  public function process()
  {
    if( $this->valid_token() && $this->valid_data() )
    {
           $this->register();
    }
    return count( $this->errors )? 0 : 1;
  }


2. Switch to the MySQLi extension or PDO to make use of prepared statements. This can speed up your application and will prevent SQL injections.


Top
 Profile  
 
PostPosted: Sat Jul 14, 2012 5:57 am 
Offline
Forum Newbie

Joined: Mon Jul 09, 2012 8:54 am
Posts: 7
Hmm, i will try. to change everything as you said. :) Anything else. And Christopher i will try to make more classes as you suggested. :)


Top
 Profile  
 
PostPosted: Sat Jul 14, 2012 8:19 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group