Jump to content

JacobSeated

Members
  • Content Count

    17
  • Joined

  • Last visited

Community Reputation

1 Neutral

About JacobSeated

  • Rank
    Member

Profile Information

  • Gender
    Male
  1. On second look, this pre-configured box is not usable to me, since I need to learn to use Bitnami as well, and the paths are also non-standard, so I have no idea where to find the files I need to edit. An old fashioned LAMP install is just so much easier to work with for me. I wasted a lot of time trying to just get it to work with a domain name instead of the bare IP address. Guess that settles my doubts.. Will go for the latest version, with a manually installed Elasticsearch. Strange that I find this much easier than all this auto-installer stuff...
  2. Hallo people, this forum has been a help and inspiration before, so lets see about this one.. I am in the situation that I promised my boss to try and learn Magento, possibly with the aim to help out with development in the future. Now I just depleted my mental energy from trying to get the Elasticsearch Service, as offered by AWS, to work. I was unable to connect from my EC2 instance (even with the WAN IP approved in the security group). Then I noticed today that AWS has a pre-configured 2.3 Magento option for Lightsail — which is really tempting for me at this point — but that's without Elasticsearch. My understanding is that Elasticsearch will be required from now on, so the question is if I should just go ahead and install 2.4 manually on lightsail, with a localhost ES? The idea was to launch a Lightsail instance and then install Elasticsearch on it, either as an external service, or together with Apache and MySQL. My existing EC2 instance already has too much stuff running on it, and I also fear it has too low memory for all these services to run reliably without swapping. For now, I will just try their 2.3 setup, as I am really just interested in getting something to work before tomorrow.
  3. I own a website/blog where I write about different technical subjects, mainly web-development and coding. No reason to post it here, since I am not trying to advertise. Over the years I have observed some really weird and interesting things that people will do relating to my site. One time, someone took my entire website and placed it in an iframe. The site that did this was total spam. Never found out why or what they wished to accomplish by doing it. Luckily I have not had major problems with plagiarism yet, but I do have scrapers stealing my content and posting it together with spam on other sites. The exact purpose of this is unclear to me, since they mainly post gibberish, and it seems they gain nothing from doing it. What is strange is that some of the sites is using AdSense, and it seems they are not even banned for these activities. It does not seem like this has any negative impact on my rankings; only recently one of my articles, ranked on first page, got de-indexed; and I had to request re-indexing — after which it quickly returned to same spot as before it was de-indexed. Perhaps the strangest thing, and something that is still happening, is that one of my articles is getting blasted with HTTP requests from countless of different IP addresses, and this has probably been going on for more than a year now. Most of these are simple GET requests, and I can tell it is not legitimate traffic, since typically the same IP will be using a lot of different user agent strings, and occasionally it might even post a spam comment (POST request); I have now started to ban the most aggressive ones, since they have been making hundreds of requests to the same article, and it was starting to mess with my internal statistics. If I look up the IPs, then they will usually have been reported for malicious activity, so I am fine with blocking them. I just do not want to be manually blocking IPs, so maybe it would be better to install a server module to deal with it. I am just really curious about these activities, since some of it has been going on for so long, and it just seems completely pointless. Maybe someone here has found out what some of this is about? I also get a lot of spam comments, without any links in them, so it is also a mystery to me why someone would want to post all this junk on someone's website without anything to gain from it. Presumably it is some sort of attempt to influence search rankings indirectly, maybe by getting people's website de-indexed because of spam comments — but that is just pure speculation on my part.
  4. I used h1's in my section elements for a while a few years back, on my tutorial site, without noticing any negative effect on my traffic. I changed back to h2-h6+section when it was made known that some assistive tech did not support it yet, and also the document outline go messed up since browsers also did not support it. I still hope that it is implemented, but I guess I have no real use for it right now. Interesting you actually tried doing that and it resulted in a 400 error. I was wondering about how to test that.
  5. I think those SEO plugins tend to cause more confusion than they add value. I have personally never used them, and I do not care if some of my title tags are too long, duplicated, or if my descriptions are too short. If some of my descriptions are short, then it is probably intentionally, and I do not want notifications about it. Having said that, chances are that you can enter in: https://example.com./ With a "dot" in front of the slash, this is also a useful trick to circumvent certain cookie-walls on websites. I think very few websites seem to normalize such requests, since developers are often not aware of it. Afaik. Search engines will perceive it just the same — dot or no dot.. But, I still prefer to redirect such requests. I think requinix is correct. Even if a misbehaving client leaves out the path part in a HTTP request, a leading slash will, as a minimum, be "presumed" by the server. But, I am not sure about that, or if it is even possible to forge such a request. Normally, the client should always add a leading slash, since an empty path is not valid. See this: http://tools.ietf.org/html/rfc7230#section-5.3.1 I have also encountered SEO folks/software that erroneously claimed you could not use multiple h1 headings, needed to include keywords meta, and so on.. But that is another story... The same goes for <a href=""> links basically. It has absolutely no significance if we include the slash or leave it out on the bare domain name. Another configuration flaw that most websites seem to suffer from, is the fact that we can use non-existent URL parameters. I.e. ?something=blah; ideally, doing that should simply result in a 404 error — I do not think these SEO plugins will inform you about these niche cases. Regardless, Google is quite good at choosing the canonical URL, so I will not worry too much about it, unless I start having problems — start seeing the main pages de-indexed, and the bugged pages taking their place. Another thing to keep in mind is that we also need to whitelist certain parameters, such as ?fbclid, since we might accidentally block people from sharing links on Facebook, and other social media sites. Personally, I prefer leaving out trailing slashes on article pages and files, since they indicate directory or index rather than a page; but it really does not matter; IMHO, it is just ugly to see URLs like this: https://www.example.com/some-article-name/ https://www.example.com/robots.txt/
  6. Ahh, it seems PHP is using "**" instead of "^" for some reason. https://www.php.net/manual/en/language.operators.arithmetic.php Somehow that slipped past me. Thanks anyway though 🙂
  7. Hey, Strange issue here with basic math. It works on my calculator, but not in PHP. 1000*1.1^1 should result in 1100, but instead gives me 1101. I.e: echo 1000*1.1^1; // 1101 What am I missing? What is with the tiny inaccuracy?
  8. Thanks, this is much appreciated. It actually looks like you are right, and this is the default behavior. Maybe this is better documented here, at least for PHPMailer: https://packagist.org/packages/phpmailer/phpmailer Use statements also seem to work. It looks like the vendor/project part is what is listed in composer.json, in the "require" section. I wonder if there is a "standard" way to include this in my index.php file, so I do not have to write all those use statements? I read somewhere else that the vendor/composer/autoload_namespaces.php is supposed to update an array automatically, but the array in my file is just empty. Not sure if that has something to do with it? In any case, this is not much different than how I do things in vanilla PHP, so it does not bother me too much; except, I have to sometimes guess at the right framework/path, since it does not seem to be documented in some cases. I can see that some other packages still mention writing new someName(), without clarifying the part about namespaces (vendor/project).
  9. Hallo, I have a strange problem with a freshly installed composer project that is not loading the dependencies as the documentation states it should. I just made a new directory (www/site/test/), which has a index.php file, and I want to be able to use composer-installed dependencies from within the index.php file, inside the test folder; is this the wrong way to do it? Do I need to place my project root somewhere else for it to work? Dependencies are installed like this: composer require phpmailer/phpmailer For some strange reason, the autoloader is not loading the dependencies, and I simply get a class not found, without any explanation as to why it was not found. The thing is, I can get it to work by resorting to crazy hackery like: new PHPMailer\PHPMailer\PHPMailer() But the documentation clearly states that I should be able to do new PHPMailer() - hope this makes sense. This is what I have in my index.php: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // define('BASE_PATH', rtrim(preg_replace('#[/\\\\]{1}#', '/', realpath(dirname(__FILE__))), '/') . '/'); // require BASE_PATH . 'vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
  10. You do not have to redirect the user after submitting a form (handling a POST request). An easier, and often better, way to show the user whether the data was accepted would be to tell them on the submit location itself. You could also add a back button to allow the user to safely return to the previous page after reading the status message. I know this is probably just a basic example, but you should also remember to validate your POST fields.
  11. XMLHttpRequest may be old, but it is not going away anytime soon. The main problem I had was the asynchronous "callback" hell of JavaScript, especially coming from a PHP background. You can not easily return the result of a HTTP request to the calling script. Instead, you have to use a callback function to deal with the response data. Afaik, fetch makes this easier, since it can wait for a "promise" to be fulfilled (a server responding). I Have not really used it much, but now that I got XMLHttpRequest working with callbacks, I am not planning on changing it. Probably should look into it.
  12. You will probably not get a complete answer on a forum, as this is a fairly large and complex topic. People are writing entire books on OOP best practices and design patterns, and many of us are still learning about these things while trying to develop and maintain existing projects. I think you will find that Dependency Injection is hugely beneficial, even just on personal projects, at least this is my experience after I started using it. At first it is not very obvious, but it should become more obvious as you continue using it. The thing is with OOP, it kinda forces you to consider the overall design of your application, and if you also follow DRY (Don't Repeat Yourself), then you will almost automatically force yourself into thinking about the design patterns. Do not expect perfection from the start. It is hard avoid writing ineffective code while learning, but don't stop thinking about your solutions and best practices. You can always re-organize things as you learn. What I personally found, is that inheritance (extends) are bad, because it couples your code and makes it harder to re-use. Instead, I am now using DI almost exclusively. Chances are that you will regret using "extends" because of following DRY, and when later realizing that you could re-use that code somewhere else. If you want to re-use a class that extends another class, then you are forced to instantiate the whole object. Not only is that ineffective, it is also not always possible, since some of that code might connect to a database or API which you do not need.. Another thing that is bad, which you pointed out yourself, is instantiating dependencies (classes) inside the class that relies on them. I used to do this for a very long time, thinking it made it easy to instantiate the classes without having to worry about instantiating the dependencies from my composition root. This is true, to a certain extent. But, it also creates a hard-coupling which makes it impractical to maintain and re-use the code as your project grows—even within your own personal project. So, no usage of new inside other classes, unless you use it in a factory class 🙂 When your dependencies themselves have dependencies, it will be impractical to instantiate them inside the constructors of classes, since you will have to update every single class if one of the dependencies changes its dependencies. Finally, it also takes more mental energy and time to assemble an object if you need to run tests on it. If you must have code duplication (usually a code-smell), then you can also consider using traits. A trait is basically a copy/paste of code that is shared by multiple classes. Now we are just discussing the code aspect, but your file system structure is just as important in keeping things simple. Hope this helps, and please note I am no expert, I am still learning about all this myself.
  13. Also, escaping in and out of HTML like this is kinda old fashioned. These days you may want to keep your HTML separate from PHP. Personally I limit myself to placing only variables in my HTML. So, no conditional logic in the HTML itself, which makes it very clean and easy to maintain. If using heredoc, you can use curly brackets around variables. I.e.: $tpl_content = array('title' => 'test', 'article_body' => 'hallo world'); $template = <<<_TEMPLATE_ <!doctype html> <html> <head> <title>{$tpl_content['title']}</title> </head> <body> <article> <header> <h1>{$tpl_content['title']}</h1> </header> {$tpl_content['article_body']} </article> </body> </html> _TEMPLATE_; // End of Template I wish I had learned this early on myself, as it could have saved me many hours of spaghetti hell.
  14. Wordpress has its own file handler (wp_filesystem), which is the official way to deal with the file system in WP. However, WP developers will often recommend you use the database to store things – probably because they feel it is more secure. But, the file system is sometimes a better choice. Many WP developers will not like it if you use bare file- functions such as file_get_contents in PHP. I personally do not mind. In fact, I would like to warn against wp_filesystem, since it does not seem to handle concurrency and file locking, which means data can be lost if two users tries to access a file at the same time. Reading is typically not a problem, but can be if someone happen to write to a file at the same time as a file-read. wp_filesystem also introduce other problems, such as prompting users for credentials to upload files via FTP if they do not have write permissions on the server. That's not a desired behavior, so you should first check for write permissions, and then present users with an error if permissions are insufficient. Instead of using functions.php, consider making a plugin or using the Code Snippets plugin, as it will be easier to maintain.
  15. Try changing this: $query = ("SELECT * from videos"); to this: $query = 'SELECT * from videos'; Also, you should really avoid escaping in and out "<?php" and "?>" of PHP like this. Instead, keep your HTML in separate template files, and load them via require. This is also known as "views", but I prefer to call it "templates", since that makes more logical sense to me.
×
×
  • 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.