Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. This is how your code should have looked. I, and so does the PHP manual, discourage the use of mysql_* functions and encourage the use of mysqli_* functions. Learn CSS. Nobody use <font/> anymore nor do they use <b/> or <u/>. <?php $host = ""; $user = ""; $pass = ""; $dbname = ""; $db = mysqli_connect($host, $user, $pass, $dbname); if (mysqli_connect_errno()) { echo mysqli_connect_error(); exit; } $query = "SELECT * FROM legs"; $result = mysqli_query($db, $query) or die(mysqli_error($db)); ?> <style> /* this is CSS preferably this should be in a .css file and linked through a <link/> tag. */ body { font-family: Arial, Helvetica, sans-serif; } table { border:1px solid gray; } table thead tr th { font-weight: bold; text-decoration: underline; } table tbody tr td, table thead tr th { padding: 3px; } </style> <table cellspacing="2"> <thead> <tr> <th>Body Area</th> <th>Difficulty</th> <th>Time Needed</th> <th>Equipment Needed</th> <th>Gender</th> <th>Link</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_assoc($result)) { ?> <tr> <td><?php echo $row['Body Area']; ?></td> <td><?php echo $row['Difficulty']; ?></td> <td><?php echo $row['Time Needed']; ?></td> <td><?php echo $row['Equipment Needed']; ?></td> <td><?php echo $row['Gender']; ?></td> <td><?php echo $row['Link']; ?></td> </tr> <?php } ?> </tbody> </table>
  2. $user->fetchInfo(1);What info? Addresses? Girlfriends? And where is it getting it from? Your User object shouldnt be aware of a database, like so: class User { private $id; private $email; private $pass; public function getId() { .. } public function getEmail() { .. } }To get this User from the database I would do: $user = $em->find('User', 1); print $user->getEmail();To change his e-mail address and store it into the database: $user->setEmail('[email protected]'); $em->persist($user); // assuming explicit strategy $em->flush();The advantage to this way of programming is that I can use a User object in other parts of my application without needing a database: $from = new User(); $from->setEmail('[email protected]'); $to = new User(); $to->setEmail('[email protected]'); $messageSender->sendMessage($from, $to, 'Je hebt een banaan in je oor!');
  3. This demonstrates the apparent problem you face when you use OOP and an RDBMS without an ORM. This code will work until you have an object with relations to other objects. Suppose User has a Role object. So you would need 2 queries or a JOIN but then you will have to manually write out the colums you need, possibly aliasing a few and then mapping them to the appropriate objects. This becomes really tedious real soon which is why everyone uses an ORM. The above code also assumes all your properties are public which is not good. For PHP there are multiple ORM's available the most popular being Doctrine and Propel.
  4. I guess this does what you want? // match <td>[email protected]</td> if (preg_match_all('~<(td)>(?<content>[_a-z0-9-]+(?:\.[_a-z0-9-]+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*(?:\.[a-z]{2,3}))</\1>~Uis', $gesamteDatei, $matches)) { foreach ($matches['content'] as $email) { // } }If you want to test your regular expressions, you can do so here: http://www.solmetra.com/scripts/regex/index.php
  5. ignace

    Ad Services

    Google AdWords?
  6. https://github.com/jsor/Geokit/blob/master/src/Geokit/Calc.php This class shows you how you can calculate the distance between 2 lat/lon points. Use the distanceHaversine method.
  7. So what is the problem? Simply leave out http://. fsockopen only takes a server address.
  8. $this is only available when you have instantiated an object. In a static content is $this not available. I think you mean: self::$info = self::$instance->getUserInfo(self::$info['id'], $fields);
  9. Keep it to one topic please. http://forums.phpfreaks.com/topic/277745-how-can-i-learn-php/?do=findComment&comment=1428840
  10. I don't see any advantage to this looking at the available Validator's already on the market. https://github.com/symfony/Validator https://github.com/zendframework/Component_ZendValidator.git https://github.com/Respect/Validation.git
  11. function cart_add($id, $quantity = 1, $color = null) { if (!isset($_SESSION['cart'])) { $_SESSION['cart'] = array(); } if ($quantity === 0) { if (isset($_SESSION['cart'][$id])) { unset($_SESSION['cart'][$id]; } return; } if (!isset($_SESSION['cart'][$id])) { $_SESSION['cart'][$id] = compact('id', 'color', 'quantity'); } else { $_SESSION['cart'][$id]['quantity'] += $quantity; } }You can use this like: session_start(); cart_add(1, 5, 'green'); // 5x green cart_add(1, 2); // 7x green cart_add(1, 0); // removed
  12. function addOrReplaceParam($params, $value = null) { if ($value !== null) { $params = array($params => $value); } return http_build_query(array_merge($_GET, $params)); }You can use it like: <a href="foo.php?<?= addOrReplaceParam('foo', 'bar') ?>">foobar</a>Or like <a href="foo.php?<?= addOrReplaceParam(array('foo' => 'bar', 'bat' => 'baz')) ?>">more foobar</a>
  13. If you have an idea for an application it's best NOT to create while you are learning. But create it once you have learned. Pretty much the same thing that you don't build a house while learning how to build a house but only do so when you have learned the required skills. The reason being that you will spend too much time on details while your learning should be put on a central spot. Also avoid learning stuff you know how it will be/is accomplished and only focus on the things you don't know. What this means is that you will for example create only a form (for example because you are learning about login), or only a button, because you are learning about google/facebook login. Don't spend any time on unnecessary details, like creating a layout or something.
  14. I think the lottery is a bad reference, I don't know how poweball lottery works but if it's lottery like we have it, every week somebody wins and sometimes multiple people guess the same numbers. So there is a high collision rate. Not preferable for something that should beat AES256. It doesn't matter how good or bad the odds are, there is still a thing called usability. Show a person the 25 images and let them select 1 each time, tell them to remember it, note their choices down. After 10 symbols are selected ask them to repeat the symbols in the correct order. The odds of someone repeating the symbols in the correct order is as slim as an attacker trying to brute-force their way in. Not to mention that there are already ways to bypass the "flaws" of md5 or sha1 or the like. Which is why most now use PBKDF2 (designed to be slow so that decrypting takes years not mere minutes/seconds like hashing algorithms) and people are encouraged to use phrases (easier to remember, longer then passwords, and harder to crack) instead of passwords. Which achieves the goal without getting in the way of users.
  15. 1. The hacker knows each password has 10 symbols (no way to stop after 5 for example), so it is a limited finite set. So 95,367,431,640,625 is highly exaggerated. 2. User's can't go beyond 10 gates, so "passwords" can't be made stronger. Which is not a problem in my above code, a user can select one code or 1000. 3. Your system has the same weaknesses a normal password has suppose someone selects the first image of each gate. 4. Because you require no username all "passwords" have to be unique otherwise 2 people can no longer login. Because "passwords" have to be unique it's possible for someone to unwillingly hack someone else's account. Just like you have collisions with regular passwords. And that is just out of the top of my hat. No, what this does is make it harder for anyone to login (they have to remember the exact symbols in the exact order) while a hacker just simply uses a script to send the sequence. It doesn't need to recognize images you send the user from gate1 to gate2 with an identifier. The script would simply query each gate with a new set.
  16. No. He is my code again more thoroughly documented. /** * We start the session here to store our steps between requests. */ session_start(); /** * If the 'sequence' does not yet exist, create it. Or clear it if ?sequence=1 is passed. */ if (!isset($_SESSION['sequence']) || (isset($_GET['sequence']) && $_GET['sequence'] === 'clear')) { $_SESSION['sequence'] = array(); } /** * When a user clicks an image it will contain ?code=X we check here if this is the case */ if (isset($_GET['code'])) { /** * It is. Store the code in our session so that it persists between requests. */ $_SESSION['sequence'][] = (int) $_GET['code']; } /** * User appears to be finished and asks us to find the user with this sequence. * Just to be sure we check if 'sequence' infact contains codes. */ if (isset($_GET['verify']) && !empty($_SESSION['sequence'])) { $db = mysqli_connect('host', 'user', 'pass', 'db') or die('Database has left the building!'); if ($stmt = mysqli_prepare('SELECT username FROM users WHERE password_sequence = ?')) { $sequence = implode(',', $_SESSION['sequence']); $stmt->bind_param('s', sha1($sequence)); $stmt->execute(); $stmt->bind_result($username); $stmt->fetch(); echo 'Hello, ', $username; exit; } } /** * Creates an array with numbers from 1..10 */ $numbers = range(1, 10); /** * Create an array with key=>value pairs where key is the number and the value is the image. * * In other words the result will look like: * array ( 1 => '01.jpg', .. ) */ $images = array_combine( $numbers, array_map(function($i) { return sprintf('%02d.jpg', $i); }, $numbers) ); /** * Display the images to the user * * This outputs: * <a href="?code=1"><img src="01.jpg" alt="" width="100" height="100"></a> */ foreach ($images as $number => $image) { printf( '<a href="?code=%d"><img src="%s" alt="" width="100" height="100"></a>', $number, $image ); } // display verify link echo '<a href="?verify=1">verify</a>';
  17. Store the player's progress in a session that way when he would take separate routes (between tabs/windows) you can detect he did and act upon it. The same goes for when he would open a new window. You can also store his progress in the database.
  18. You don't need multiple gate*.php files. One file will do. Every time you click on an image it sends you to the same page with a different ?code=X, it stores these codes and when the user clicks verify it tries to find a match in the database containing the entered codes. Suppose my sequence is the images clicked in this order: 1, 7, 13, 19, 25 (diagonal) then I would send the following requests: gate1.php?code=1 gate1.php?code=7 gate1.php?code=13 gate1.php?code=19 gate1.php?code=25 I have entered my sequence and therefor I send the last request: gate1.php?verify=1 The database is queried a match is (hopefully) found and I am logged in.
  19. session_start(); // our sequence container if (!isset($_SESSION['sequence']) || (isset($_GET['sequence']) && $_GET['sequence'] === 'clear')) { $_SESSION['sequence'] = array(); } // user passed a code, store the code in the sequence container if (isset($_GET['code'])) { $_SESSION['sequence'][] = (int) $_GET['code']; } // user asked us to verify what is currently in the sequence container (omit if empty) if (isset($_GET['verify']) && !empty($_SESSION['sequence'])) { $db = mysqli_connect('host', 'user', 'pass', 'db') or die('Database has left the building!'); if ($stmt = mysqli_prepare('SELECT username FROM users WHERE password_sequence = ?')) { $sequence = implode(',', $_SESSION['sequence']); $stmt->bind_param('s', sha1($sequence)); $stmt->execute(); $stmt->bind_result($username); $stmt->fetch(); echo 'Hello, ', $username; exit; } } // our numbers $numbers = range(1, 10); // corresponding images $images = array_combine( $numbers, array_map(function($i) { return sprintf('%02d.jpg', $i); }, $numbers) ); // display images foreach ($images as $number => $image) { printf( '<a href="?code=%d"><img src="%s" alt="" width="100" height="100"></a>', $number, $image ); } // display verify link echo '<a href="?verify=1">verify</a>';A user can create a sequence as long as he likes (just like a password, the longer the better). When he presses verify the currently stored codes are converted to a string and separated by a , so that a sequence of 1,2 and 12 do not match the same thing. The sequence is then encrypted with sha1 (the same rules as with a password still apply here). For this to work you need a UNIQUE constraint on the password_sequence. No 2 people can have the same sequence. This of course imposes a problem because a hacker would now be able to simply enter simple sequences to login to someone's account (without having to know their username or e-mail or any other info). So to put the security at the same level as a normal login you need to provide a username field.
  20. $sql = "select * from mr_recipes WHERE id "; WHERE id Where id is what? You have to tell it what id you are looking for.
  21. It's a standard try/catch: try { $this->activateFunction(); $this->activatePlan(); .. } catch (ComponentActivationFailed $e) { return $e->getMessage(); } class ComponentActivationFailed extends Exception {}If you need to specifically know which component failed: try { $this->activateFunction(); $this->activatePlan(); .. } catch (FunctionActivationFailed $e) { .. } catch (PlanActivationFailed $e) { .. } catch (ComponentActivationFailed $e) { // catch-all } class FunctionActivationFailed extends ComponentActivationFailed {} class PlanActivationFailed extends ComponentActivationFailed {}
  22. Most browsers give you the option to replay Ajax requests. There are even browser extensions that allow you to create ajax calls with for example POST and JSON as body. @faces3 if you have Chrome installed (if not, install it) go to your page where you would call the ajax. Options (the three horizontal lines) > Extra > Developer Tools. This opens a new pane at the bottom. Click Network and click on XHR at the bottom. Now fire your ajax and you'll see that a new line appears. Click it and select Response, fix your code, come back and right-click on the line and select Replay XHR, another line appears, click it and select Response. Keep repeating this process until you have the output you expect.
  23. Download/Install Zend\Form Create an abstract form type to represent a quiz qa (ie setQuestion, setAnswers/setOptions, getUserSelectedAnswers) extending Zend\Form Create a form for each of the different quiz question categories, add additional methods where required (but favor configuration) Make sure each of the forms render correctly Create a factory to build the different form types (used to build the form objects from text in your database)
  24. Now you made me curious, link?
  25. Symfony2, Zend framework 2.0, .. Look for a framework that does not constrain your modeling in any way. To give an example in CI & CI2 you need to extend Model and call it through their Loader interface for it to work. That's a BIG no-no
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.