rewriting the class or not?

Results 1 to 12 of 12
  1. #1
    [Professional PHP Coder] Lioness is offline
    MemberRank
    Nov 2011 Join Date
    i see youLocation
    216Posts

    rewriting the class or not?

    Hello,

    I'm currently reviewing the code and I said yours for safety why not rewrite the history class to have something that might be useful optimized

    So I began writing course, the start and I stop because I know if you want to do or not ...


    Are you interested?

    an example pdo
    pdo2.php
    PHP Code:
    /**
     * Class implementing the singleton for PDO
     */
    class PDO2 extends PDO {

        private static 
    $_instance;

        
    /* Constructor : heritage public */
        
    public function __construct(){
        }

        
    // End of PDO2::__construct() */

        /* Singleton */
        
    public static function getInstance(){
            if (!isset(
    self::$_instance)){
                try{
                    
    self::$_instance = new PDO(SQL_DSNSQL_USERNAMESQL_PASSWORD);
                }
                catch (
    PDOException $e){
                    echo 
    $e;
                }
            }
            return 
    self::$_instance;
        }
        
    // End of PDO2::getInstance() */


    and a simple example of the email update
    Member.class.php
    PHP Code:
    class Member {

        
    // Function login ( register.php )
        
    public function login($username$password){
            
    $pdo PDO2::getInstance();
            
    $requete $pdo->prepare('SELECT id, username, email, tribe, access, gold, gender, birthday, location, desc1, desc2, plus, b1, b2, b3, b4, sit1, sit2, 
                                         alliance, act, timestamp, ap, apall, dp, dpall, protect, quest, gpack, cp, lastupdate, RR, Rc, ok, clp, oldrank
                                        FROM '
    .TB_PREFIX.'users 
                                        WHERE username = :user and password = :password and access != '
    .BANNED);
            
    $requete->bindValue(':user'$usernamePDO::PARAM_STR);
            
    $requete->bindValue(':password'md5($password), PDO::PARAM_STR);
            
    $requete->execute();
            if(
    $requete->rowCount() == 1){
                
    /*
                //    Create $_SESSION 
                //    id, username, email, tribe, access, gold, gender, birthday, location, desc1, desc2, plus, b1, b2, b3, b4, sit1, sit2, alliance, act, 
                //    timestamp, ap, apall, dp, dpall, protect, quest, gpack, cp, lastupdate, RR, Rc, ok, clp, oldrank
                //    The session will serve as a cache server and a faith is connected does not touch a ca disappear unless the session 
                //    (session time exceeded or browser closed)
                */
                
    $result $requete->fetch(PDO::FETCH_OBJ); // Return result in objet
                
    $_SESSION['id'] = $result->id;
                
    $_SESSION['email'] = $result->email;
                return 
    true;
            }
            else{
                return 
    false;
            }
        }

        public function 
    update_email_adress($email){
            
    $pdo PDO2::getInstance();
            
    $requete $pdo->prepare('UPDATE '.TB_PREFIX.'users SET email = :email WHERE id = :id_user');
            
    $requete->bindValue(':id_user'$_SESSION['uid']);
            
    $requete->bindValue(':email'$email);
            
    $_SESSION['email'] = $email;    // Update session cache
            
    return $requete->execute();
        }

    }
    $member = new Member
    and finally to pass the parameter we have a simple
    PHP Code:
    echo ($member::login('test''123456789') == true) ? 'i\'m logged and my id is '.$_SESSION['id'] :  'i\'m not logged' ;
    $member->update_email_adress('email@email2.fr'); //after vérify update email 


    Well I still said that I did not it simple of course a lot of audit are to do ect and never go through but the username id

    and also if it's still set an STR or INT


    I refer the member to function in the file you edited and Member.class.php as a measure for and you see one can conduct

    with login -> Session -> Cache -> update -> update cache

    the logical flow of a well designed aplications



    (I said it's not perfect but its far from the present will be probably better)
    Last edited by Lioness; 28-11-11 at 08:45 AM.


  2. #2
    Trolololol Dzoki is offline
    MemberRank
    Mar 2011 Join Date
    htdocsLocation
    1,614Posts

    Re: rewriting the class or not?

    Use english comments.

  3. #3
    [Professional PHP Coder] Lioness is offline
    MemberRank
    Nov 2011 Join Date
    i see youLocation
    216Posts

    Re: rewriting the class or not?

    why is it written in language? lol

    you want me to rewrite the variable?

    I am preparing a small package, so you test this script
    and you give me your opinion

    Warning: my script is beautiful lol

  4. #4
    Working in iZariam v0.1.0 ZZJHONS is offline
    MemberRank
    Feb 2011 Join Date
    LocalhostLocation
    1,117Posts

    Re: rewriting the class or not?

    The comment of php in english language:

    PHP Code:
    // This in english
    # This in english
    /* This in english */ 

  5. #5
    Enthusiast deckstatus is offline
    MemberRank
    Nov 2011 Join Date
    35Posts

    Re: rewriting the class or not?

    Yeah Lion, English is the common language in here.

    Some speak spanish (JHON+Me), some English (Dzoki), some French (you), and some don't even speak a language (tuyuale) <. lol

    But everybody knows a bit of English.

    So it would be useful for everyone to have comments in English :D

  6. #6
    Trolololol Dzoki is offline
    MemberRank
    Mar 2011 Join Date
    htdocsLocation
    1,614Posts

    Re: rewriting the class or not?

    We wont implement any code without english comments cuz script is full enough of spanish / dutch and etc..

  7. #7
    Valued Member SlimShady95 is offline
    MemberRank
    Mar 2011 Join Date
    134Posts

    Re: rewriting the class or not?

    German FTW!

    greets,
    Slim

  8. #8
    [Professional PHP Coder] Lioness is offline
    MemberRank
    Nov 2011 Join Date
    i see youLocation
    216Posts

    Re: rewriting the class or not?

    this was an example of code that's all ...

    pdo2.php not to hit <- this small file to instantiate this and all pdo and pdo feasible with the simple class with a singleton

    now I rewrote the entire code for:
    register 100% ok and secure
    login 100% ok and secure
    activate 100% ok and secure
    logout 100% ok and secure
    profile ~ 50% ok (short Rewrtie tpl)

    Now all comment is english ( one line change ... )
    Last edited by Lioness; 28-11-11 at 08:46 AM.

  9. #9
    Working in iZariam v0.1.0 ZZJHONS is offline
    MemberRank
    Feb 2011 Join Date
    LocalhostLocation
    1,117Posts

    Re: rewriting the class or not?

    Please, upload to your github repo to see it

  10. #10
    [Professional PHP Coder] Lioness is offline
    MemberRank
    Nov 2011 Join Date
    i see youLocation
    216Posts

    Re: rewriting the class or not?

    this version is not compatible with the current version I completely remade the code in OOP and pdo

    but for now I not git but the link will be: https://github.com/GameEngine/Travianx-2

    Once I did with dorf1.php I would add the git so that everyone can test and returned me the error

    (It's not very hard to do a lot of copy paste and Rehabilitation pdo code above, and many optimization)

  11. #11
    Working in iZariam v0.1.0 ZZJHONS is offline
    MemberRank
    Feb 2011 Join Date
    LocalhostLocation
    1,117Posts

    Re: rewriting the class or not?

    Ok, thx, I will wait

  12. #12
    [Professional PHP Coder] Lioness is offline
    MemberRank
    Nov 2011 Join Date
    i see youLocation
    216Posts

    Re: rewriting the class or not?

    Hello,

    I noticed that Strange to the generation of the capital of the player at registration was slow

    So I thought I had to zap something

    and suddenly I look at the function "generateBase ($ sector)"

    and but what is this thing seriously?

    What is to loop?
    Why not just selected, and what can and choose one of the only possibility?

    Why limit the location FieldType 3 while that should not be just the 0 (Oasis)?
    Answer: Some of the maps are specific to certain production (clay, wood, crop, iron) and are not playable in the first map or at least that braid can give some advantage to other players.
    conclusion: remove FieldType 0 (oasis) and 6 (Max Cropland)


    and at the same time its also means that the investment has incripnion (+/+) (+/-) (-/+) (-/-) not work since you not even take into account $ sector and defined the passage of the function (you just randomly reset after)

    more you exclude all online ... 0 X and Y may I ask why?

    In short, the function and heavy and expensive for php and for bdd

    I better than you, in addition the desired results, just by causing one query ...

    the square root, the exponential ...
    there is no use of you believe it?
    Last edited by Lioness; 29-11-11 at 10:17 AM.



Advertisement