Jump to content

gizmola

Administrators
  • Posts

    5,882
  • Joined

  • Last visited

  • Days Won

    139

Everything posted by gizmola

  1. There are entire books written about this subject. Your choice of database/datastore will drive the solution, but in general, an individual listing would have one or more attributes that indicate its location. With that said, services like yelp are doing sophisticated geo-location these days, not to mention having a fairly constant data entry effort going on, in order to insure that businesses exist in their directories with full name + address + city + state/province + postalcode + country.
  2. I prefer redhat/centos/amazonlinux for server distros. I don't think that Debian is "by far" the best server distro, but I have used it, and I find it a good option, even if it's not my goto distro. With that said, I've always thought of ubuntu as a contender for people wanting linux workstations, and most of the people using ubuntu went in that direction because they want linux as their workstation OS. I think you also do both Ubuntu and Debian a disservice when you don't acknowledge that Ubuntu is built upon the bones of Debian.
  3. Glad to see ya back in the mod pool.
  4. I understand what your code does, and pinpointed why you are getting a result that surprises you. It is because you never get to the condition that checks for the variable == null. Thus you attempt to echo out a variable that is not set. Thus you get a notice. The rest of the advice provided and reitereated by ginerjm has to do with helping you see how you can write better clearer more maintainable code, whiich ostensibly is the entire reason you're trying to use OOP in the first place, right?
  5. There's just too many hosting options out there to even describe. Cloud options like aws are very popular because you can ramp up things when needed, and ramp down when you don't. A lot of the staff here at phpfreaks (myself included) have used Linode. I've also heard good things about Digital Ocean. There are plenty of articles out there talking about the strengths and weaknesses of each. The entry and even mid level costs for these services is quite reasonable. I have a personal aversion to hosting panels, as they bloat the server and eat up precious resources. I do understand that in some circumstances where you need a control panel to turn over to clients, a reseller account can be a viable option, but I really think that the tide has turned in favor of "cloud" ie. "VPS" resources. You can also develope using Vagrant/Virtualbox and basically run your own development resources locally, having an environment that is nearly identical to your desired deployment environment. Pair that with a paid github account and you have everything you need to develop responsibly and effectively, as well as helping automate deployment of updates. And during development you can easily make a localhost development server available for client review using ngrok.com.
  6. You're trying to utilize null and isset() in a very odd manner. The immediate problem is that when you try (if (!$log) and you pass null to that, the condition is going to be true. With that said, this really isn't good coding philosophy: function CheckIfUserLoggedIn() { if(isset($_SESSION['user'])) return false; This appears to do the opposite of what the naming suggests. Why would a logged in user (due to the presence of a session variable) return false? Try and have your naming match the intention of the code, and break things down into discreet pieces that do one thing.
  7. MySQL really doesn't support load balancing for writes. It does support slaves/replication for reads. So the idea of putting a load balancer in front of a set of mysql servers isn't used from what I've seen. I think what you're really looking for is: http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html You can google for mysql replication and get more information.
  8. You just have to read this until you're really really clear what it offers: http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html
  9. Greetings, and good luck with OOP. One way to think about an object is as a struct/record, with an element that stores an array of pointers to functions. That is the basic implementation for most languages AFAIK. PHP has single inheritance, interfaces, support for scoping (public, private, protected) and some new tricks like traits. If you can get the knack of static methods (imagine one magic object that the os creates for you) vs dynamic instantiation (ie. Myclass::foo() vs. $obj = new Myclass() ) you'll be well on your way.
  10. Getting the join syntax right was certainly important, however i bet it's still table scanning. Did you do the EXPLAIN EXTENDED on the query? If it's a small data set it won't matter that it's table scanning, but it does put a lot of stress on the database, if these types of queries are happening frequently, and of course over time, if the dataset becomes large, performance degrades. If this is just a "once and a while" query, then I wouldn't worry about it.
  11. PHP programming is not complicated. Web development is complicated, and PHP is highly focused on solving web development problems. As you stated, you need to learn a lot of things: How does the WWW work? How does the internet work? What is HTML? What is CSS? What is javascript? Why, when where do you need javascript? What is HTTP and what do I need to know about it? What features do browsers offer, and why/when are the used? (Cookies, HTML5) How do I setup the various servers and modules needed in order to code specific things (unix/linux, command lines, etc.) All of this before you even can really turn the corner on what PHP does, or get into data persistence (files, relational database and document stores, caches, etc). Based on what you've said, I would highly recommend, that you learn html + css to the point that you can create and style a nice web page. This includes building forms using all the various form input types. The good news is that there are so many free resources available not to mention places like codeacademy, all for free, and you don't need anything but a browser and a text editor to study and practice. After that you can either proceed to javascript, or start in on PHP. Personally, I'd recommend adding javascript, at least to the degree that you can do some basics. Learning jquery around this time would not be a bad thing either. Once you can create web pages, with HTML, css and javascript, you're ready for PHP. Trying to dive into PHP without those foundation elements, can certainly be extremely confusing, because you don't have any context for many of the features of PHP. Also, all the browsers have tools now like firebug that let you look into the workings of existing web pages, or the ones you create, so that you can debug javascript, look at the DOM, check out the HTTP requests. I would have killed for tools like these when I was starting out in this field.
  12. Any time you try and relate tables using a computed value, no indexes can be used. Index matching is very simple stuff, a must equal b. No doubt you are table scanning the tables, and your time to run is a function of that. Of course you can and should do "EXPLAIN EXTENDED query" to validate statements like the one I'm making, but having two tables related by an integer key, and having one of those values be negative, is just comically wrong. I believe there are even small datatype mismatch issues like whether or not the column was signed vs unsigned that can cause problems.
  13. All we have here is model classes. You are using the doctrine2 orm. Controllers or command scripts would need to actually initialize your database connection and instantiate objects before you persisted anything at all.
  14. I know it's hard to throw away stuff you know and are productive with. If you get some time play with symfony2. So much goodness in there, and tremendous velocity in terms of support. Lots of other projects are using the core symfony2 components. Drupal and phpbb for example are both well into rewrites using the components, and then you have other frameworks like laravel using a lot of their core. Even if you don't ever want to go to a framework, it's really worth looking at your personal stack and figuring out how to move it to component libraries and PSR-0 compatibility. You can do this easily enough by setting up your libraries in github and learning the basics of composer. You can then get access to all the libraries out there, and mix them into your ongoing work. I've recommended this presentation to lots of folks: This is the lead documentation guy for Symfony2, and just does a great summary of the history of this, and goes over a few of the core symfony2 components, showing how you can easily explore them individually. The same guy has an online training site, and they offer up a number of free webcasts that are worth watching for 5 mins: Namespaces was the important facilitating addition to php: http://knpuniversity.com/screencast/php-namespaces-in-120-seconds Composer: http://knpuniversity.com/screencast/composer I need to fix the borked phpfreaks home page and post up this info one of these days.
  15. Hi BlueFilly, The first issue is not really an error per-se. It is a "Notice". PHP is a scripting language, that is easy going about things like checking for the existence of variables before attepting to reference or use them. Your plugin has some loose coding, which is not necessarily a problem, however, it appears that most likely your PHP version or configuration of your hosting server has been changed. My first comment is that, for a production server, errors should never be displayed to end users. Production settings should not display errors, and any errors generated should be logged to files on the server. As for the 2nd issue, that could be related to the first one. In order to fix this, you have a couple of options. The first one is to change settings in the php.ini file on your server. Probably this is what changed in your environment. The 2nd is to add some settings to your wordpress config file, which is an option if you really only are using the WP php app on your server or if you can't access and change your php.ini (which also requires you to be able to restart your web server to pick up changes). There's relevant info here: http://codex.wordpress.org/Editing_wp-config.php#Configure_Error_Logging In summary, you need to set your display errors off in the php.ini display_errors = Off display_startup_errors = Off log_errors = On error_log = /some/writable/path/on/your/server/logs/php_error.log This type of configuration is really a system administrator level exercise in most cases. You may have to seek support from your hosting company.
  16. Hehe, no worries man, we have all been there. Glad to see you are still alive and kicking, and doing the Java thing. The PHP world has really exploded since the major frameworks guys got together and put together some standards for library autoloading, and we have this great tool composer now that allows you to install and use libraries together, that makes php comparable to ruby, node and python finally. Some great stuff in the frameworks area too, like Symfony2 and Zend Framework2 (both ground up rewrites) heavily inspired by Spring and similar Dependency Injection frameworks. PHP doesn't feel as dirty as it used to.
  17. json_decode has an option to convert the decoded output into an array rather than a series of objects. This is often preferable in a scenario like this, where you have a deeply nested structure. Add true as a second param: $json_output = json_decode($json, true); var_dump($json_output); Now you will get a dump of the array and it should be a lot easier to see how to get down to the elements you want either by direct array index manipulation or nested foreach() blocks.
  18. Hey ober, long time no see. Out of curiousity, does this table use the myisam engine, or innodb or some other engine?
  19. I don't see any issue with that sql script. MySQL supports a number of different syntax options for things like joins, and that syntax appears to me to be valid.
  20. This is a common misconception that people have about sessions. "Login" is an application concept. Sessions are simply per-connection server-side storage. An anonymous user hitting your server will create a session in most cases. By default sessions are stored as files on your file server. You can look at the manual page to see how the garbage collection works, but as skunkbad stated, without a quorum of users hitting your site, the probability calculation won't be triggered, and garbage collection will not cleanup the session files. Regardless of this fact, your application would be better served if you set an application expire time in your session, and utilized that to determine that someone should be logged out. With that said, one fairly easy way of doing what you're trying to do, would be to change the storage of your sessions from the default to a cache system like memcache, where you can control the expiration of the storage separately at creation time. I don't advise that you do that until you better understand session mechanics, however, memcache is certainly a high performance/scalability step, should your deployment ever get to the point that you require multiple servers behind a load balancer. I would still recommend that you handle "login" in your application code. Also, to be clear, these calculations can only be determined when requests are made. An idle browser will not show that the client is "logged out" if no requests are made to the server.
  21. Your orginal basic code is doing this: int(float/float - float) A cast to int is going to be equivalent to a php cast to int or the use of intval, in that it discards the floating point portion of the result. So either: $NRSLATHOR = (int)($LSLATVER / $PITCHVER) - .; or $NRSLATHOR = intval($LSLATVER / $PITCHVER) - .); I would probably opt for the 2nd option in your case. If you're not getting the same result, then it's a case of the floating point defaults in use by each implementation creating rounding errors of slightly different proportions. Just FYI, don't sprinkle so many typecasts into your PHP code. If you start with an integer (no decimal point) then it's an int. PHP will typecast using the rules described here: http://www.php.net/manual/en/language.types.type-juggling.php If you're getting odd results, you want to look at the intermediary results of the floating point operations and how rounding is occurring, rather than looking at the truncation, which is very simple. In the case of both your original basic program, and the php program, use of floating point numbers have reliability issues: http://www.php.net/manual/en/language.types.float.php This paper gets pretty heady very quickly, but goes into more detail: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html My guess is that you are encountering the differences between how your old basic program handles floating point rounding errors, and how php is handling it on the operating system you are running under.
  22. I hope you evaluate the advice from AJinNYC and trq, as they both provided great suggestions. Obviously, the larger the hash, the more characters you have to store in your table for the password, but that shouldn't be a concern.
  23. In my opinion, the best solution is not to encrypt the password but to hash it. A hash can not be decrypted. As entire books have been written on this subject, and it's non-trivial I'll try and limit myself to a few comments. md5 is one such hash, and is not a terrible choice if you take other precautions, however, there are better hashes available -- sha1 for example. It's very important that you use a salt when you're hashing the password. The best practice lately, is that you hash or encrypt passwords using a large number of repeated operations. For example, rather than hash the password once, you might hash it 500x using the result and re-hashing it over and over again. This slows down the operation, so that people attempting brute-force hacks, or who compromise your entire user table, will face a substantial barrier to utilizing a rainbow table and determining simple matches. In your code, I'd suggest you write a simple function that does the hashing routine. As input it requires the username, the password, the salt, and a randomly generated number of hash operations to be repeated. Of course you need to generate and store all these in your user table, so this will require some modifications and some routines that will generate random numbers in a range, and random strings to use as salts. You then compare the stored password with this result and if == the user has authenticated. Do not store the password in the session.
×
×
  • 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.