Php: get keywords from search engine referer url

Introduction

PHP scripts are used to retrieve the URL of a web page on the website server. There are multiple approaches to lớn achieve this task. In this article, you will explore three approaches to get full URL in PHP. You will use the $_SERVER superglobal array variable and its various elements to retrieve different parts of the URL. After that, those parts will be appended together to get full URL in PHP. In this way, you will get the full path of the current website page.Bạn vẫn xem: Php get full url code example

The necessary superglobal variables such as $_SERVER, $_SERVER, $_SERVER are used khổng lồ get full URL in PHP. The variable HTTPS can easily retrieve the protocol in the URL of a webpage. If it returns a value “on”, then the protocol is HTTPS. And if the value returned is not equal lớn “on” then the protocol in the URL of the webpage is HTTP.

Bạn đang xem: Php: get keywords from search engine referer url

What Are Superglobals?

PHP provides you with certain specific pre-defined variables. These variables help you retrieve the data and information about a request or its context. As their name suggests, superglobal variables have a superglobal scope. They are accessible throughout your PHP script. You can access these variables by using any function, file, or class without doing much work to create or declare a new variable inside your function or class. The primary purpose that these variables serve is to hold as well as retrieve the data from a page of an application. 

Here is a menu of superglobals that are provided by PHP:

$GLOBALS:

 It is a type of superglobal variable that helps to access all the global variables throughout the PHP script và comes in useful when trying to get full URL in PHP. PHP provides an array $GLOBALS lớn hold the references of all the global variables as array elements. The index of the array represents the names of the global variables.


*

 

In the program stated above, two global variables, var1 and var2 are initialized with 2 integer values. The function getSum() stores the result of the addition of these two global variables in a GLOBAL array.

Xem thêm: Pneumococcal Là Gì


*

$_SERVER:

Server is a PHP superglobal that is defined as an array that contains the data about paths, headers, script location, etc. The web hệ thống itself makes these entries within the array. Using this to lớn get full URL in PHP however depends on your server, as not every vps provides that information. Some may skip them, whereas others may provide some extra data. The data provided by your web server is sometimes used to lớn retrieve the data from a $_SERVER superglobal variable

The following program illustrates the $_SERVER variable in PHP.

";

// print the name of the server

echo $_SERVER;

echo "";

// print the name of the host

echo $_SERVER;

echo "";

// print the complete URL of the current page

echo $_SERVER;

echo "";

// print the user agent string

echo $_SERVER;

echo "";

// print the path of the script

echo $_SERVER;

?>


*

 

In the program depicted above, various $_SERVER elements are used to lớn retrieve information about the web page on the server. For example, $_SERVER is used lớn get the name of the current file, $_SERVER is used lớn get the name of the server, $_SERVER returns the name of the host, & so on.

$_REQUEST:

Request is another superglobal whose function is to lớn collect & store the data whenever you submit an HTML form. This is one of the more common methods khổng lồ get full URL in PHP. The $_REQUEST array stores the information about $_GET, $_POST và $_COOKIE by default. However, $_REQUEST is not in much use as the same purpose can be fulfilled by $_GET và $_POST.