Tutorial for $_SERVER in Super Global Variables

What is $_SERVER?

It’s a super global variable in PHP that keeps track of headers, paths, and script locations. Some of these components are used to obtain data from the $_SERVER super global variables.

Server IP (PHP $_SERVER variables) | Drupal.org

Example:-

Output:-

To retrieve some information, we used the $_SERVER components in the code above. Using the ‘PHP SELF’ element, we retrieve the current file name that is being worked on. Then, using the ‘SERVER NAME’ attribute, we retrieve the current server name. Then we use ‘HTTP HOST’ to retrieve the host name.

The following table lists the most important elements that can go inside $_SERVER:

Element/CodeDescription
$_SERVER[‘PHP_SELF’]Returns the filename of the currently executing script
$_SERVER[‘GATEWAY_INTERFACE’]Returns the version of the Common Gateway Interface (CGI) the server is using
$_SERVER[‘SERVER_ADDR’]Returns the IP address of the host server
$_SERVER[‘SERVER_NAME’]Returns the name of the host server (such as www.w3schools.com)
$_SERVER[‘SERVER_SOFTWARE’]Returns the server identification string (such as Apache/2.2.24)
$_SERVER[‘SERVER_PROTOCOL’]Returns the name and revision of the information protocol (such as HTTP/1.1)
$_SERVER[‘REQUEST_METHOD’]Returns the request method used to access the page (such as POST)
$_SERVER[‘REQUEST_TIME’]Returns the timestamp of the start of the request (such as 1377687496)
$_SERVER[‘QUERY_STRING’]Returns the query string if the page is accessed via a query string
$_SERVER[‘HTTP_ACCEPT’]Returns the Accept header from the current request
$_SERVER[‘HTTP_ACCEPT_CHARSET’]Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1)
$_SERVER[‘HTTP_HOST’]Returns the Host header from the current request
$_SERVER[‘HTTP_REFERER’]Returns the complete URL of the current page (not reliable because not all user-agents support it)
$_SERVER[‘HTTPS’]Is the script queried through a secure HTTP protocol
$_SERVER[‘REMOTE_ADDR’]Returns the IP address from where the user is viewing the current page
$_SERVER[‘REMOTE_HOST’]Returns the Host name from where the user is viewing the current page
$_SERVER[‘REMOTE_PORT’]Returns the port being used on the user’s machine to communicate with the web server
$_SERVER[‘SCRIPT_FILENAME’]Returns the absolute pathname of the currently executing script
$_SERVER[‘SERVER_ADMIN’]Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host) (such as someone@w3schools.com)
$_SERVER[‘SERVER_PORT’]Returns the port on the server machine being used by the web server for communication (such as 80)
$_SERVER[‘SERVER_SIGNATURE’]Returns the server version and virtual host name which are added to server-generated pages
$_SERVER[‘PATH_TRANSLATED’]Returns the file system based path to the current script
$_SERVER[‘SCRIPT_NAME’]Returns the path of the current script
$_SERVER[‘SCRIPT_URI’]Returns the URI of the current page
Tagged : / / / / / / / / / /

Tutorial for $GLOBALS in Super Global Variables

What is $GLOBALS?

$GLOBALS is a super global variable that may be accessed from anywhere in the PHP script. All global variables are stored in the array $GLOBALS[], where index is the global variable name that may be retrieved.

All global variables are stored in an array named $GLOBALS[index] in PHP. The variable’s name is stored in the index.

Global Variables - Superglobals Several predefined variables in PHP are  "superglobals", which means that they are always accessible, regardless of  scope. - ppt download

The example below shows how to use the super global variable $GLOBALS:

Example:-

Output:-

Two global variables, $x and $y, are declared in the above code and are given a value. Then, in the GLOBAL array, a function multiplication() is written to multiply the values of $x and $y and store the result in another variable $z.

Tagged : / / / / / / / / / /

Tutorial for Super Global Variables in PHP

What is Super Global Variables in PHP?

These are PHP array variables with specific definitions that make it simple to retrieve information about a request or its context. The super global variables may be found all across your script. These variables can be accessible from any function, class, or file without the need to do any further steps, such as defining a global variable. They are mostly employed in applications to save and retrieve data from one page to the next.

PHP Variables and scopes

The following are the PHP superglobal variables:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
PHP 5 Global Variables - Superglobals - MEGATEK ICT ACADEMY
Tagged : / / / / / / /

Introduction to Laravel

What is Laravel?

Laravel is a web framework built on PHP. That is, the code that has been done has been coded in PHP. You can use it to create High-End Web Applications, you can create the very best web application using Laravel in it. Laravel follows the architectural pattern of MVC (Model View Controller). Laravel was created by Taylor Otwell.

Advantages of Laravel?

  • Open Source
  • Collection of tools
  • Save Time
  • Improve Productiity
  • Robust and Easy
  • Security of the Application
  • Authentication
  • Routing
  • Templating

Requirements for Learning Laravel

Do You Know

  • HTML
  • CSS
  • JavaScript
  • SQL
  • PHP OOP
  • MVC
  • Composer

Laravel Requirements

  • PHP 7.2.0 or Higher
  • XAMPP (Apache + MariaDB + PHP + Perl)
  • WAMP/LAMP/MAMP
  • Composer
  • Text/Code Editor- Notepad++, VS Code, ATOM, Brackets
  • Web Browser- Google Chrome, Mozilla Firefox, Edge
Tagged : / / / / /

Complete Referance of Blade in Laravel

What is Blade?

Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates.

Blade template files use the .blade.php file extension and are typically stored in the resources/views directory

Blade Template

Displaying Data – You may display data that is passed to your Blade views by wrapping the variable in curly braces.

Blade’s {{ }} echo statements are automatically sent through PHP’s htmlspecialchars function to prevent XSS attacks.

Example:- {{$name}}

Calling Function – You may also echo the results of any PHP function by wrapping the function name in curly braces.

Example:- {{ time( ) }}

Note – You can put any PHP code you wish inside of a Blade echo statement.

Comment

Blade also allows you to define comments in your views. However, unlike HTML comments, Blade comments are not included in the HTML returned by your application.

{{– This comment will not be present in the rendered HTML –}}

Conditional Directives

If Directive

If.. Else.. Directive

If… elseif… else… Directive

Empty Directive

Authentication Directives

Auth Directive

Guest Directive

Tagged : /

Tutorial for Method Attribute in html for php

What is Method Attribute?

The HTTP method used to transfer data while submitting the form is specified using the HTML form> method Attribute. The HTTP methods GET and POST are the two types of HTTP methods. With the form> element, the method attribute can be used.

Html 4

Attribute Values:

  • GET:- When using the GET method, the form data are shown in the address bar of the new browser tab once the form is submitted. It is restricted to around 3000 characters in length. It’s just good for non-sensitive data, not for sensitive data.
  • POST:– After submitting a form with the post method, the form values will not appear in the address bar of the new browser tab, as they did with the GET method. The form data is appended to the body of the HTTP request. It is unrestricted in terms of size. The outcome of this technique is not bookmarkable.

Which are the Supported Tags:

<form>

Syntax:

<form method="get|post">

Example 1:– This example illustrates the use of GET method attribute.

Output:-

Example 2: This example illustrates the use of the POST method attribute. This method sends the form-data as an HTTP post-transaction. 

Output:-

Tagged : / / / / / / / / /

Tutorial for Enctype Attribute in html for php

What is  Enctype Attribute?

This Attribute indicates that data in the form should be encoded before being submitted to the server. This sort of property can only be utilised if the method is set to “POST.”

Syntax:

<form enctype = "value">

Element:– The enctype property is only applicable to the form> element.

Attribute Value: There are three values for this characteristic, which are given below:

  • application/x-www-form-urlencoded:– It’s the default setting. Before sending the data to the server, it encodes all of the characters. Spaces are converted to + symbols, while special characters are converted to their hex value.
  • multipart/form-data:– There is no character encoded in this value.
  • text/plain:– This value converts spaces to + symbols, however it does not convert special characters.

Example:

Output:-

Supported Browsers: The browser supported by enctype Attribute are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Apple Safari

Tagged : / / / / / / /

Tutorial for Action Attribute in html used in php

What is Action Attribute?

It contains a URL that defines where to send the data after submitting the form.

It specifies the physical address of the server to which the user data should be redirected at the click of the submit button.

The action property specifies what should happen when the form is submitted.

When a user presses the submit button, the form data is usually transferred to a server file.

The form data is delivered to a file called “action page.php” in the example below. This file includes a server-side script for dealing with form data:

Example:-

Output:-

Tagged : / / / / / /

Complete Referance of Controller in Laravel

Controllers

Controllers can group related request handling logic into a single class. Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes.

Controllers are stored in the app/Http/Controllers directory.
Controller extends the base Controller class included with Laravel.

Defining Controller Class

Run Command:- php artisan make:controller

Example:- php artisan make:controller AboutController

Path:- app/Http/Controllers/AboutController.php

Creating Route for Controller Class

Path of Controller :- app/Http/Controllers/AboutController.php

Path of Route:- routes/web.php

Syntax:- Route::get(‘uri’, [ControllerName::class, ‘method_name’]);

Passing Data from Controller to View

Path of Controller :- app/Http/Controllers/AboutController.php

Path of Route:- routes/web.php

Path of View:- resources/views/aboutme.blade.php

Multiple Methods inside Controller

Path of Controller :- app/Http/ControllersAboutController.php

Path of Route:- routes/web.php

Path of aboutme blade file:- resources/views/aboutme.blade.php

Path of aboutyou blade file:- resources/views/aboutyou.blade.php

Single Action Controller

If you would like to define a controller that only handles a single action, you may place a single __invoke method on the controller.

Run Command:- php artisan make:controller ShowAbout –invokable

Path of Controller :- app/Http/Controllers/ShowAboutController.php

Path of Route:- routes/web.php

Path of aboutme blade file:- resources/views/aboutme.blade.php

Tagged : /

Tutorial for Type Attribute in php

What is Type Attribute?

It indicates the type of input element. It’s an empty tag. The default value is text.

Example:-

<input>

<input type=“text”>
  • Text – It defines a single-line text field.
<input type=“text”>
  • Password – A password field is like text field, the difference being that this control hides each typed character by displaying an asterisk(*) or bullets(●) instead of the character itself.
<input type=“password”>
  • Button – This is used to add a button on a web form to activate a script when an user click the button.
<input type=“button”>
  • Email – This field is used to add an email address or a list of email address to a form, where type=“email” is a value for the input type. The input format should be an email like example@gmail.com else it will prompt an error.
<input type=“email”>
  • Check Box – A check box is a small box, which when selected includes a checkmark. It is used to allow the user to select one or more than one of the options available on a web page. An User can select or clear the check box by clicking it
<input type=“checkbox”>
  • Radio Button – A radio button is used to create a series of options of which only one can be selected. It is displayed as a circle which when selected, displays a dot in the middle.
<input type=“radio”>
  • URL – The URL field is used to enter only the web addresses, in their correct format. If the URL is not entered in the correct format then the URL field validates the text field to enter web address.
<input type=“url”> 
  • Autofocus – helps in keeping the focus of mouse pointer on the input field.
  • Pattern – defines the regular expression of the text that should be entered in the text field.
  • Search Box – This is used to add a search box to a form.
<input type=“search”>
  • Tel – The tel type represents a one-line plain-text edit for entering a telephone number.
<input type=“tel”>
  • Range – Range input represents the input of limited range numerical values.
<input type=“range”>
  • Number – Number is used to validate the textbox only if the value within the field is a numerical value.
<input type=“number”>
  • File – This is used to upload a file on a web page. You also need to set the enctype=“multipart/form-data”
<input type=“file”>
  • Image – It represents either an image from which the UA enables a user to interactively select a pair of coordinates and submit the form, or alternatively a button from which the user can submit the form.
<input type=“image”>
  • Hidden – A hidden control stores the data that is not visible to the user on a web page. This control is used to submit some information, which can not be edited by user.
<input type=“hidden”>
  • Submit – A submit button is used to transfer form data to the URL specified in the <form action> tag.
<input type=“submit”>
  • Reset Button – A reset button helps user to clear all the data that they have entered in the text fields.
<input type=“reset”>

  • Date – This is used for input fields that should contain a date.
<input type=“date”>
  • Time – It allows the user to select a time.
<input type=“time”>
  • DateTime – It allows the user to select  date and time.
<input type=“datetime”>
  • Datetime-local – It allows the user to select a date and time.
<input type=“datetime-local”>
  • Month – It allows the user to select a month and year.
<input type=“month”>
  • Week – It allows the user to select a week and year.
<input type=“week”>
  • Color – It is used for input fields that should contain a color.
<input type=“color”>
Tagged : / / / / / /