Best way to learn php?

Forum
Last Post
Threads / Messages

grandcorsair

Member
Member
Joined
May 22, 2024
Messages
12
Points
3
Mysidian Dollar
98
I really want to learn but all the videos and sites are intimidating. How did you learn and what would you recommend?
 
Well, I don't know if I can help the "intimidating" part, but I might be able to help with learning from scratch, and starting from square one and all that.
I always start a new coding language with W3Schools - they have a tutorial to teach you syntax, and have a reference for functions, operators, etc. https://www.w3schools.com/php/default.asp
If you're trying to understand how a function works, you can use this sandbox: https://onlinephp.io/
As you get into learning how to script your own stuff, PHP.net's documentation is gonna be your best friend. You can search functions up to find out how they work, what parameters they use, what return values to expect, etc. You can add PHP.net's search to your browser's search bar, too. https://www.php.net/manual/en/
I haven't looked too much into PHP: The Right Way, but it seems to have a long list of organized links to look at, emphasizing organized, structured, and standardized code (along with the basics of running a website on PHP): https://phptherightway.com/

PHP is a general-use scripting language, but in our case is probably gonna be used for web development. The Mozilla doc for "What is a web server?" defines what a dynamic web server is, what you'll be making with PHP. An example of a static web server would be something like Neocities: it only uses front-end languages like HTML, CSS, and JS.
Actually, as a really weirdly specific example, I built this pet site mockup page with HTML/CSS only on my Neocities... If you're building a dynamic website, you could actually interact with the links and images on there, and it would replace filler words like "username"!

SQL, MySQL, and MariaDB
If you're learning to set up a website with PHP, you'll invariably need to know the SQL language and how to use a MySQL database. W3Schools has a tutorial on SQL, including MySQL functions. MariaDB also has a beginner's articles section.

You should definitely learn basic SQL functions/syntax, but honestly, when it comes to MySQL/MariaDB, you'll probably be using an interface like phpMyAdmin, which automates the MySQL and MariaDB functions. Personally, any time I run into confusion with phpMyAdmin, there will be a "?" icon to click and troubleshoot the issue and/or figure out what to type into the command line, or I can read the phpMyAdmin FAQ to do something similar. XD

Mysidia 1.3.6 interacts with the MySQL database based on its Resource/Core/Database.php script, using this format:
PHP:
$mysidia = Registry::get("mysidia");
$mysidia->db->insert("table_name", ["column" => "insertThisValue"]);
$mysidia->db->select("table_name", ["column_to_select"], "column = 'mustBeThisValue' AND column2 = 'alsoMustBeThisValue'");
$mysidia->db->delete("table_name", "column = 'mustBeThisValue'");
The column = 'mustBeThisValue' format is the WHERE clause of the SQL statement.

Actually setting up your own full website with PHP...
Over time, lots of open-source web frameworks have been created to do the heavy lifting of basic functions your site will need to use frequently. For example, user authentication: a user logs in and has a username, password, and profile. It also needs to communicate with the SQL database.

Mysidia has its own web framework that uses the model-view-controller and model-view-viewmodel patterns. When you read through Mysidia 1.3.6's Resource/Core files like Database.php, AppController.php, FrontController.php, Frame.php, View.php, and ViewModel.php, etc., these give you an idea of how the framework works.

Other popular open-source PHP frameworks are Laravel, CakePHP, and CodeIgniter. If you want to understand how other functioning framework looks, or just try making your own web app, you can read their source code and documentation. (But DANG Laravel, WHY are you so huge?!?!)
Mysidia doesn't natively support AJAX, for example, so it can be nice to cross-reference.
Recently, I've been learning to use Slim, cuz like the name says, the source code is smaller and easier to digest.

Testing huge libraries, and not screwing up your website :p
Mysidia 1.3.6 uses Smarty Template 3.1.30 and HTMLPurifier 4.13.0. Needless to say, installing well-known, well-tested open-source code to your project where it can save you a lot of time is smart! But sometimes compatibility can be a headache and ruin your whole project... And something like the OnlinePHP sandbox can't test all those libraries at once.

You can host your own webserver using XAMPP, which is Apache/MariaDB/PHP/Perl, or just "Apache". It runs on your computer using the web address "localhost", and the only size/memory limitations are set by your computer running it.
I've also had luck with InfinityFree free hosting, I've been running a test server on there with no hangups.

Web security concerns
Your site is probably up and running by now, but you shouldn't launch it 'til you're sure it's safe from security vulnerabilities! At the very least, be aware of some of the most common vulnerabilities. The Open Worldwide Application Security Project (OWASP) is your friend when it comes to this: https://owasp.org/
OWASP Top Ten: https://cheatsheetseries.owasp.org/IndexTopTen.html
Cross-site scripting, SQL injection, HTML headers, cryptographic storage, and authentication are very relevant pages.

Your site should also be on the latest version of PHP, since it comes with important security updates!
The history of PHP is confusing, but the most secure password storage method is now universally using the PHP 5+ built-in functions password_hash(), password_needs_rehash(), and password_verify(). It will default to using the most cryptographically secure algorithm for encryption unless otherwise specified, which is currently bcrypt.
On a similar note, mt_rand() used to be more randomized than rand(), but ever since PHP 7.1.0, they are the same function. rand() is not, however, cryptographically secure.

Conclusion
And... that should be enough to start a site with PHP!
When it comes to Mysidia itself, reading the source code and tweaking pre-existing script is how you get acquainted with it, and trying to make mods.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,297
Messages
33,199
Members
1,610
Latest member
qwerty
BETA

Latest Threads

Top