AllExperts > PHP4 
Search      
PHP4
Volunteer
Answers to thousands of questions
 Home · More PHP4 Questions · Answer Library  · Encyclopedia ·
More PHP4 Answers
Question Library

Ask a question about PHP4
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Draicone
Expertise
I can answer almost all things related to php, and have years of experience coding for almost any situation. Snippets and bug fixes are the most common issues I deal with.

Experience
For the past four years I have been coding in php for various purposes. My recent uses of the skill have been in coding for xtraticwar.com, an online game written entirely in php that has allowed me to make use of my various experience with the language. For mathematical purposes I once turned an algorithm relating to probability into php code to calculate all possibilitie

Organizations
None.

Publications
School newsletters, general publications.

Education/Credentials
None related to the category.

Awards and Honors
None related to the category. However, I won the 2006 ICAS Computer Skills competition.

Past/Present clients
XtraticWar.com, LogicZero.net, Combobularity@SPLC (a toastmasters public speaking club requiring a web presence).

 
   

You are here:  Experts > Computing/Technology > Perl/PHP > PHP4 > IP address

PHP4 - IP address


Expert: Draicone - 7/25/2006

Question
hello.. i have some few question. i dont know how to solve this problem. if you know friendster website or other site that have profile and you can register and login, thats what is my problem now. when the user login, my program get the ip adress of the user to recognize that he is the user using in his account. the store it in a database. then i try using two computers in a computer shop or internet cafe. first i log in into the site using the first computer. the profile show up. then when i try the 2nd computer, the profile show up and never show the log in form. my problem is that the computer shops or internet cafe have the same ip address, can you tell me how to get the original ip adress of the computers. im using $REMOTE_ADDR to this problem. maybe their is something that you can help me... thank you and sorry for the wrong grammar.  

Answer
Unfortunately, this is not possible. All computers have an IP address on the internet that is specific to their internet connection, and within the network that shares the internet connection there is a 'subnet', but as a website you cannot see this or detect it. The best way to use authentication to check that people are logged in or not is to use cookies. By setting cookies (or better yet, session variables so that you can simply call session_start() and make $_SESSION['is_logged_in'] or similar serve this purpose) you can handle logins far more effectively. See http://php.net for instructions on how to use sessions. The way they work is that php generates a session ID, unique to the computer accessing the site, and stores that in a cookie on the user's computer. Then you can store as many variables as you like, and the values you assign will be specific to the computer your site is being accessed from, e.g. you can set $_SESSION['loggedin']. Here is a simple example of session use in php:
<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
echo "You have visited this page ".$_SESSION['count']." times.\n";
?>
Hope this helps.

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.