DIGITAL ELECTRONICS AND INFORMATION TECHNOLOGY

INTRODUCTION TO PHP LANGUAGE

INTERNET AND HTTP PROTOCOL Before talking about the PHP language, it is good to make some premises on the web. We can consider the Internet as a series of interconnected devices. Generally these devices on the internet are called hosts or peripheral systems. Hosts are connected to each other via a series of links (wi-fi, fiber) and routers. In order for hosts to communicate properly, it is necessary to have rules for exchanging data. These rules are called protocols. When we open a browser and enter an address to visit a website, technically a communication has taken place between [...]

By |2022-07-15T09:44:50+02:0015 July 2022|0 Comments

FIRST STEPS IN PHP

FIRST PHP PROGRAM Let's start by deleting the contents of the htdocs folder located under the path C:\xampp\htdocs. The PHP web server when we connect with the browser at http://localhost or http://127.0.0.1 is actually accessing the htdocs folder. Once the content has been deleted, we create a corsi folder inside htdocs and nest a php folder. Now let's open V.S Code and connect the php folder. We are now ready to write our first PHP program. We create a file and call it index.php, the name index is not random; in fact, the Apache web server will automatically search [...]

By |2022-10-27T20:45:10+02:0031 July 2022|0 Comments

NUMERIC TYPES IN PHP

NUMBERS IN PHP In PHP, numbers are divided into integers and floats (floating point), we do not have to worry about how to represent a number, we simply assign it to a variable, then PHP will decide whether the number will be an integer or a float. PHP provides us with several functions to check numbers, such as whether a certain variable contains a number or not, like is_numeric(value). In addition to the is_numeric(value ) function we have functions that check whether a type is an integer or a float, is_int(value) and [...]

By |2022-10-27T20:46:56+02:0010 August 2022|0 Comments

STRINGS IN PHP

STRINGS IN PHP Strings in PHP are sequences of bytes and are used to represent text. We can assign any string to a variable, the limit is given only by the amount of memory available, can be enclosed in single or double quotes, there are differences e.g. with single quotes no parsing of variables is done, also con double superscripts escape sequences are recognized. HEREDOC AND NOWDOC NOWDOC does not parse variables; otherwise it behaves like HEREDOC. FUNCTIONS ON CODE STRINGS DEEPENING Strings [...]

By |2024-08-17T03:22:59+02:0011 August 2022|0 Comments

ARRAY IN PHP

BOOLEANS Before discussing Arrays let's do a brief review of Booleans. The Boolean type is a simple but important data type. They allow us to perform operations or not based on the Boolean value. INTRODUCTION TO ARRAYS So far we have analyzed simple or primitive data types. In PHP we can define compound values through arrays. ARRAY ORDERED $alumni = ['Michele','Silvia','Luca'];It takes the name of sorted or numbered array because each element of the array is associated with a numeric index starting with 0. SORTED ARRAY CODE ADD AND REMOVE CODE ELEMENTS [...]

By |2024-08-22T09:41:24+02:0014 August 2022|0 Comments

THE SUPERGLOBAL ARRAY $_GET

SUPERGLOBAL ARRAYS SCOPE When we define a script the main scope is the global scope. In addition to the global scope there is a local scope, that is, the one within functions. Communication between global scope and local scope is through function parameters, we pass a value to the function from the global scope, and the function can return a value to the global scope. The following code explains these concepts better. SUPERGLOBAL ARRAYS BRIEF INTRODUCTION $GLOBALS It is explained by the following code. $_SERVER Contains information such as headers, paths, locations in the script [...]

By |2024-08-23T11:03:06+02:0018 August 2022|0 Comments

SUPERGLOBAL ARRAY $_POST

THE SUPERGLOBAL ARRAY $_POST With the POST method, the values are not passed to the URL. If we open the developer tools (F12) then network tab redo the request, click on the PHP file we notice that the data is passed through the Payload. In the Headers tab we have the request and response, which is the information that client and server have exchanged. With the POST method, the values are not passed to the URL. One thing never to do is to trust what the user types into the text boxes, it can in fact [...]

By |2024-08-24T07:26:53+02:0019 August 2022|0 Comments

THE SUPERGLOBAL ARRAYS $_SERVER AND $_FILES

THE SUPERGLOBAL ARRAY $_SERVER A very important superglobal array is $_SERVER. It contains information about the request, the server itself, headers, paths, and the script. This is the information extracted via a var_dump($_SERVER). We have information about the script, SCRIPT_NAME, about the QUERY_STRING in this case empty, we have the method of the request REQUEST_METHOD in our case I did a GET through HTTP/1.1. There is the full path to the PHP script SCRIPT_FILENAME, the communication SERVER_PORT happened on port 80 as the default HTTP protocol uses this port, if we use HTTPS [...]

By |2024-08-25T08:51:20+02:0022 August 2022|0 Comments

THE SUPERGLOBAL ARRAY $_SESSION

COOKIES AND SESSIONS The HTTP protocol is stateless, that is, it does not maintain state. We create a form by which we ask the user whether they prefer light or dark colors. The fact is that if the user enters a preference and navigates to another page in the application we lose that information, but also if we make a new request to the same page the information is lost. Imagine an authentication system in which the user enters username and password, without a state-preserving mechanism, we would be prompted for username and password at each new page. MAINTAIN [...]

By |2024-08-28T16:32:27+02:0025 August 2022|0 Comments

THE SUPERGLOBAL ARRAY $_COOKIE

THE ARRAY $_COOKIE The preservation of the state as already mentioned can be done on the server with session files but also on the client, in this case we talk about cookies. If we want to delegate to the client the storage of data however not sensitive, the thing we need to do is send this information to the client, and we do that through the response headers. As we know when we make a request we make it through a browser within the address bar by specifying a URL. THE SETCOOKIE() FUNCTION Through this request other information travels [...]

By |2024-08-28T21:34:29+02:0027 August 2022|0 Comments
Go to Top