记录后,php会话数据未存储在成员页面上

时间:2014-05-14 20:12:46

标签: php mysql session session-variables session-cookies

我正在构建一个成员系统,我已经通过php会话遇到了障碍,我可以创建一个帐户但是当我到达登录区域并提交我的详细信息时,我的会话没有被存储。我在每个页面上都有一个require_once文件,其中包含我的会话信息等。请看下面的代码。

我只是能够到达会员页面,因为会话数据没有被转移。

你可以在我的网站上测试:

http://dailypaychecknetwork.com/account/login.php

用户名: gazaian1
密码: icd199444

请帮助我,我已经在这3天了。 :(

每页都包含

页面:

//Require DB connection
require_once dirname(__FILE__) . "/connect_hostgator.php";

//Pages to require
require_once dirname(__FILE__) . "/languages/en.php";
require_once dirname(__FILE__) . "/class.newuser.php";
require_once dirname(__FILE__) . "/class.user.php";
require_once dirname(__FILE__) . "/funcs.php";

session_start();

//Global User Object Var
//loggedInUser can be used globally if constructed
if(isset($_SESSION["userCakeUser"]) && is_object($_SESSION["userCakeUser"]))
{
    $loggedInUser = $_SESSION["userCakeUser"];
}

登录脚本:

require_once("models/member-config.php");
error_reporting(E_ALL);
//Prevent the user visiting the logged in page if he/she is already logged in
if(isUserLoggedIn()) { header("Location: account.php"); die(); }

//Forms posted
if(isset($_POST['dpnlogin']))
{
    $errors = array();
    $username = sanitize(trim($_POST["username"]));
    $password = trim($_POST["password"]);

    //Perform some validation
    //Feel free to edit / change as required
    if($username == "")
    {
        $errors[] = lang("ACCOUNT_SPECIFY_USERNAME");
    }
    if($password == "")
    {
        $errors[] = lang("ACCOUNT_SPECIFY_PASSWORD");
    }

    if(count($errors) == 0)
    {
        //A security note here, never tell the user which credential was incorrect
        if(!usernameExists($username))
        {
            $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
        }
        else
        {
            $userdetails = fetchUserDetails($username);
                //Hash the password and use the salt from the database to compare the password.
                $password = MD5($password);

                if($password != $userdetails["user_pass"])
                {
                    //Again, we know the password is at fault here, but lets not give away the combination incase of someone bruteforcing
                    $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
                }
                else
                {
                    //Passwords match! we're good to go'

                    //Construct a new logged in user object
                    //Transfer some db data to the session object
                    $loggedInUser = new loggedInUser();
                    $loggedInUser->user_id = $userdetails["id"];
                    $loggedInUser->username = $userdetails["userid"];
                    //$loggedInUser->user_no = $userdetails["userno"];
                    $loggedInUser->email = $userdetails["email_address"];
                    $loggedInUser->pass = $userdetails["user_pass"];
                    $loggedInUser->fname = $userdetails["f_name"];
                    $loggedInUser->lname = $userdetails["l_name"];
                    $loggedInUser->phonee = $userdetails["phone"];
                    $loggedInUser->znzsingle = $userdetails["znz_single"];
                    $loggedInUser->znzdouble = $userdetails["znz_double"];
                    $loggedInUser->empowerid = $userdetails["empower_id"];
                    $loggedInUser->znzadteamlink = $userdetails["znzadteam_link"];

                    //$loggedInUser->updateLastSignIn();
                    $_SESSION["userCakeUser"] = $loggedInUser;

                    //var_dump($_SESSION); die;

                    //Redirect to user account page
                    header("Location: account.php");
                    die();
                }
        }
    }
}

require_once("../includes/header.php");
echo "
<div class='main-content-wrap'>
    <div class='main-content'>
        <h2>Login To Your Account:</h2>

        <div id='main'>";

        echo resultBlock($errors,$successes);

        echo "  
        <div id='regbox'>
                <form name='loginUser' action='".$_SERVER['PHP_SELF']."' method='post'>
                    <table cellpadding='3px' class='mtext'>
                        <tbody>
                            <tr>
                                <td class='tdSubHeader'><label>Username</label></td>
                                <td class='tdContent'><input type='text' name='username' size='25'/></td>
                            </tr>

                            <tr>
                                <td class='tdSubHeader'><label>Password</label></td>
                                <td class='tdContent'><input type='password' name='password' size='25'/></td>
                            </tr>
                        </tbody>
                    </table>
                        <br>
                        <div style='float:left;'><input type='submit' name='dpnlogin' value='Login'></div>                  
                </form>
            </div>
        </div>
    </div>
    <div class='sidebar'>
        <p>*CREATE YOUR FREE MARKETING SYSTEM TODAY*</p>
        <div class='important'>
            <b>IMPORTANT:</b>
            <p>IF YOU HAVE NOT YET SIGNED UP FOR EMPOWER NETWORK OR ZNZADTEAM.COM THEN PLEASE LEAVE THOSE FIELDS BLANK UNTIL YOU DO.</p>
        </div>
        <img class='green-button' src='../../images/leftbutton.jpg'>
    </div>
</div>
";
require_once("../includes/footer.php");

会员页面脚本:

require_once("models/member-config.php");
error_reporting(E_ALL);
//Prevent the user visiting the page if he is not logged in
if(!isUserLoggedIn()){ header("Location: login.php"); die(); }

require_once("../includes/header.php");
?>
<div class='main-content-wrap'>
    <div class="back-office-head">
        <div class="date"><p>TODAY IS:</p> <p><?php echo date("F jS \, Y"); ?></p></div>
        <div class="back-office"><h1>BACK OFFICE</h1></div>
        <div class="user-meta"><p>WELCOME <?php echo $loggedInUser->username; ?>,</p> <p>TO YOUR BACK OFFICE.</p></div>
    </div>

    <div class="back-office-links">
        <div class="links">
            <p>MY REFERRAL LINK:</p>
            <p><a href="#">http://www.dailypaychecknetwork.com/<?php echo $loggedInUser->username; ?></a></p>
            <br>
            <p>MY ZNZADTEAM.COM LINK:</p>
            <p><a href="#">CLICK HERE TO LEARN MORE</a></p>
            <br>
            <p>MY EMPOWER NETWORK LINK:</p>
            <p><a href="#">CLICK HERE TO LEARN MORE</a></p>
        </div>

        <div class="back-office-logo">
            <a href="http://www.dailypaychecknetwork.com"><img src="../images/dpnlogo.jpg" alt="daily paycheck network" /></a>
        </div>
    </div>

    <div class="back-office-buttons">
        <div class="back-office-row-1">
            <div class="gsg"><a href="#"><img src="../images/gettingstartedbutton.jpg" alt="getting started guide"/></a></div>
            <div class="ui"><a href="http://www.dailypaychecknetwork.com/account/updateuser.php"><img src="../images/updateinfobutton.jpg" alt="update info"/></a></div>
            <div class="vl"><a href="#"><img src="../images/viewleadsbutton.jpg" alt="update info"/></a></div>
        </div>
        <div class="back-office-row-2">
            <div class="gsg"><a href="#"><img src="../images/trainingbutton.jpg" alt="traning"/></a></div>
            <div class="ui"><a href="#"><img src="../images/autoresponderbutton.jpg" alt="autoresponder"/></a></div>
        </div>
        <div class="back-office-row-3">
            <div class="gsg"><a href="#"><img src="../images/toolsbutton.jpg" alt="tools"/></a></div>
            <div class="ui"><a href="http://dailypaychecknetwork.com/account/photo.php"><img src="../images/uploadphotobutton.jpg" alt="upload photo"/></a></div>
            <div class="vt"><a href="#"><img src="../images/viewtrafficbutton.jpg" alt="view traffic stats"/></a></div>
        </div>
        <div class="back-office-row-4">
            <div class="fb"><a href="#"><img src="../images/facebook.png" alt="daily paycheck network facebook"/></a></div>
            <div class="ao"><a href="#"><img src="../images/additionaloppsbutton.jpg" alt="additional opportunities"/></a></div>
            <div class="faq"><a href="#"><img src="../images/additionaloppsbutton.jpg" alt="fqa"/></a></div>
            <div class="cu"><a href="#"><img src="../images/additionaloppsbutton.jpg" alt="contact us"/></a></div>
        </div>
    </div>

    <div class="back-office-footer-ad-space"></div>
    </div>
</div>
<?php var_dump($_SESSION); ?>
<?php require_once("../includes/footer.php");

var dump:

array(1) { ["userCakeUser"]=> object(loggedInUser)#2 (12) { ["user_id"]=> int(31) ["user_no"]=> NULL ["email"]=> string(19) "nadogrand@gmail.com" ["pass"]=> string(32) "4f7253f18db6d091cd2f028bb0ab417c" ["fname"]=> string(8) "leonardo" ["lname"]=> string(9) "grandison" ["phonee"]=> string(10) "8764249826" ["username"]=> string(8) "gazaian1" ["znzsingle"]=> string(7) "1313434" ["znzdouble"]=> string(7) "1314445" ["empowerid"]=> string(9) "leodragon" ["znzadteamlink"]=> string(22) "znzadteam.com/gazaian1" } }

2 个答案:

答案 0 :(得分:1)

session_start()需要是第一次调用。

http://www.php.net/manual/fr/function.session-start.php

答案 1 :(得分:0)

问题出在我的htaccess文件中,我请求两个不同的网址,其中一个是www,一个是没有www。一旦我只请求了我的会话固定的网址。非常感谢你的帮助。