duande3134 2014-05-14 20:12
浏览 53

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

I am building a member system and i have hit a road block with php sessions, I am able to create an account but when i reach the login area and submit my details my sessions are not being stored. I have a file that require_once on every page with my session info and such. Please see below code.

I am just noe able to reach the member page because the session data is not carried over.

you can test at my site here:

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

username: gazaian1
Password: icd199444

Please help me out i have been at this for 3 days. :(

Page included on every page:

//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"];
}

Login script:

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");

Member page script:

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条回答 默认 最新

  • dongpiao8821 2014-05-14 20:46
    关注

    session_start() need to be the first call.

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

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错