Php功能限制区域

时间:2014-05-28 05:39:34

标签: php html mysql function

嘿,我有这个功能:

<?php

    if(isset($_POST['login']) && $_POST['login'] == 'LOGARE') {

        include('./inc/configurare.php');
            mysql_select_db('account');

        $user = mysql_real_escape_string($_POST['user']);
        $pass = mysql_real_escape_string($_POST['pass']);

            $check = "SELECT * from account where login = '" . $user . "' and password = PASSWORD('$pass')";
                $query = mysql_query($check);
                    $num = mysql_num_rows($query);


            if($num > 0) {

                $array = mysql_fetch_array($query);


            // SESSION variable start //

            $_SESSION['id'] = $array['login'];
            $_SESSION['coins'] = $array['coins'];
            $_SESSION['isadmin'] = $array['isadmin'];
            $_SESSION['pscadmin'] = $array['pscadmin'];
            $_SESSION['email'] = $array['email'];
            $_SESSION['real_name'] = $array['real_name'];
            $_SESSION['social_id'] = $array['social_id'];
            $_SESSION['user_admin'] = $array['web_admin']; 
            $_SESSION['user_id'] = $array['id'];
            $_SESSION['user_name'] = $array['login'];
            $_SESSION['user_coins'] = $array['coins'];
            $_SESSION['user_email'] = $array['email'];
            echo "<meta http-equiv='refresh' content='0; URL=index.php?s=home'>";
            } else {
            echo "<meta http-equiv='refresh' content='0; URL=index.php?s=login_error'>";
            }
        }

?>

我想在某些页面上限制访问,你必须登录到那个页面的介绍:

<?php

if(isset($_SESSION['user']) && isset($_SESSION['pass']))

{

    auto_unban();

    $username = $_SESSION['user'];

    $sql = mysql_query("Select * from account.account where login='".$_SESSION['user']."'") or die(mysql_error());

    $accc=mysql_fetch_object($sql);

    $charss = mysql_query("Select * from player.player where account_id='".$accc->id."'") or die(mysql_error());

    $chars = mysql_num_rows($charss);

?>

<script type='text/javascript'>

function myFunction()

{

var jmsg = "<? echo "Blocked : ".$acc->unban_date." pentru ".$acc->motiv_ban.".mlock."; ?>";

    if(jmsg){

        alert(jmsg);

    }

    window.onload=myFunction;

}

</script>

Script , script

<?php } else { echo "Please login!";} ?>

当我不登录时,该剧本告诉我这个回音:请登录! 当我登录时还告诉我echo:登录登录!

我不知道如何在php中创建和读取函数任何人都可以告诉我如何制作这样的函数:

if(isset($_SESSION['user']) && isset($_SESSION['pass']))

1 个答案:

答案 0 :(得分:0)

您的变量$ _SESSION ['login']为空,因为您忘记调用session_start();在你的PHP脚本的开头。

放置session_start();在打印页面上的任何字符之前。 例如:

<?php session_start(); 
$_SESSION['login'] =  'login';
...