Jump to content
MakeWebGames

john.

Members
  • Posts

    63
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by john.

  1. Did you play World of Warcraft ?
  2. Seems like you got it fairly somewhat right. 1. Why would you save the sql as a .txt? Take the contents and save as db.sql. 2. You should aim to have consistency when naming your tables and columns. So either you rename all tables to be in plural or keep them all singular. Here is two good questions about the subject: http://stackoverflow.com/questions/338156/table-naming-dilemma-singular-vs-plural-names http://stackoverflow.com/questions/808992/singular-or-plural-database-table-names (Personally I use plural, only lowercases and uses underscores, when dealing with mapping tables I take tables in alphabetical order in singular, like Laravel framework does it). So please pick a style and adapt afterwards. Consistency is the key. 3. Consider using UTF8 instead of latin1. Read: http://www.utf8everywhere.org/ 4. Restructure your project structure to be more logical and readable. For example put all your assets (CSS files, JavaScript files) in a assets/ folder. The db.sql in a sql/db folder. Files I presume are included (functions.php) in a includes/ folder. When you have all files just in the root it gets messy and some files should not be direct script accessed like functions.php and header.php. 5. Please consider to separate the PHP and HTML. It's bad practice having them mixed up, harder to manage, more complex to work on same project as a team, etc. This can be pretty much work to do, but a good way to start is something like this: 5a. Make sure all "business" PHP is in the top, only the things you output echo, looping out array data, etc should be within the HTML. So make a clear separation all PHP that does something in the top and the things to be outputted in the bottom the HTML and echo stuff.. 5b. Now take the PHP code in the top and put in new files and have them included in the top of the files.   6. Drop the use of mysql_ extension and use PDO or MySQLi instead. I have written a tutorial that exists on these forums that introduces you to PDO, have a look at it and get started! Mysql_ API is depreceated and is to be removed in future PHP version. 7. Stop using md5 for password hashing. Its bad and insecure, definitely insecure without salting. You should use bcrypt. I have written a tutorial about how to make a registration page on this forums that uses bcrypt, the in-built password_hash methods that comes with PHP 5.5 and show also how to use these on systems using < 5.5. 8. Use die; after your redirects on header(); because, in other case, your script will be executed till the end, what can cause some unexpected behavior.
  3. What license does the project have? Would you mind putting the project on a repository site using GIT, like Github or Bitbucket? If so, I could give you a code review and perhaps a pull request or two.
  4. john.

    Layout PSD 15$

    Go ahead with MCC v3 instead. But yeah, nice initiative!
  5. Nice, just need another design though.
  6. You could try a PERMAMENT REDIRECT in the file. Or just use a proper IDE and change the links.
  7. Nope. Have you ever failed to follow the rules in a Have you ever game?
  8. No, I have not. Have you ever been using floats and positions attributes in CSS without actually know how the works?
  9. Looks good [MENTION=50433]ColdBlooded[/MENTION]!
  10. Shouldn't Dabomstew be considered gone as well?   Last Activity 05-01-2013 11:13 PM
  11. Here is my suggestions: Header Remove the gun. Set opacity on the header background, like 80-90% in between. Like mentioned above, place the navigation, like the picture in the post above, and get rid of the effects it currently has, it just bloats it down. The login bar need proper proportions, left align the labels and the button, place it on the right starting from where the text input fields end, or left align it as well. Place the copyright text in the right bottom corner. Remove the (not sure what it's called, but the Photoshop effect that adds that the button looks shiny in the bottom and top). Lower or remove the shadow/whatever it is around the font on the button. Remove the : from the labels. But the most important one: Change the font, try Open Sans or something. By the way, the art is copyrighted by Riot Games, are you sure you're allowed to use it?
  12. One of the most annoying thing I find is that db.sql file. It sucks. It's hard to interpret, because it contains **** loads of data. Using a tool like MySQL Workbench or phpMyAdmin works pretty good, but requires you to dump and overwrite your sql files. Here is an alternative simple but better route: Create a db/ folder. (Yep, your database structure deserves one directory itself!) Make one file for each table. Put some effort and use DROP TABLE IF EXISTS; and such to easily help your drop and create tables when importing files. Now you can easily import the tables you only need, if you change the users.sql table, you would import that table. Only want to alter the file and not drop it? Make a users_2.sql, users_altered.sql etc. Sure, this works fine when you only have a small amount of tables, but what if you come at a point where you have 30-40 tables. It would suck importing these one by one. Well, you shouldn't. Merge the files! By applying the naming convention above, (User_alter) you would make sure that the files would be merged in a correct order. On Windows you would do:   copy *.sql db.sql   AND BAM! You have one kick-ass db.sql to distribute. So to get rid of the headache looking for the db.sql, you may want to put all your table files in a dev/ sub folder within db/. This was a simple route you can take, it's definitely better than the db.sql way. The best way to accomplish this is using a migration tool. A tool that does all of this for you, allows you to fancy rollbacks and seeding data. One example is using Phinx. http://phinx.org/ A PHP Database Migration you can use.   What do you think? Is the db.sql file enough for you? Does it make sense structuring your database files in a way like this? Have you used a migration tool? Would you try one? If not, why not?
  13. It looks good, however I think that you should address the separation between PHP and HTML, it is messy, and would be hard for a front end developer to easily modify the HTML and CSS only. At the very least I would say that PHP business logic would be put in the top. and then outputting data, mixed in in the HTML.
  14. You have a point. I have my doubts, but hopefully if it gets here I am wrong and it will do what you suggests it will.
  15. My bet is that it would be inactive. So, I would disagree for now. If Panther becomes more active, discussed etc, it's definitely considerable. That's just my 2 cents.
  16. I would still need a factory for instantiating rules though =)
  17. What browsers supports this? :) Looks good.
  18. Valid points. I did write a version before that had more a object-oriented approach, where you defined Rule classes that had a validate() method that could be instantiated through a factory injected in the Validator, but the problem is that I needed it to be lightweight. I want a single-file drop in my current code setup to just quickly validate. I know per basis that many classes doesn't mean it's not lightweight but in all the goal is a one-filer. My other was to only have the Validator using callbacks instead of defined method, an extra dependency to inject when creating an instance, but would let the Validator have less responsibility. The problem with unique validation was that I did not want any specific database dependency on the Validator, instead you would write your own custom rule (a callback) that uses dependencies to perform these kind of validations. A callback like that would look like this:   $validator->registerCallback('unique', function ($value, $params) use ($db) { //params[0] should contain name of table //params[1] would contain the column in the table... // $stmt = $db.... return (bool) $stmt->fetch(); });   But yeah, probably need a rewrite or two before I get this Validator the way I want, I could post the Rule one too if you like. The only problem right now is the additional parameters, like "Field %s has to be %d long", (%d) not sure how I would store the other values (parameter values) in the error statement...
  19. The moment you realize that this domain is so good that you don't want to tip about it, you know you found a good name.
  20. Comments will come, just prototyping at the moment, and stripped all non-appropriate comments out from the source :3 But on a more serious note, won't be doing so much more with this, it taking to long and I am better of using some library available on Packagist instead.
  21. john.

    PDO Login Error

    1. Remove stripslashes( strip_tags( , they are redundant when using prepared statements. 2. Use a better hashing method, like bcrypt. 3. No need to use bindValue, these methods are mostly used when doing stored procedures. $stmt-execute(array($this->username, $this->password)); is fine. 4. Move the creating of PDO instance outside, it does not belong there (SRP) and should rather be injected throughout the constructor so it can be tested. 5. Remove the try {} catch block, you're not actually doing anything useful with what you catch, should rather let some global exception handler outside the class take care of it. 6. Optimize your query by removing * and just set id, you're actually not fetching anything or returning the PDOStatement object for that matters.   <?php class Login { protected $db; protected $username; protected $password; public function __construct(PDO $db) { $this->db = $db; } public function setCredentials(array $credentials) { $this->username = $credentials['username']; $this->password = $credentials['password']; } public function login() { $success = false; $stmt = $this->db->prepare("SELECT `id` FROM `users` WHERE `username? = ? AND `password` = ?"); $stmt->execute(array($this->username, $this->password)); if ($stmt->fetch()) { $success = true; } return $success; } }   I rework the code a bit, still not a reusable it can be. What if you want to use email as credential in your next project? Going in the class and changing is not very reusable, neither object-oriented approach :-) What if you want to use a NoSQL db? etc.
  22. Built a Validator class and would like some feedback and ideas on how to improve the current code; Too cool for comments :cool: <?php class Validator { protected $messages; protected $callbacks; protected $errors; public function __construct(array $messages = array()) { $this->messages = array( 'required' => '%s required', 'email' => '%s invalid', ); if (!empty($messages)) { $this->messages = array_merge($this->messages, $messages); } } public function registerCallback($rule, $callback) { if (!is_callable($callback, true)) { throw new InvalidArgumentException( sprintf('Invalid callback: %s.', print_r($callback, true))); } $this->callbacks[$rule] = $callback; } public function validate(array $fields, array $data) { foreach ($fields as $field) { $name = $field['name']; $rules = $this->parseRules($field['rules']); $value = $this->getValue($name, $data); if (in_array('required', $rules) === false && empty($value)) { continue; } foreach ($rules as $rule => $params) { $result = $this->execute($rule, $params, $value); if ($result === false) { $this->setError($field, $rule); } } } return (count($this->errors) === 0); } public function hasErrors() { return (count($this->errors) !== 0); } public function getErrors($rule = null) { if ($rule === null) { return call_user_func_array('array_merge', $this->errors); } return $this->errors[$rule]; } public function setMessage($rule, $message) { $this->messages[$rule] = $message; } protected function execute($rule, array $params, $value) { if (isset($this->callbacks[$rule])) { $callback = $this->callbacks[$rule]; return call_user_func_array($callback, array($value, $params)); } if (method_exists($this, $rule)) { return call_user_func_array(array($this, $rule), array($value, $params)); } throw new BadMethodCallException(); } protected function parseRules($rules) { $matches = array(); $rules = explode('|', $rules); $parsedRules = array(); foreach ($rules as $rule) { if (preg_match('/(.*?)\[(.*)\]/', $rule, $matches)) { $params = explode(',', $matches[2]); $parsedRules[$matches[1]] = $params; } else { $parsedRules[$rule] = array(); } } return $parsedRules; } protected function getValue($name, $data) { return (isset($data[$name]) ? $data[$name] : null); } protected function setError(array $field, $rule) { $message = sprintf($this->messages[$rule], $field['name']); if (isset($field['label'])) { $message = sprintf($this->messages[$rule], $field['label']); } $this->errors[$rule][] = $message; } protected function required($value) { if (is_null($value) || $value == '') { return false; } return true; } protected function email($value) { return (filter_var($value, FILTER_VALIDATE_EMAIL) !== false); } }   Problem: I need to figure out how to let the parameters be added to the error messages, like this: '%s must be between %d and %d'... uh. Use:   $validator = new Validator(); $fields = array( array( 'name' => 'email', 'rules' => 'email|required', //Currently only rules implemented. 'label' => 'E-mail', ), ); $validator->validate($fields, $_POST); if ($validator->hasErrors()) { var_dump($validator->getErrors()); //Returns a flattened array with all errors... }   It's extendable, for example you could register your own rule callbacks that has precedence before the defined methods, allowing you to override currently existing rules as well. So yeah, any comments.
  23. Open source?
  24. Definitely.
  25. $35 Is the code valid HTML5/CSS3? Responsive? ( I am just wondering how much additional works that needs to be done, before implementing in game :)) Where is the domain located? Are there any domain transferring fees to be aware of?
×
×
  • Create New...