ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
$user = new User(); $data = array('first_name'=>$_POST['first_name'], 'last_name'=>$_POST['last_name'], 'email'=>$_POST['email'], 'password'=>md5($_POST['password'])); $user->data = $data; //set the 'data' property $user->save(); //save the new user to the database As User being part of the domain, and models being free of storing and presenting themselves, the correct approach would be: $user = new User($data); $userRepo->save($user); $isLoggedIn = $user->login($_POST['email'], $_POST['password']); if(!$isLoggedIn) { /*do something*/ } else { /*do something*/} The same applies here, a User is not responsible for authentication: $authService = new AuthService(); if($authService->logon($user)) {
-
Your database schema will look somewhat similar to: CREATE TABLE user ( user_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, user_email_address VARCHAR(96) NOT NULL CHARACTER SET utf8 COLLATE utf8_general_ci, user_password CHAR(40) NOT NULL CHARACTER SET ascii, INDEX idx_user_logon (user_email_address, user_password), UNIQUE INDEX idx_user_email_address (user_email_address) ) ENGINE = MyISAM; CREATE TABLE website ( website_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, website_url VARCHAR(255) NOT NULL CHARACTER SET utf8 COLLATE utf8_general_ci, website_count INT UNSIGNED NOT NULL DEFAULT 1, website_is_visible TINYINT(1) NOT NULL DEFAULT FALSE, INDEX idx_website_url (website_url), INDEX idx_website_is_visible (website_is_visible) ) ENGINE = MyISAM; CREATE TABLE list ( list_website_id INT NOT NULL, list_user_id INT NOT NULL, list_comment VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci, list_website_is_accepted NOT NULL DEFAULT FALSE, PRIMARY KEY (list_website_id, list_user_id) ) ENGINE = MyISAM;
-
Yes it's possible to let PHP run as a "daemon" using the command: set_time_limit(0); However as PHP is not designed for such applications it may be best to look for other technologies that better fit the bill like Flash. The new ActionScript comes with socket server support like ElectroServer (which is specifically designed for hosting Flash-based MMO games). The same company (ElectroTank) also released a book explaining every bit you need to get your own game up and running (ActionScript for Multiplayer Games and Virtual Worlds).
-
Hiding certain parts of a web page - best way of doing it
ignace replied to mds1256's topic in PHP Coding Help
Who would stop me from making a script that would post the exact same variables to his login script using a directory attack? The #2 method is better because some people may have CSS set to off and the form would display to them. That's the only reason as to why #2 is better, not for stopping hackers. You'll have to write custom code to prevent people from submitting a form remotely, like: <?php session_start(); if(!isset($_SESSION)) { $_SESSION['form_token'] = uniqid(true); } if(sizeof($_POST)) { if($_POST['token'] !== $_SESSION['form_token']) { exit('form denied'); } else { if(empty($_POST['username']) || empty($_POST['password'])) { $errors[] = 'username and password are empty'; } else if (..) { } if(sizeof($errors)) { $_SESSION['form_token'] = uniqid(true); // errors detected, generate a new token for next form submission } else { .. } } } $token = $_SESSION['form_token']; ?> <form action="#" method="POST"> <input type="hidden" name="token" value="<?php print $token; ?>"> </form> -
That depends on the kind of framework you chose for. A full-stack framework will limit you, a glue framework will not. For the hobbyist? Frameworks like those of Zend are not merely for the hobbyist, if a hobbyist is even capable of getting past the steep learning curve. Writing your own framework and using it's component will make you competent in PHP programming not in it's inner workings. If you want to learn what makes PHP tick you should start with the manual (especially the sections on Language Reference, PHP at the core, and the Appendices). Get your hands dirty, learn C and write a PHP extension. Documentation means nothing if the framework isn't properly tested.
-
It may also be a good idea to use a framework so you won't have to bother with writing all this tedious tasks and focus on writing the actual application.
-
#3
-
Presuming you used zf.bat you should find a constant APPLICATION_PATH in the index.php which you can use throughout your project, like: $fileLocation = APPLICATION_PATH . '/files/1.jpg';
-
You want to use Exceptions.
-
Either of these is the solution your looking for:
-
It makes sense of course. Why put a $1500 training on lynda.com for $37. Everything is possible of course on the Internet (well, not everything then). Thx
-
Drawing lines on a piece of paper is difficult?
-
I have over 38 RSS feeds so I'm well-aware of what goes on in the blogosphere. I was just scouting to see if there are any good tutorial-based websites prior to considering training.
-
Hi, Does anyone know of any better service websites like Lynda.com (and not net.tutsplus.com)? Although it contains a lot of tutorials, I can't find the particular topics I am interested in concerning software analysis, -design, methodologies, ... I have only found websites similar to Lynda.com through Google, so I'm not sure if these even exist. Regards
-
For projects like these it may help to use wire-frames. This could be an example for the bike-shop:
-
1. use built-in functions as intended: $db_res = mysql_connect('localhost', 'root'); mysql_select_db('test', $db_res); 2. do not use die() use trigger_error() instead 3. do not create your tables in your application 4. ALWAYS properly escape your data: $tableName = mysql_real_escape_string($tableName); 5. use meaningful function names 6. use meaningful argument names 7. do not output inside functions, rather use the returned value and output it afterwards. 8. put related functions in an object 9. only include/require functions (libraries), don't include files that will execute once their included (this helps to avoid #10) 10. don't clutter the global scope
-
The nail right on the head!
-
When became wedding's so complicated?
-
@robcrozier As you can tell by the comment of @thorpe choosing a framework is no easy task. My point - although not really clear - is that each framework has different goals and these may or may not suit your project, choose wisely. However from my personal experience I can advise you not to use CI nor CakePHP (which is a bottleneck of it's own, unless you are really experienced with the framework and know where these bottlenecks are and how to fix them). For a legacy product I had to implement a few new features and learn CI along the way - which sounded interesting at first - until I found myself in the deep-end, frustrated as to why I could not just pass the "Active Record" to a function and modify it (or reset everything for that matter), or simply parse the query or create a simple UNION statement. Create a pre-defined set of requirements. Find and select the frameworks that fulfill these requirements and benchmark the hell out of it! The single framework that beats all tests is the one you want.
-
If you query on a primary key you get - at maximum - 1 result as a primary key is a unique index back so their is no need for the LIMIT-clause.
-
I have finally completed my site - I need your advice now!!
ignace replied to jeger003's topic in Website Critique
<a href="#wyoming_zip_code" onclick="showZipCodeDialog()">..</a> <a name="wyoming_zip_code">..</a> -
$itemEquipped = mysql_fetch_assoc(mysql_query("SELECT $slotName FROM user_database WHERE user_id='$userID' LIMIT 1")); Strange code. If you query on primary key how many records do you think you'll possibly get back? If you perform one single mysql_fetch_assoc() how many records do you think you'll get back?
-
Like goldbarhosting already said the layout is great, the colors however... Purple is indeed beautiful but this is crazy