Chotu Posted May 11, 2011 Share Posted May 11, 2011 Hi I was wondering is it possible to get the client's ip when he clicks on an activation link? If yes how? Quote Link to comment https://forums.phpfreaks.com/topic/236087-ip-using-activation-link/ Share on other sites More sharing options...
wepnop Posted May 11, 2011 Share Posted May 11, 2011 Hi I was wondering is it possible to get the client's ip when he clicks on an activation link? If yes how? use this in the php form that responses that link: $ip = $_SERVER['REMOTE_ADDR']; Quote Link to comment https://forums.phpfreaks.com/topic/236087-ip-using-activation-link/#findComment-1213697 Share on other sites More sharing options...
Chotu Posted May 12, 2011 Author Share Posted May 12, 2011 Could you show me one example how to response to the link ? Sorry I just learning this stuff and I'm stuck at this portion Quote Link to comment https://forums.phpfreaks.com/topic/236087-ip-using-activation-link/#findComment-1214278 Share on other sites More sharing options...
btherl Posted May 12, 2011 Share Posted May 12, 2011 Do you have a script already? If you do, please post it. If you don't have anything yet, I suggest looking for a tutorial or some sample code in google first. Eg you can search for "php activation link code" or "php activation link tutorial" Quote Link to comment https://forums.phpfreaks.com/topic/236087-ip-using-activation-link/#findComment-1214284 Share on other sites More sharing options...
Chotu Posted May 12, 2011 Author Share Posted May 12, 2011 This is what me and my friend after some researching on the net wrote. Now I have a ip column in the mysql table I dont know where to put it in this code mysql_connect("localhost", DATABASE, "PASSWORD") or die(mysql_error()); mysql_select_db("USER_TABLENAME") or die(mysql_error()); if ($_POST['form_submitted'] == '1') { ##User is registering, insert data until we can activate it $activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand(); $username = mysql_real_escape_string($_POST[username]); $password = mysql_real_escape_string($_POST[password]); $email = mysql_real_escape_string($_POST[email]); $sql="INSERT INTO users (username, password, email, activationkey, status) VALUES ('$username', '$password', '$email', '$activationKey', 'verify')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration."; ##Send activation Email $to = $_POST[email]; $subject = " doitright.com Registration"; $message = "Welcome to our website!\r\rYou, or someone using your email address, has completed registration . You can complete registration by clicking the following link:\rhttp://www..doitright.com/verify.php?$activationKey\r\rIf this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\ YOURWEBSITE.com Team"; $headers = 'From: noreply@ doitright.com' . "\r\n" . 'Reply-To: noreply@ doitright.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } else { ##User isn't registering, check verify code and change activation code to null, status to activated on success $queryString = $_SERVER['QUERY_STRING']; $query = "SELECT * FROM users"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if ($queryString == $row["activationkey"]){ echo "Congratulations!" . $row["username"] . " your account is activated"; $sql="UPDATE users SET activationkey = '', status='activated' WHERE (id = $row[id])"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } } } } Quote Link to comment https://forums.phpfreaks.com/topic/236087-ip-using-activation-link/#findComment-1214290 Share on other sites More sharing options...
btherl Posted May 12, 2011 Share Posted May 12, 2011 Can you try this (if the ip column is in the users table): $sql="UPDATE users SET activationkey = '', status='activated', ip = '{$_SERVER['REMOTE_ADDR']}' WHERE (id = $row[id])"; It should replace the existing update query. You may also want to replace the select with this: $query = "SELECT * FROM users WHERE activationkey = '" . mysql_real_escape_string($queryString) . "'"; But that isn't necessary to get the script to work, it's just a sensible optimization. Quote Link to comment https://forums.phpfreaks.com/topic/236087-ip-using-activation-link/#findComment-1214308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.