- PHP Intelephense
- Live Server
- PHP Server
Access your localhost by typing localhost into your webbrowser. You can access your VS code project by typing localhost/[enter your projects folder name]. Add the Live Server extension on Google chrome if you want your VS Code updates to happen live.
Type "!" and press tab for boiler plate code.All PHP code is contained within . You can also write html, css and javascript alongside PHP.
A variable is a reusable container that holds dataincludng strings, integers, floats and booleans
$_GET and $_POST are two special php variables used to collect data from an HTML form i.e.
.$_GET means data is appended to the url.
$_POST means the data is packaged inside the body of the HTTP request.
Sanitizing and validating user input is always a good idea in case the rare user decides to input malicious content.
You can sanitize your code with functions like:
You can validate your code with tests like:
More details on this can be found at 2:44:30
To print values from cookies, do as follows:
setCookie(key, value, time() + time til expiry, path);
foreach($_COOKIE as $key => $value){
echo"{$key} = {value}
";
}
A session is a super global varable (SGB) used to store information on a user to be used across multiple pages. A user is assigned a session-id ex. login credentials. Any login websites i.e. Facebook use sessions.
Place session_start(); in a php tag before the rest of your code.
You can then create named value pairs within our SGB by using i.e. $_SESSION["username"] = "Buckle23" then echo $_SESSION["username"];
The server SGB contains headers, paths and script locations. The entries in this array are created by the web server. It shows nearly everything you need to know about the current web page env.
To access the server SGB type $_SERVER["PHP_SELF"];
Password hasing is transforming sensitive data (password) into letters, numbers, and/or symbols via a mathematical process (similar to encryption). It hides the original data from 3rd parties.
Use the password_has($password, PASSWORD_DEFAULT); function.
There's two popular ways to connect PHP to MySQL:
- MySQLi Extension
- PDO (PHP Data Objects) - many developers use PDO's because they can connect to 12 or more database types.
For the purpose of this tutorial we will just be using the MySQLi extension
Go to http://localhost/phpmyadmin/
This url allows to you to configure your database. You can make SQL queries, monitor the status, export/import data, etc.
Create a db for this tutorial called tutorialdb
Go to the User Accounts Overview at http://localhost/phpmyadmin/index.php?route=/server/privileges&viewing_mode=server
Create a file called database.php
You should be able to view the output at http://localhost/tutorial-website/database.php