1echo $_SERVER['PHP_SELF'];
2echo "<br>";
3echo $_SERVER['SERVER_NAME'];
4echo "<br>";
5echo $_SERVER['HTTP_HOST'];
6echo "<br>";
7// echo $_SERVER['HTTP_REFERER'];
8echo "<br>";
9echo $_SERVER['HTTP_USER_AGENT'];
10echo "<br>";
11echo $_SERVER['SCRIPT_NAME'];
1<?php
2echo $_SERVER['PHP_SELF'];
3echo "<br>";
4echo $_SERVER['SERVER_NAME'];
5echo "<br>";
6echo $_SERVER['HTTP_HOST'];
7echo "<br>";
8echo $_SERVER['HTTP_REFERER'];
9echo "<br>";
10echo $_SERVER['HTTP_USER_AGENT'];
11echo "<br>";
12echo $_SERVER['SCRIPT_NAME'];
13?>
1<?php
2 // PHP $_SERVER['...']; method
3
4 // PHP file name
5 echo 'PHP file name: '.$_SERVER['PHP_SELF'].'<br>';
6 // Server name
7 echo 'Server name: '.$_SERVER['SERVER_NAME'].'<br>';
8 // HTTP host
9 echo 'HTTP host: '.$_SERVER['HTTP_HOST'].'<br>';
10 // Refering link
11 echo 'Refering link: '.$_SERVER['HTTP_REFERER'].'<br>';
12 // User agent
13 echo 'User agent: '.$_SERVER['HTTP_USER_AGENT'].'<br>';
14 // Script name
15 echo 'Script name: '.$_SERVER['SCRIPT_NAME'];
16
17 // The rest is optional
18
19 if($_SERVER['PHP_SELF']=='/filename.php'){
20 //If there is no folder
21 echo 'No folder'.$_SERVER['PHP_SELF'];
22 } else{
23 // Echo the name of the folder containing the PHP file
24 echo 'PHP file name: '.$_SERVER['PHP_SELF'];
25 }
26
27 // The same if statements can be used for the script name
28
29 if($_SERVER['SCRIPT_NAME']=='/filename.php'){
30 // If there is no folder
31 echo 'No folder'.$_SERVER['SCRIPT_NAME'];
32 } else{
33 // Echo the name of the folder containing the PHP file
34 echo 'PHP file name: '.$_SERVER['SCRIPT_NAME'];
35 }
36
37 echo '<a href="repl.it/@CoolWebDev">More from me...</a>';
38
39 // I hope you found this helpful!
40?>
1
2<?php
3/*
4Sometimes you will find that your website will not get the correct user IP after adding CDN, then this function will help you
5*/
6function real_ip()
7{
8 $ip = $_SERVER['REMOTE_ADDR'];
9 if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
10 foreach ($matches[0] AS $xip) {
11 if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
12 $ip = $xip;
13 break;
14 }
15 }
16 } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
17 $ip = $_SERVER['HTTP_CLIENT_IP'];
18 } elseif (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
19 $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
20 } elseif (isset($_SERVER['HTTP_X_REAL_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_REAL_IP'])) {
21 $ip = $_SERVER['HTTP_X_REAL_IP'];
22 }
23 return $ip;
24
25}
26echo real_ip();
27
28?>
29
30