Javascript PHP会话变量未在Safari中设置

Javascript PHP会话变量未在Safari中设置,javascript,php,safari,session-variables,Javascript,Php,Safari,Session Variables,我在使用PHP会话变量时遇到了一个新问题。问题是,它们似乎都能在Chrome和FireFox中工作,但在我的iPhone上不能在Safari中工作(注意:目前我无法访问本地页面用Internet Explorer进行测试,但我认为这超出了本问题的范围) 这是一个特别的问题,当我在一个网站上登录我正在工作的用户。代码如下: index.php <?php session_start(); include ("dbconfig.php"); ?> <html> <he

我在使用PHP会话变量时遇到了一个新问题。问题是,它们似乎都能在Chrome和FireFox中工作,但在我的iPhone上不能在Safari中工作(注意:目前我无法访问本地页面用Internet Explorer进行测试,但我认为这超出了本问题的范围)

这是一个特别的问题,当我在一个网站上登录我正在工作的用户。代码如下:

index.php

<?php session_start();
include ("dbconfig.php");
 ?>
<html>
<head>
    <title>My Webpage</title>
    <link rel = "stylesheet" type = "text/css" href = "site.css" />
    <link rel="shortcut icon" href="index.html?img=favicon" type="image/ico" />
    <script>

            function validatingForm(){
                var x;
                var y;
                var e;
                var p;

                x = document.getElementById('nameCheck').value;
                y = document.getElementById('password').value;
                e = document.getElementById('errorMsg');
                p = document.getElementById('errorPass');

                if(x !="" && y !=""){
                    return true;
                    }
                    else if(x =="" && y == ""){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        return false;
                    }
                    else if(x =="" && y!=""){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="blue">Password:</font>';
                        return false;
                    }
                    else if(y =="" && x!=""){
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        e.innerHTML='<font color="blue">Name:</font>';
                        return false;
                        }

            }
        function validatingSignUpForm(){
                var x;
                var y;
                var e;
                var p;

                x = document.getElementById('newonameCheck').value;
                y = document.getElementById('newopassword').value;
                e = document.getElementById('newoerrorMsg');
                p = document.getElementById('newoerrorPass');

                if(x !="" && y !=""){
                    return true;
                    }
                    else if(x =="" && y == ""){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        return false;
                    }
                    else if(x =="" && y!=""){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="blue">Password:</font>';
                        return false;
                    }
                    else if(y =="" && x!=""){
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        e.innerHTML='<font color="blue">Name:</font>';
                        return false;
                        }

            }
        function addValidate(){
                var x;
                var y;
                var z;
                var e;
                var p;
                var r;

                x = document.getElementById('nameCheck').value;
                y = document.getElementById('password').value;
                z = document.getElementById('role').value;
                e = document.getElementById('errorMsg');
                p = document.getElementById('errorPass');
                r = document.getElementById('errorRole');

                if(x !="" && y !="" && z !="empty"){
                    return true;
                    }
                    else if(x =="" && y == "" & z == "empty"){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        r.innerHTML='<font color="red">(required) Role:</font>';
                        return false;
                    }
                    else if(x !="" && y == "" & z == "empty"){
                        e.innerHTML='<font color="blue">Name:</font>';
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        r.innerHTML='<font color="red">(required) Role:</font>';
                        return false;
                    }
                    else if(x =="" && y!="" && z == "empty"){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="blue">Password:</font>';
                        r.innerHTML='<font color="red">(required) Role:</font>';
                        return false;
                    }
                    else if(x =="" && y == "" && z != "empty"){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        r.innerHTML='<font color="blue">Role:</font>';
                        return false;
                    }
                    else if(x =="" && y!="" && z != "empty"){
                        e.innerHTML='<font color="red">(required) Name:</font>';
                        p.innerHTML='<font color="blue">Password:</font>';
                        r.innerHTML='<font color="blue">Role:</font>';
                        return false;
                    }
                    else if(y =="" && x!="" && z != "empty"){
                        p.innerHTML='<font color="red">(required) Password:</font>';
                        e.innerHTML='<font color="blue">Name:</font>';
                        r.innerHTML='<font color="blue">Role:</font>';
                        return false;
                        }

            }
        </script>
</head>

<body>
    <?php include("header.php"); ?>
                <?php

                if (isset($_SESSION['user']))
                        /* user is logged in */
                        echo "<p class ='welcome' id='greeting'> Hi, ". $_SESSION['user'] . "! Welcome to the site!</p>";
                else
                        /* user is NOT logged in*/
                        echo "<p class ='welcome' id='greeting'> Please Login:</p>
                                        <form action='welcome.php' method='post'>
                                            <center><b id = 'errorMsg'>Name:</b>
                                            <input type='text' id='nameCheck' name = 'username' /></center>
                                            <br />
                                            <center><b id='errorPass'>Password:</b> <input type='password' id ='password' name = 'password'/></center>
                                            <br /><br />
                                            <center><input type='submit' value='Log In' onClick='return validatingForm()'/></center>
                                        </form>

                              <p class ='welcome' id='greeting'> OR Sign Up:</p>
                                        <form action='sign_up.php' method='post'>
                                            <center><b id = 'newoerrorMsg'>Name:</b>
                                            <input type='text' id='newonameCheck' name = 'addusername' /></center>
                                            <br />
                                            <center><b id='newoerrorPass'>Password:</b> <input type='password' id ='newopassword' name = 'addpassword'/></center>
                                            <br /><br />
                                            <center><input type='submit' value='Sign Up' onClick='return validatingSignUpForm()'/></center>
                                        </form>
                                        ";
                ?>
            <?php
                if (isset($_SESSION['user']) && $_SESSION['role'] == 'admin') {

                    /*query user db */
                    $user_rs = $db_con->query("SELECT * FROM users");

                    /* Assume there is a recordset and create the table */
                    echo "<center>
                            <h1> User List:</h1>
                            <table border='1'>
                            <tr>
                            <td><b>User ID</b></td>
                            <td><b>Username</b></td>
                            <td><b>Password</b></td>
                            <td><b>Options</b></td>
                            </tr>";

                            /* loop through recordset - new row for each user */
                            while( $record = $user_rs->fetch_object() ){
                                echo "
                                    <tr>
                                        <td>" . $record->id . "</td>
                                        <td>" . $record->username . "</td>
                                        <td>" . $record->password . "</td>
                                        <td><a href='remove_user.php?id=" . $record->id . "'>Delete</a></td>  
                                    </tr>";
                            }
                            /* Close the table */
                            echo "
                                </table>
                            </center>
                            <br />";
                            }
                else if (isset($_SESSION['user']) && $_SESSION['role'] == 'user') {

                    /*query user db */
                    $user_rs = $db_con->query("SELECT * FROM users WHERE username = '" . $_SESSION['user'] . "'");

                    /* Assume there is a recordset and create the table */
                    echo "<center>
                            <h1> Your Profile:</h1>
                            <table border='1'>
                            <tr>
                            <td><b>User ID</b></td>
                            <td><b>Username</b></td>
                            <td><b>Password</b></td>
                            </tr>";

                            /* take one row for user only */
                            $record = $user_rs->fetch_object();
                                echo "
                                    <tr>
                                        <td>" . $record->id . "</td>
                                        <td>" . $record->username . "</td>
                                        <td>" . $record->password . "</td>
                                    </tr>";

                            /* Close the table */
                            echo "
                                </table>
                            </center>
                            <br />";
                            }
                #else {
                    #do nothing
                #   }
            ?>
            <?php
                    if (isset($_SESSION['user']) && $_SESSION['role']=="admin")
                    echo "<p class ='welcome' id='greeting'> Add User:</p>
                                <form action='add_user.php' method='post' onSubmit='return addValidate();' style = 'border: 2px grey solid; padding: 5px'>
                                    <b id='errorMsg'>Name:</b>
                                    <input type='text' id='nameCheck' name='addusername'/>
                                    <br /><br />
                                    <b id='errorPass'>Password:</b> <input type='password' id='password' name='addpassword'/>
                                    <br /><br />
                                    <b id='errorRole'>Role:</b> <select name='addrole' id='role' >
                                    <option value='empty'>Select Role</option>
                                    <option value='admin'>Admin</option>
                                    <option value='user'>Ordinary User</option></select>
                                    <br /><br />
                                    <input type='submit' value='Add'/>
                                </form>";
                                ?>
            <?php if (isset($_SESSION['user']))
                echo "<center><a href='logout.php'>Logout</a></center>";?>  

            <p class = "content"> This is a page that is a scrap work in progress. </p>


            <?php include("footer.php"); ?> 
    </body>
</html>

我的网页
函数validatingForm(){
var x;
变量y;
变量e;
var-p;
x=document.getElementById('nameCheck')。值;
y=document.getElementById('password')。值;
e=document.getElementById('errorMsg');
p=document.getElementById('errorPass');
如果(x!=“”&&y!=“”){
返回true;
}
else if(x==“”&y==“”){
e、 innerHTML='(必需)名称:';
p、 innerHTML='(必需)密码:';
返回false;
}
如果(x==”&&y!=”,则为else{
e、 innerHTML='(必需)名称:';
p、 innerHTML='Password:';
返回false;
}
如果(y==”&&x!=”,则为else{
p、 innerHTML='(必需)密码:';
e、 innerHTML='Name:';
返回false;
}
}
函数validatingSignUpForm(){
var x;
变量y;
变量e;
var-p;
x=document.getElementById('newonameCheck')。值;
y=document.getElementById('newopassword')。值;
e=document.getElementById('newoerrorMsg');
p=document.getElementById('newoerrorPass');
如果(x!=“”&&y!=“”){
返回true;
}
else if(x==“”&y==“”){
e、 innerHTML='(必需)名称:';
p、 innerHTML='(必需)密码:';
返回false;
}
如果(x==”&&y!=”,则为else{
e、 innerHTML='(必需)名称:';
p、 innerHTML='Password:';
返回false;
}
如果(y==”&&x!=”,则为else{
p、 innerHTML='(必需)密码:';
e、 innerHTML='Name:';
返回false;
}
}
函数addValidate(){
var x;
变量y;
var z;
变量e;
var-p;
var-r;
x=document.getElementById('nameCheck')。值;
y=document.getElementById('password')。值;
z=document.getElementById('role')。值;
e=document.getElementById('errorMsg');
p=document.getElementById('errorPass');
r=document.getElementById('errorRole');
如果(x!=“”&&y!=“”&&z!=“空”){
返回true;
}
else if(x==“”&y==“”&z==“空”){
e、 innerHTML='(必需)名称:';
p、 innerHTML='(必需)密码:';
r、 innerHTML='(必需)角色:';
返回false;
}
如果(x!=“”&y=“”&z=“空”),则为else{
e、 innerHTML='Name:';
p、 innerHTML='(必需)密码:';
r、 innerHTML='(必需)角色:';
返回false;
}
如果(x==“”&&y!=“”&&z==“空”),则为else{
e、 innerHTML='(必需)名称:';
p、 innerHTML='Password:';
r、 innerHTML='(必需)角色:';
返回false;
}
else if(x==“”&&y==“”&&z!=“空”){
e、 innerHTML='(必需)名称:';
p、 innerHTML='(必需)密码:';
r、 innerHTML='Role:';
返回false;
}
如果(x==“”&&y!=“”&&z!=“空”){
e、 innerHTML='(必需)名称:';
p、 innerHTML='Password:';
r、 innerHTML='Role:';
返回false;
}
如果(y==“”&&x!=“”&&z!=“空”){
p、 innerHTML='(必需)密码:';
e、 innerHTML='Name:';
r、 innerHTML='Role:';
返回false;
}
}

你的具体问题是什么?会话变量似乎没有设置?您可能需要检查从浏览器获取的用户名和密码。浏览器对PHP代码的运行方式没有影响,因为它都是服务器端的,但它可以影响PHP脚本从浏览器获得的输入。浏览器不应该影响会话变量(因为它们是服务器生成的)。检查您的
文档。cookie
并查看会话ID是否为sameYes,检查cookie。如果PHP设置为仅使用Cookie,Safari设置为拒绝来自站点的Cookie,那么这将很好地解释您的问题。大多数浏览器调试器都知道允许cookie检查。只需在FFox(Q或Firebug)或Chrome调试器中检查cookie,然后在Safari的调试器中检查cookie。因为您正在调试mobile Safari,所以
<?php session_start(); 
include('dbconfig.php');?>
<html>
<head>
<title>My Webpage</title>
    <link rel = "stylesheet" type = "text/css" href = "site.css" />
    <link rel="shortcut icon" href="index.html?img=favicon" type="image/ico" />
<body>
<?php include("header.php"); ?>
<p class="welcome" id="greeting">
<?php

    $usercheck = $_POST["username"];
    $passcheck = $_POST["password"];
    $db_query = "SELECT * FROM users WHERE username = '" . $usercheck . "'";
    $result = mysqli_query($db_con, $db_query);
    if(!$result) {
        die(mysqli_error($db_con));
    }
    if(mysqli_num_rows($result) > 0) {
        $record = mysqli_fetch_array($result);
        if (md5($passcheck) == $record['password']){
            echo "Welcome, " . $_POST["username"] . "! You are now logged in. <br/>";
            $_SESSION['user']= $_POST["username"];
            $_SESSION['pass']= $passcheck;
            $_SESSION['role']= $record['role'];
            }
        else
            echo "Sorry, wrong password. <br/>";
        }
    else
        echo "No such user exists... <br />";
?>
<a href="index.php">Click here</a> to return to the main page.
<?php include("footer.php"); ?>
    </body>
</html>