javascript - Detect IP address, converting it to a username and displaying it on the page
Get the solution ↓↓↓Solution:
First, your opening statement ‘I need this all in HTML format’ is not possible as you point out the requirement for PHP which is not HTML. It generally produces HTML, but it’s not HTML in itself.
To detect a users IP address: Google searchphp get ip address of client
and you will find a lot of info including some of the pitfalls on accuracy etc.
Where you want to put HTML or JavaScript in your document use something like:
<?php
$clientIP = $_SERVER['REMOTE_ADDR'];
// now check if it’s a particular IP address. This if statement will only add the echoed html/javascript code if it is that IP address.
If ($clientIP == “192.168.0.2”) {
echo “Javascript/HTML code here to create your popup message between quotes”;
// you can use multiple echo lines which is where you write javascript of html to create your html page
}
// repeat if statement for more IP’s or you can get fancy
?>
A tip on using PHP for certain bits in a normal HTML document: Write the document as HTML and where you need to put something different because of (in this case) a specific IP address, put the PHP code there. Don’t forget to start the php code with a<?php
and end it with a?>
// is a comment line in PHP
$_SERVER http://php.net/manual/en/reserved.variables.server.php
echo is what it says, a built in PHP command that echoes what its told to. See http://php.net/manual/en/function.echo.php for details.
This is fairly basic to hopefully get you going. Start small and work your way up.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: trying to access array offset on value of type bool
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.