Showing posts with label PHP Beginner. Show all posts
Showing posts with label PHP Beginner. Show all posts

Wednesday, 20 April 2022

How to generate random number?

Using following code we can create random number. Than can be use Order number, unique id or like something that.

<?php 

//Unique or Random number Generate
//$today = date("Ymd");
$today = date("dmY");
$random = strtoupper(substr(uniqid(sha1(time())),0,6));
echo $order_no = $today . $random;

?>


For more Interesting, Useful Article & codes visit IT New Code.

How to get IP Address of System?

Run following PHP code for get IP Address.




<html>
<head>
 <title>What is my IP address?</title>
</head>
<body>
<?php
  $ipaddress = '';
    if ($_SERVER['HTTP_CLIENT_IP']){
        echo "1-Ip is:".$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    }
    else if($_SERVER['HTTP_X_FORWARDED_FOR']){
        echo "2-Ip is:".$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
    else if($_SERVER['HTTP_X_FORWARDED']){
        echo "3-Ip is:".$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
}     else if($_SERVER['HTTP_FORWARDED_FOR']){
        echo "4-Ip is:".$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
}     else if($_SERVER['HTTP_FORWARDED']){
        echo "5-Ip is:".$ipaddress = $_SERVER['HTTP_FORWARDED'];
}     else if($_SERVER['REMOTE_ADDR']){
        echo "6-Ip is:".$ipaddress = $_SERVER['REMOTE_ADDR'];
}     else{
        echo "7-Ip is:".$ipaddress = 'UNKNOWN';
}
?>
</body>
</html>






For more Interesting, Useful Article & codes visit IT New Code.

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah