Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Zapisanie adresu ip podczas logowania.
Forum PHP.pl > Forum > Przedszkole
woxala123
Witam prosze o pomoc.
Jak napisac skrypt by podczas logowania zapisywał adres ip i datę do odpowiednich komórek.
ylk
  1. function getRealIpAddr()
  2. {
  3. if (!empty($_SERVER['HTTP_CLIENT_IP'])) $ip=$_SERVER['HTTP_CLIENT_IP'];
  4. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  5. else $ip=$_SERVER['REMOTE_ADDR'];
  6. return $ip;
  7. }

woxala123
Może inaczej mam oto taki skrypt logowania
  1. <?php require_once('Connections/ko.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6. if (PHP_VERSION < 6) {
  7. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8. }
  9.  
  10. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12. switch ($theType) {
  13. case "text":
  14. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15. break;
  16. case "long":
  17. case "int":
  18. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19. break;
  20. case "double":
  21. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22. break;
  23. case "date":
  24. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25. break;
  26. case "defined":
  27. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28. break;
  29. }
  30. return $theValue;
  31. }
  32. }
  33.  
  34. mysql_select_db($database_ko, $ko);
  35. $query_Recordset1 = "SELECT ip_add FROM users";
  36. $Recordset1 = mysql_query($query_Recordset1, $ko) or die(mysql_error());
  37. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  38. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  39. ?>
  40. <?php
  41. // *** Validate request to login to this site.
  42. if (!isset($_SESSION)) {
  43. }
  44.  
  45. $loginFormAction = $_SERVER['PHP_SELF'];
  46. if (isset($_GET['accesscheck'])) {
  47. $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  48. }
  49.  
  50. if (isset($_POST['myusername'])) {
  51. $loginUsername=$_POST['myusername'];
  52. $password=$_POST['mypassword'];
  53. $MM_fldUserAuthorization = "";
  54. $MM_redirectLoginSuccess = "lista.php";
  55. $MM_redirectLoginFailed = "login_failed.php";
  56. $MM_redirecttoReferrer = true;
  57. mysql_select_db($database_ko, $ko);
  58.  
  59. $LoginRS__query=sprintf("SELECT user_login, user_password FROM users WHERE user_login=%s AND user_password=%s",
  60. GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  61.  
  62. $LoginRS = mysql_query($LoginRS__query, $ko) or die(mysql_error());
  63. $loginFoundUser = mysql_num_rows($LoginRS);
  64. if ($loginFoundUser) {
  65. $loginStrGroup = "";
  66.  
  67. if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  68. //declare two session variables and assign them
  69. $_SESSION['MM_Username'] = $loginUsername;
  70. $_SESSION['MM_UserGroup'] = $loginStrGroup;
  71.  
  72. if (isset($_SESSION['PrevUrl']) && true) {
  73. $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  74. }
  75. header("Location: " . $MM_redirectLoginSuccess );
  76. }
  77. else {
  78. header("Location: ". $MM_redirectLoginFailed );
  79. }
  80. }
  81. ?>
  82. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  83. <html xmlns="http://www.w3.org/1999/xhtml">
  84. <head>
  85. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  86. <title>Untitled Document</title>
  87. </head>
  88.  
  89. <body>
  90. <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  91. <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  92. <tr>
  93. <td colspan="3"><strong>Member Login </strong></td>
  94. </tr>
  95. <tr>
  96. <td width="78">Username</td>
  97. <td width="6"> </td>
  98. <td width="294"><input name="myusername" type="text" id="myusername" /></td>
  99. </tr>
  100. <tr>
  101. <td>Password</td>
  102. <td> </td>
  103. <td><input name="mypassword" type="password" id="mypassword" /></td>
  104. </tr>
  105. <tr>
  106. <td> </td>
  107. <td> </td>
  108. <td> </td>
  109. </tr>
  110. <tr>
  111. <td> </td>
  112. <td> </td>
  113. <td><p>
  114. <input type="submit" name="Submit" value="Login" /td>
  115. </p>
  116. <p>  </p></td>
  117. </tr>
  118. </table>
  119. </form>
  120. </body>
  121. </html>
  122. <?php
  123. mysql_free_result($Recordset1);
  124. ?>

Teraz chodzi mnie oto jak dopisac funkcję zapisywania adresu ip do tabeli users w kolumnie ip_add
bubusek
Cytat(woxala123 @ 18.03.2011, 11:38:08 ) *
Teraz chodzi mnie oto jak dopisac funkcję zapisywania adresu ip do tabeli users w kolumnie ip_add


kod do IP kolega podał wyżej a do tego dodaj

  1. $query = "INSERT INTO users SET ip_add='$ip'";

woxala123
To jak wstawić to wszystko razem by zadziałało? razem
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.