Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. If data transfer objects is what you are looking for. Doctrine has you covered aswell: http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html#new-operator-syntax
  2. When posting code please always use your code goes here tags. You can find them as on the editor.
  3. By that he means make sure the following and any derivatives thereof does not work: download.php?file=download.php <-- should NOT workThe reason being that it could compromise your website and allow hackers to download sensitive information.
  4. If you expect someone to help you at the very least properly format your code when you post it. You have dumped your shit and expect us to weed through it and then give you the answer on a silver platter, most would be inclined to simply ignore your threat. Put in effort or at the very least show that you tried to solve it and where you are currently stuck. The code below is more pleasant to read don't you think? Anyway to return the favour I have inserted the answer in this wall of text: <script type="text/javascript"> var map; var polyShape; var markers = []; var drag_poly = false; var mouseDownPos; var oldVertexPos; var toplace = [new google.maps.LatLng(52.63586014925004, 1.2875261303270236), new google.maps.LatLng(52.63888119537785, 1.3024606701219454), new google.maps.LatLng(52.632838894493, 1.325119971879758), new google.maps.LatLng(52.626587360201505, 1.314305305131711), new google.maps.LatLng(52.62294021941067, 1.304520606645383), new google.maps.LatLng(52.62585795635695, 1.2856378551805392), new google.maps.LatLng(52.6309635279822, 1.303147315629758), new google.maps.LatLng(52.63190122128495, 1.281174659379758)]; function createMarker(g) { var f = google.maps; var h = function (a) { return { url: a, size: new f.Size(11, 11), anchor: new f.Point(5, 5) } }; var e = new f.Marker({ position: g, map: map, icon: h("/images/google_maps/square.png"), raiseOnDrag: false, draggable: true }); markers.push(e); f.event.addListener(e, "mouseover", function () { e.setIcon(h("/images/google_maps/m-over-square.png")) }); f.event.addListener(e, "mouseout", function () { e.setIcon(h("/images/google_maps/square.png")) }); f.event.addListener(e, "drag", function (a) { for (var b = 0, d; d = markers[b]; b++) { if (d == e) { var c = a.latLng; break } } polyShape.getPath().setAt(b, c); showValues() }); f.event.addListener(e, "click", function () { for (var a = 0, b; b = markers[a]; a++) { if (b == e) { b.setMap(null); markers.splice(a, 1); break } } polyShape.getPath().removeAt(a); showValues() }); return e } function movePoly(a) { if (drag_poly) { var b = a.latLng; var d = polyShape.getPath(); for (var c = 0, g; g = oldVertexPos[c]; c++) { var f = g.lat() + b.lat() - mouseDownPos.lat(); var h = g.lng() + b.lng() - mouseDownPos.lng(); var e = new google.maps.LatLng(f, h); d.setAt(c, e) } } } function startDrag(a) { var b = google.maps; drag_poly = true; mouseDownPos = a.latLng; oldVertexPos = []; for (var d = 0, c; c = markers[d]; d++) { oldVertexPos[d] = c.getPosition(); b.event.clearInstanceListeners(c); c.setMap(null) } markers.length = 0; map.setOptions({ draggable: false }); b.event.addListener(map, "mousemove", movePoly); if (window.event) { window.event.returnValue = false } a.stop() } function mouseUp() { if (drag_poly) { drag_poly = false; map.setOptions({ draggable: true }); google.maps.event.clearListeners(map, "mousemove"); var a = polyShape.getPath(); for (var b = 0; b < a.getLength(); b++) { createMarker(a.getAt(b)) } } } function setShape() { var a = google.maps; var b = { strokeColor: "#3355ff", strokeOpacity: .8, strokeWeight: 3, fillColor: "#335599", fillOpacity: .3, map: map }; polyShape = new a.Polygon(b); polyShape.listeners = [a.event.addListener(polyShape, "mousedown", startDrag), a.event.addListener(polyShape, "mousemove", movePoly)]; document.onmouseup = mouseUp } function showValues() { var a = document.getElementById("report"); var b = google.maps.geometry.spherical; var d = polyShape.getPath().getArray(); document.getElementById("paths").value = d; var c = b.computeArea(d, 6371); if (markers.length <= 2) { a.innerHTML = " " } else if (markers.length > 2) { a.innerHTML = c.toFixed(3) + " kmĀ²" } } function leftClick(a) { if (a.latLng) { if (!polyShape) setShape(); createMarker(a.latLng); polyShape.getPath().push(a.latLng); showValues() } } function buildMap() { var a = google.maps; var b = { center: new a.LatLng(52.6322568, 1.3127337), zoom: 12, zoom: 8, mapTypeId: a.MapTypeId.ROADMAP, draggableCursor: 'auto', draggingCursor: 'move', disableDoubleClickZoom: true, mapTypeControlOptions: { mapTypeIds: [a.MapTypeId.ROADMAP, a.MapTypeId.SATELLITE, a.MapTypeId.TERRAIN] }, panControl: false, zoomControlOptions: { style: a.ZoomControlStyle.SMALL } }; var poly = new google.maps.Polygon({ path: toplace, strokeWeight: 1, fillColor: '#55FF55', fillOpacity: 0.3 }); poly.setMap(map); // map is not (yet) defined --v You may also want to register to the event listener so that you only add the polygon to the map when it is fully loaded map = new a.Map(document.getElementById("map"), b); setShape(); a.event.addListener(map, "click", leftClick); } function zoomToPoly() { if (polyShape && polyShape.getPath().getLength() > 1) { var b = new google.maps.LatLngBounds(); polyShape.getPath().forEach(function (a) { b.extend(a) }); map.fitBounds(b) } } function clearPoly() { var a = google.maps; for (var b = 0, d; d = markers[b]; b++) { a.event.clearInstanceListeners(d); d.setMap(null) } if (polyShape) { for (var c = 0, g; g = polyShape.listeners[c]; c++) { a.event.removeListener(g) } polyShape.setMap(null); polyShape = null } markers.length = 0; document.getElementById("report").innerHTML = " " } window.onload = buildMap; </script> <div id="map"></div> <table id="desc"> <tr> <td>Click at least at three different places on the map to draw a polygon. <b>Try to drag the shape of the polygon.</b> The corners of the polygon are draggable and removable at any position. You can add and remove vertices simply by click.</td> </tr> <tr> <td>Area of polygon:</td> </tr> <tr> <td id="report"> </td> </tr> <tr> <td style="height:20px"> </td> </tr> <tr> <td> <a href="#" class="button" onclick="zoomToPoly();return false;">Zoom To Polygon</a> </td> </tr> <tr> <td> <a href="#" class="button" onclick="clearPoly();return false;">Remove Polygon</a> </td> </tr> <tr> <td style="padding-right:19px; height:30px;"> <span class="include"><a href="../index.html">Back</a></span> <form action="" method="POST"> <input name="paths" id="paths" value="" type="hidden" /> <input type="hidden" id="submitpath" value="Save Paths" name="save_paths"> <input type="submit" id="Save" value="Save" name="Save"> </form> </td> </tr> </table>
  5. 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>
  6. $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('my-brand-spanking-new@gmail.com'); $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('bert@bert-en-ernie.nl'); $to = new User(); $to->setEmail('ernie@bert-en-ernie.nl'); $messageSender->sendMessage($from, $to, 'Je hebt een banaan in je oor!');
  7. 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.
  8. I guess this does what you want? // match <td>some@email.com</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
  9. ignace

    Ad Services

    Google AdWords?
  10. 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.
  11. So what is the problem? Simply leave out http://. fsockopen only takes a server address.
  12. $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);
  13. Keep it to one topic please. http://forums.phpfreaks.com/topic/277745-how-can-i-learn-php/?do=findComment&comment=1428840
  14. 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
  15. Create a database. Read up on how to create a database and normal forms. Once you have that you can start by creating functions that will handle your requirements: You will need to flesh these out more so that you get actionable requirements like these: function player_join_team($player_id, $team_id) { // .. code here } function player_leave_team($player_id, $team_id) { // .. code here } function team_create($name, ..other attributes..) { // .. code here }Also think about these requirements and get into details like will a player be able to join any team or does he need an invite? These things change your requirements and thus also your code. Your requirements won't always match a function, sometimes to fulfill a requirement you will need multiple functions maybe even several user actions to fulfill the requirement for example registering and verifying their e-mail address. Having a good set of requirements and having a rough idea on how to complete them is half the battle. Requirements generally are formed like this: These come with prerequisites, something like this: Having all this information before you start to actually program will make it much easier then when you would just have:
  16. 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
  17. 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>
  18. 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.
  19. 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.
  20. 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.
  21. 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>';
  22. 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.
  23. 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.
  24. 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.
  25. $sql = "select * from mr_recipes WHERE id "; WHERE id Where id is what? You have to tell it what id you are looking for.
×
×
  • 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.