dtwzwmv87399 2014-03-24 00:01
浏览 7
已采纳

如何检测用户是否接受了条款?

Basically I am writing a PHP and MYSQL script that will check whether a user has accepted the terms and conditions or not. In the databse every current user that has signed up is set to "unaccepted". When they log in the first page that they are directed to should have a scirpt on it that detects whether or not the status of the tos column in the users table is set to "accepted" or "unaccepted". If it is accepted they can continue, and if it is not they they will be forced to go to a page and accept them before they can continue to use the rest of my site. This is the code so far but it doesn't seem to be working. Any suggestions help.

<?php

$username=$_SESSION['username'];
$connect = mysql_connect('**', '**', '**', '**');
if (!$connect) 
{
    die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('**')) 
{
    die('Could not select database: ' . mysql_error());
}
$toschecker = mysql_query("SELECT `tos` FROM `users` WHERE `username` = '$username'");
if (!$toschecker) 
{
    die('Could not query:' . mysql_error());
}
mysql_close($connect);
$unaccepted='unaccepted';

if ($toschecker === $unaccepted)
{
    header('Location: accepttos.php');
}    
?>

For some reason this isn't directing them to the accepttos.php page. Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dongzan9069 2014-03-24 00:11
    关注

    Change MySQL to MySQLi. Explanations are in the comments.

    <?php
    
    $username = $_SESSION['username'];
    $connect = mysqli_connect('Host', 'Username', 'Password', 'Database');
    if (!$connect) 
    {
        die('Could not connect: ' . mysql_error());
    }
    
    $toschecker = mysqli_query($connect,"SELECT `tos` FROM `users` WHERE `username` = '$username'"); /* SELECT TOS COLUMN */
    
    while ($row = mysqli_fetch_array($toschecker)) 
    {
        $tos = $row['tos']; /* STORE TO A VARIABLE THE FETCHED TOS */
    }
    
    $unaccepted = 'unaccepted';
    
    if ($tos == $unaccepted) /* COMPARE THE TOS VARIABLE IF UNACCEPTED */
    {
        header('Location: accepttos.php');
    }
    
    else {
        header('Location: acceptedTOS.php'); /*  IF TOS IS ACCEPTED. CHANGE THE LOCATION */
    }
    
    mysqli_close($connect);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?