dongshen9686 2014-03-30 16:04
浏览 147
已采纳

MySQL函数不起作用

Thanks For Answers! I got lots of feedback and I have an answer and I fixed it. Thanks!

I am working on making a user login system for my website. I want the updates to be faster so I moved the exact files to my local server, (Apache/2.2.22 (Ubuntu)), and it suddenly does not work. The Database is external so it does not need the hostname changed. Any ideas? I get no errors, it just does not parse the MySQL bit.

Connect File:

<?php
    $host = "xxxxxxx.xxxxxxxxx.xx.xx";
    $user = "sh0u_xxxxxx";
    $pass = "xxxxx";
    $db   = "sh0u_1xxxxx_store";
    mysql_connect($host,$user,$pass) or die("Unable To Connect To Database");
    mysql_select_db($db)
?>

Login File:

<?php
    session_start();
    session_destroy();
    include('connect.php');
    $email = $_POST['email'];
    $pass = md5($_POST['password']);
    $query = mysql_query("SELECT * FROM users WHERE email='".$email."' AND password='".$pass."'");
    $numrows = mysql_num_rows($query);
    if($numrows === 1) {
        session_start();
        $_SESSION['sid'] = "".$email.":".$pass."";
        header('Location:../index.php');
    }else {
        include('../login.php');
        echo "<script>alert('Incorrect Username and/or Password');</script>";
    }
?>
  • 写回答

1条回答 默认 最新

  • duandun2218 2014-03-30 16:13
    关注

    Most hosting providers do not allow external access to the databases they include with their plans. Not only that, most of them use localhost as a database server so as to force a socket connection (so that they can even disable network connections to their DBs altogether).

    To test your script and site locally you will need to download a dump of your database and create a local version of it on your own.

    Other issues with your code

    As mentioned in comments you are:

    • You should be using the MySQL Improved Extension, instead of the old (and deprecated) MySQL extension
    • You are not sanitizing data you use for your queries (use prepared statements)
    • MD5 is not secure for passwords, you should be using the new password_hash instead
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP