Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by ignace

  1. Yes, it is better to store it in a database then simply relying on the fact whether or not the session ID still exists. Which you will have to store in the database anyhow, if you would want to re-use it on re-authentication. Also storing it into a database allows for multiplayer shared loot and making sure the same drop item is not taken more then once.
  2. This is a problem most employed developers experience. Clean code, refactoring, testing, .., all those good bits do not convert in more ROI. "It works!" is the one and only measure in our industry. I have worked with cowboy programmers, and even with people who write stuff like: function a($b, $c) { // do stuff with $b and $c, and create variables like $d, $e, $f, .. }Not example function names, literally named like that. When I complained about it they replied it works and it goes faster then what I wrote. A part of me simply wanted to do the very same thing, write code just the same way until it was such a ball-of-mud that I could go to them and say: NO I CANT FIX IT, NO ONE CAN! BUT HEY YOU KNOW WHAT IT IS FAST
  3. Sessions are coupled to cookies. Cookies are coupled to browsers. Browsers do not share cookies, so a different browser means the user will have to authenticate again. If your concern is load on the database, this is not the solution.
  4. Instead of storing ID's in constants, maybe you can use OOP to accomplish what you are doing: class PageRepository { private static $QUERY_HOME_PAGE = 'SELECT .. FROM pages WHERE page_id = 1'; private static $QUERY_CONTACT_PAGE = 'SELECT ..'; private $pdo; private $pageFactory; public function __construct(PDO $db, PageFactory $pageFactory) { $this->pdo = $db; $this->pageFactory = $pageFactory; } public function getHomePage() { $stmt = $this->pdo->query($this->QUERY_HOMEPAGE); // return $this->pageFactory->createFromArray($data); } public function getContactPage() { return $this->pageFactory->createFromArray(..); } }
  5. Search for "js|jquery radial menu" it shows quite a few available code samples or available plugins to use directly.
  6. Since people are using the native app it may be an opportunity for you to contact the creator of the app and come to a business arrangement, where he pays you X% of the profits. Be reasonable, he did create a native app for your website. If not, you have it taken down through the app store. Though the first option is better. Not really sure what you can do as a defense, assuming the user enters his credentials into the app, which then performs a sub-request on your website and stores the cookie locally and sends them with every request there after making anti-CSRF useless. In essence the app acts as a browser, so you need to figure out how to filter out the app using only the request headers, though I assume it will only be a matter of time before these are spoofed. Also keep in mind that any counter measures you may take may result in further visitor loss which is why I really advise you to take the first option.
  7. Also if your pages always generate the same darn page, then cache it and avoid the DB connection completely. You create a unique cache key for each page and check if it exists, then stop and echo it, or continue and create the cache. Something like this: <?php $cacheKey = 'video_' . intval($_GET['id']); if (file_exists('cache/' . $cacheKey)) { include('cache/' . $cacheKey); exit; } // query DB $html = include('some/view.html'); file_put_contents('cache/' . $cacheKey, $html); echo $html;
  8. It is possible that Google, Yahoo, Bing and the likes are crawling your website. They are known to open multiple connections to crawl your website faster, but it is possible that by this they are actually hitting the limit. If you have Google Analytics installed on your website, it should be possible to detect who is at your website doing what at the time this occurs. In the case of crawlers you can tell them (atleast the legal ones) to only use 1 connection, not multiple.
  9. class Horse { public function __construct(DateTime $lastFedAt) { $this->lastFedAt = $lastFedAt; } public function feed() { $this->lastFedAt = new DateTime(); } public function isHungry() { if (date('H') < 6 || date('H') > 22) { return false; // sleeping } return time() - $this->lastFedAt->getTimestamp() > 4 * 3600; // feed every 4 hours } } class HorseFeeder { public function check(Horse $horse) { $horse->isHungry() && $horse->feed(); } public function checkLoop(Horse $horse) { while (true) { $this->check($horse); sleep(600); } }
  10. It could look like this: public function uploadAction(Request $request) { $uploadService = $this->get('upload_service'); $form = $uploadService->getForm(); if ($uploadService->handle($form, $request)) { $request->getSession()->getFlashBag()->add('success', 'Image uploaded successfully!'); return $this->redirect($this->generateUrl('foo_bar')); } return array(); }Yes, this is the same script as what you wrote up there. And this is typical for OO programming. It hides ALL the details. The UploadService would do something like this: public function handle(FormInterface $form, Request $request) { $form->handleRequest($request); if (!$form->isValid()) { return false; } foreach ($form->get('upload')->getData() as $uploadedFile) { $file = $uploadedFile->move($this->targetDirectory); $upload = new Upload($uploadedFile->getClientOriginalName(), $file->getMimeType(), $file->getSize()); $this->em->persist($upload); } $this->em->flush(); return true; }This is an example using Symfony framework.
  11. @Ionut-Bajescu thank you for your very insightful advice. Take a look at composer, it allows you to create packages that you can "require" in new projects. The Symfony framework uses independent bundles that can be distributed and installed through configuration. FOSUserBundle is such an example.
  12. You should have said to him: "So, your classes are empty." The truth is that the polishing only happens at the workplace not in uni. I have had graduates who I had to unlearn things and teach them the proper way of doing it.
  13. It depends on what you want to do. If you want to make websites and online applications, PHP is a good choice as it's easy to learn. If you wanna become a mobile developer, you want to learn Java or Swift. If you want to make games you need to learn C++ or Lua. So, it all depends on what you want to become.
  14. The second class should not extend the first class. Because then the second class can build itself thus making the first class obsolete. Also it wouldn't need the first class either to set errors, it can simply set it on itself to set it on the first class.
  15. When assigning responsibilities you should keep in mind that Crate is the Information Expert: http://en.wikipedia.org/wiki/GRASP_(object-oriented_design)#Information_Expert SRP is about the big picture, class cohesion, not about trimming all classes until they only have 1 method.
  16. Why do you require a factory to get basic properties from a Crate object? Shouldn't it be: $crate->getDimensions(); $crate->getWeight();Whatever that $options variable hold should be modelled into your Special Case Crate object.
  17. composer also supports git clone (or if git is not installed on the server, can download's the dist zip): https://getcomposer.org/doc/04-schema.md#repositories
  18. None of your examples includes a DI. Here's a rewrite of your index.php with DI: $di = include 'includes/di.php'; $di['content']->loadPage($_GET['page']);And your article_index.php $di = include 'includes/di.php'; $di['articles']->getArticles(0, 15);The includes/di.php could look something like: // download from http://pimple.sensiolabs.org/ $container = new Pimple(); $container['config_filepath'] = 'config/config.ini'; $container['config'] = function($c) { return new Config($c['config_filepath']); }; $container['db'] = function($c) { return new Database($c['config']); }; $container['content'] = function($c) { return new Content($c['db']); }; $container['articles'] = function($c) { return new Articles_Model($c['db']); }; return $container;For all your autoloading you may want to consider composer
  19. CodeIgniter is dead. And security is only as good as the programmer who wrote it. It's like the lock on your front door, it's nice to have it, useless if you never actually lock your door. From your description I am guessing they did not hack your website through software problems, but through FTP (since the JS is gone off the pages, unless you built a removeJsFromViews() function). So your FTP access is likely compromised, you might wanna change your password, or if using shared hosting, another account on the server has been able to access your account. In that case, you'll need the provider to dig through his log files.
  20. That is really hard, your mind may be blown. $dirs = array(__DIR__ . "/src", __DIR__ . "/src2"); $config = Setup::createAnnotationMetadataConfiguration($dirs, $isDevMode); To make it easier to consume: $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/src", __DIR__ . "/src2"), $isDevMode);Now for the complete meltdown: $config = Setup::createConfiguration(); $chain = new MetadataChain(); foreach (array('xml' => __DIR__ . "/src", 'yml' => __DIR__ . "/src2") as $driverName => $path) { switch ($driverName) { case 'xml': $driver = new SimplifiedXmlMetadataDriver($path); case 'yml': $driver = new SimplifiedYamlMetadataDriver($path); } $chain->addDriver($driver); } $config->setMetadataDriver($chain); ..EDIT: do not copy paste, it won't work, you'll need to do your own research.
  21. maxxd has the right idea, but i would keep it simple like this: abstract class Auto { abstract public function getWheelBase(); } class Mustang2013 extends Auto { public function getWheelBase() { return new WheelBase(17, ; } }Other option is to pass specific info to the class: class Auto { private $wheelBase; public function __construct(WheelBase $wheelBase, ..) { .. } }
  22. You can find some good books in this thread: http://forums.phpfreaks.com/topic/2307-good-programming-and-web-design-books/?p=11836 You might also want to read: http://www.phptherightway.com/
  23. Post a username and password interested can use to test your game.
  24. I've seen your questions pass on these forums and they are always very vague and very abstract. So at best you get a very vague and very abstract answer for which the chances of it actually solving your design problems are less than likely. But anyway here goes: How about: public function someMethodFromSomeGhostClass { $this->model->doSomeMethodFromSomeClassInsideGhostClassAndCrossFingers(); }
  • 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.