可以在php中设置设置会话

迪比恩杜·科纳尔(Dibyendu Konar)

我有一个要设置会话的登录页面,但是我的会话没有设置!!!!

<!--
Author: Dibyendu Konar

-->
<?php
session_start();
print_r($_SESSION);
include "db.php";
?>
<!DOCTYPE html>
<html>
<head>
    <title>Handikap admin login</title>
        <meta charset="utf-8">
        <link href="css/style.css" rel='stylesheet' type='text/css' />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
        <!--webfonts-->
        <link href='http://fonts.googleapis.com/css?family=Open+Sans:600italic,400,300,600,700' rel='stylesheet' type='text/css'>
        <!--//webfonts-->
</head>
<body>
     <!-----start-main---->
     <div class="main">
        <div class="login-form">
            <h1>Admin Login</h1>
                    <div class="head">
                        <img src="images/user.png" alt=""/>
                    </div>
                <form method="POST" onsubmit="errorCheck()">
                        <input type="text" name="email" id="email" class="text" value="EMAIL" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'EMAIL';}" >
                        <input type="password" id="password" name="password" value="PASSWORD" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Password';}">
                        <div class="submit">
                            <input type="submit" name="submit" value="LOGIN" >
                    </div>  
                    <p><a href="<?php echo  "./login"; ?>">Forgot Password ?</a></p>
                </form>
            </div>
            <!--//End-login-form-->

        </div>
             <!-----//end-main---->

</body>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" charset="utf-8" async defer>
function errorCheck()
{
    var password = $('#password').val();
    var email    = $('#email').val();
    if(((password == '') || (password == 'password') )|| ((email == '') || (email == 'EMAIL')))
    {
        alert("Please enter values");
        return false;
    }
}   

</script>
</html>


<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
function redirect($url) {
    if(!headers_sent()) {
        //If headers not sent yet... then do php redirect
        header('Location: '.$url);
        exit;
    } else {
        //If headers are sent... do javascript redirect... if javascript disabled, do html redirect.
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$url.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
        echo '</noscript>';
        exit;
    }
}


if(isset($_POST['submit']))
{
    /*-------------Getting the value------------*/
    $emailId     = trim($_POST["email"]);
    $passwordAdmin    = trim($_POST["password"]);
    /*------------------------------------------*/

    //echo $emailId.'<br/>'.$passwordAdmin;
    $result =mysql_query("SELECT * FROM `admin`");
    if(mysql_num_rows($result)>0)
                {
                    while($row=mysql_fetch_assoc($result))
                        {
                            extract($row);
                            echo '<pre/>';
                            $values[] = $row;
                        }
                }
    $databaseAdminEmail = $values[0]['email'];
    $databaseAdminPassword = $values[0]['password'];
    //echo $databaseAdminEmail.'<br/>'.$databaseAdminPassword;
    /*-----------------Validation debug--------------------------*/

    if ($databaseAdminEmail != $emailId) 
        {
            header('Location: '.$_SERVER['PHP_SELF'].'?auth=user_not_found');

        }

    if($databaseAdminPassword != $passwordAdmin)
        {
            header('Location: '.$_SERVER['PHP_SELF'].'?auth=password_error');
            //echo "stupid";
        }
    else
        {

                $_SESSION["admin"] = "log_in";
                echo "testpassed";
                echo $_SESSION['login'];
                $newURLExploded = explode("/admin.php", $newURL);
                $targetUrl = "playerlist.php";
                redirect($targetUrl);

                //die();
        }       
}
?>

因此无法开始将其也放入同一项目的另一个文件夹中

编码规范是这样的

<!DOCTYPE html>
<?php
session_start();
echo $_SESSION['admin'];
include "db.php";
?>
<html>

<head>
    <meta charset='UTF-8'>

    <title>User information</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="css/style.css">

    <!--[if !IE]><!-->
    <style>

    /* 
    Max width before this PARTICULAR table gets nasty
    This query will take effect for any screen smaller than 760px
    and also iPads specifically.
    */
    @media 
    only screen and (max-width: 760px),
    (min-device-width: 768px) and (max-device-width: 1024px)  {

        /* Force table to not be like tables anymore */
        table, thead, tbody, th, td, tr { 
            display: block; 
        }

        /* Hide table headers (but not display: none;, for accessibility) */
        thead tr { 
            position: absolute;
            top: -9999px;
            left: -9999px;
        }

        tr { border: 1px solid #ccc; }

        td { 
            /* Behave  like a "row" */
            border: none;
            border-bottom: 1px solid #eee; 
            position: relative;
            padding-left: 50%; 
        }

        td:before { 
            /* Now like a table header */
            position: absolute;
            /* Top/left values mimic padding */
            top: 6px;
            left: 6px;
            width: 45%; 
            padding-right: 10px; 
            white-space: nowrap;
        }

        /*
        Label the data
        */

    }

    /* Smartphones (portrait and landscape) ----------- */
    @media only screen
    and (min-device-width : 320px)
    and (max-device-width : 480px) {
        body { 
            padding: 0; 
            margin: 0; 
            width: 320px; }
        }

    /* iPads (portrait and landscape) ----------- */
    @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
        body { 
            width: 495px; 
        }
    }

    </style>
    <!--<![endif]-->

</head>

<body>

    <div id="page-wrap">



    <table>
        <thead>
        <tr>
            <th>Player id</th>
            <th>Percentage of complition</th>
            <th>Tag</th>
            <th>Device</th>

        </tr>
        </thead>
        <tbody>



<?php


        $result =mysql_query("SELECT * FROM `handikap`");
            if(mysql_num_rows($result)>0)
                {
                    while($row=mysql_fetch_assoc($result))
                        {
                            extract($row);
                            echo '<pre/>';
                            $values[] = $row;
                        }
                }
        $sizeOfArray =  sizeof($values);
        if($sizeOfArray >= 0)
                {
                       for($i=0;$i<$sizeOfArray;$i++)
                       {

                            echo "<tr>
          <td>".$values[$i]['playerId']."</td>
          <td>".$values[$i]['percentageComplete']."%"."</td>
          <td>".$values[$i]['tag']."</td>
          <td>".$values[$i]['device']."</td>

        </tr>";
                       }
                }
?>
        </tbody>
    </table>

    </div>

</body>

</html>

现在我的问题是我在哪里出错... ???? 因为我已经设置了会话以及获取会话,所以也没有输出.... !!!!!

我想破坏我在logout.php中的会话

<?php
session_destroy();   
unset($_SESSION["admin"]);
$target = "admin.php";
header( 'Location: ' . $target ) ;
?>

因此会议不破坏

将要

PHP文档中:

要使用基于cookie的会话,必须在将任何内容输出到浏览器之前调用session_start()。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用AJAX在PHP中设置会话变量

来自分类Dev

使用AJAX在PHP中设置会话变量

来自分类Dev

PHP会话未设置

来自分类Dev

PHP会话未设置

来自分类Dev

从PHP设置ASP会话

来自分类Dev

您可以通过哪种方式用CSS在PHP中设置会话Flash消息的样式?

来自分类Dev

在cookie中设置会话并从cookie PHP检索会话

来自分类Dev

我可以在 html 模板中设置会话变量吗?- 流星

来自分类Dev

PHP会话未设置或PHP会话破坏

来自分类Dev

PHP中的Redis会话忽略php.ini设置

来自分类Dev

PHP会话错误未设置

来自分类Dev

PHP会话变量未设置

来自分类Dev

PHP未设置会话变量

来自分类Dev

PHP会话错误未设置

来自分类Dev

PHP无法设置会话变量

来自分类Dev

jQuery和Ajax在PHP中设置会话变量

来自分类Dev

如何根据所选语言在php中设置会话?

来自分类Dev

如何在PHP中取消设置会话数组

来自分类Dev

在php中设置会话的正确方法是什么?

来自分类Dev

如何在php中设置用于登录和注销的会话?

来自分类Dev

在php中设置cookie并通过ajax运行会话

来自分类Dev

在Laravel中设置会话变量

来自分类Dev

在Laravel中设置会话变量

来自分类Dev

无法在codeigniter中设置会话后设置会话

来自分类Dev

设置会话?

来自分类Dev

除非刷新,否则未设置PHP会话

来自分类Dev

PHP未设置会话不起作用

来自分类Dev

PHP Laravel:如何设置或获取会话数据?

来自分类Dev

PHP使用相同的网站设置会话Cookie