dounou9751 2015-09-18 04:33
浏览 37

将IP地址存储在单列中

Here is my code which insert a single value of IP Address when user login. If the user tries to login from a different IP then user will get an email to confirm. After the user clicks on the link sent in the email, the IP address is updated. Instead of updating the IP adddress, I want to store all IPs when whenever the user confirms its identity so that if the user can be able to login same IP that we have stored in our array.

Basically I want to store IP address as an array.

<?php

       include 'header.php';
   include('config.php');
         $eemail=$_GET['email'];

        if(isset($_POST['scode']))
        {
     $unncode=$_POST['uncode'];

      $sql1="SELECT * FROM nennetwork WHERE code ='$unncode'";
        $res=mysql_query($sql1);

    $rows = mysql_fetch_array($res);

     $ccode = $rows['code'] ;

      if($unncode==$ccode)
     $eemail=$_GET['email'];
       $ips = $_SERVER['REMOTE_ADDR'];
   if(mysql_query("update nennetwork set useripp= '".$ips ."' WHERE email ='$eemail'"))
        {
       $mmmsg= "You can <a href='".'index.php'."' class='ac'>Login</a> if the code matches the code that we have sent you.";


      }


      else{

     $mmmsg="Please submit the numeric code that we sent to your email.";

     }}

        ?> 
  • 写回答

3条回答 默认 最新

  • doulun1939 2015-09-18 04:51
    关注

    Ok, besides a massive case for SQL injection (READ UP ON php-pdo on php.net, great simple to use examples).

    The troublesome query for you which does not insert:

    if(mysql_query("update nennetwork set useripp= '".$ips ."' WHERE email ='$eemail'"))

    Could be replaced by:

    INSERT INTO nennetwork (useripp, email) VALUES (?,?) 
      ON DUPLICATE KEY UPDATE useripp=?;
    

    For this to work you will need 1 index:

    CREATE UNIQUE INDEX idx_nennetwork_nn_1 ON nennetwork(email);
    

    This will cause the duplicate key to trigger the update or the insert depending on the data involved.

    (Read php-pdo on how to get the ?,? and ? be replaced by bind variables and some safer code).

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题