$_SESSION['firstname'] returns everytime blank





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















When i try to get the firstname with $_SESSION it returns blank..
Here is the PHP side of my home.php:



<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';


sec_session_start();


?>

<a href="#" title=""><?php echo $_SESSION['firstname'];?>


I'm not sure but i think there is a problem with the sec_session_start() function:



function sec_session_start() {
$session_name = 'sec_session_id';

// The Below is set in a document which is included in the
// functions document: include_once 'psl-config.php' with
// define("SECURE", TRUE);
$secure = SECURE;

// This stops JavaScript being able to access the session id.
$httponly = true;

// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}

// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);

// Sets the session name to the one set above.
session_name($session_name);

session_start(); // Start the PHP session
session_regenerate_id(); // regenerated the session, delete the old one.
}


I can't figure out what the problem is. Can someone help me with this :)



*Error Reporting:

I have enabled error reporting and it gives me this error now




Notice: Undefined index: firstname in /----------/home.php on line 239




I have fixed this error*



Setting $_SESSION['firstname']



if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];

if ($stmt = $mysqli->prepare("SELECT firstname FROM members WHERE id = ? LIMIT 1")) {
$stmt->bind_param('i', $user_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($_SESSION['firstname']);
$stmt->fetch();
} else {
// Not logged in
return false;
}


The page is now white without any error reportings



Also some pictures of the database:










share|improve this question




















  • 1





    Enable error reporting if you haven't already.

    – Funk Forty Niner
    Nov 16 '18 at 22:01






  • 2





    Where are you setting $_SESSION['firstname'] ?

    – ksealey
    Nov 16 '18 at 22:02











  • You have to declare session start before anything. then you set the session variable. and then you can retreive it. you dont need a function that start a session. And we can not see where you set you session firstname var anywhere

    – MadeInDreams
    Nov 16 '18 at 22:05













  • try to add $_SESSION['firstname'] = 'MYNAME'; after the session_strat(); function and you should get something;

    – MadeInDreams
    Nov 16 '18 at 22:10






  • 4





    This is entirely the wrong way you should be setting sessions

    – Martin
    Nov 16 '18 at 22:14


















0















When i try to get the firstname with $_SESSION it returns blank..
Here is the PHP side of my home.php:



<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';


sec_session_start();


?>

<a href="#" title=""><?php echo $_SESSION['firstname'];?>


I'm not sure but i think there is a problem with the sec_session_start() function:



function sec_session_start() {
$session_name = 'sec_session_id';

// The Below is set in a document which is included in the
// functions document: include_once 'psl-config.php' with
// define("SECURE", TRUE);
$secure = SECURE;

// This stops JavaScript being able to access the session id.
$httponly = true;

// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}

// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);

// Sets the session name to the one set above.
session_name($session_name);

session_start(); // Start the PHP session
session_regenerate_id(); // regenerated the session, delete the old one.
}


I can't figure out what the problem is. Can someone help me with this :)



*Error Reporting:

I have enabled error reporting and it gives me this error now




Notice: Undefined index: firstname in /----------/home.php on line 239




I have fixed this error*



Setting $_SESSION['firstname']



if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];

if ($stmt = $mysqli->prepare("SELECT firstname FROM members WHERE id = ? LIMIT 1")) {
$stmt->bind_param('i', $user_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($_SESSION['firstname']);
$stmt->fetch();
} else {
// Not logged in
return false;
}


The page is now white without any error reportings



Also some pictures of the database:










share|improve this question




















  • 1





    Enable error reporting if you haven't already.

    – Funk Forty Niner
    Nov 16 '18 at 22:01






  • 2





    Where are you setting $_SESSION['firstname'] ?

    – ksealey
    Nov 16 '18 at 22:02











  • You have to declare session start before anything. then you set the session variable. and then you can retreive it. you dont need a function that start a session. And we can not see where you set you session firstname var anywhere

    – MadeInDreams
    Nov 16 '18 at 22:05













  • try to add $_SESSION['firstname'] = 'MYNAME'; after the session_strat(); function and you should get something;

    – MadeInDreams
    Nov 16 '18 at 22:10






  • 4





    This is entirely the wrong way you should be setting sessions

    – Martin
    Nov 16 '18 at 22:14














0












0








0








When i try to get the firstname with $_SESSION it returns blank..
Here is the PHP side of my home.php:



<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';


sec_session_start();


?>

<a href="#" title=""><?php echo $_SESSION['firstname'];?>


I'm not sure but i think there is a problem with the sec_session_start() function:



function sec_session_start() {
$session_name = 'sec_session_id';

// The Below is set in a document which is included in the
// functions document: include_once 'psl-config.php' with
// define("SECURE", TRUE);
$secure = SECURE;

// This stops JavaScript being able to access the session id.
$httponly = true;

// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}

// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);

// Sets the session name to the one set above.
session_name($session_name);

session_start(); // Start the PHP session
session_regenerate_id(); // regenerated the session, delete the old one.
}


I can't figure out what the problem is. Can someone help me with this :)



*Error Reporting:

I have enabled error reporting and it gives me this error now




Notice: Undefined index: firstname in /----------/home.php on line 239




I have fixed this error*



Setting $_SESSION['firstname']



if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];

if ($stmt = $mysqli->prepare("SELECT firstname FROM members WHERE id = ? LIMIT 1")) {
$stmt->bind_param('i', $user_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($_SESSION['firstname']);
$stmt->fetch();
} else {
// Not logged in
return false;
}


The page is now white without any error reportings



Also some pictures of the database:










share|improve this question
















When i try to get the firstname with $_SESSION it returns blank..
Here is the PHP side of my home.php:



<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';


sec_session_start();


?>

<a href="#" title=""><?php echo $_SESSION['firstname'];?>


I'm not sure but i think there is a problem with the sec_session_start() function:



function sec_session_start() {
$session_name = 'sec_session_id';

// The Below is set in a document which is included in the
// functions document: include_once 'psl-config.php' with
// define("SECURE", TRUE);
$secure = SECURE;

// This stops JavaScript being able to access the session id.
$httponly = true;

// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}

// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);

// Sets the session name to the one set above.
session_name($session_name);

session_start(); // Start the PHP session
session_regenerate_id(); // regenerated the session, delete the old one.
}


I can't figure out what the problem is. Can someone help me with this :)



*Error Reporting:

I have enabled error reporting and it gives me this error now




Notice: Undefined index: firstname in /----------/home.php on line 239




I have fixed this error*



Setting $_SESSION['firstname']



if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];

if ($stmt = $mysqli->prepare("SELECT firstname FROM members WHERE id = ? LIMIT 1")) {
$stmt->bind_param('i', $user_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($_SESSION['firstname']);
$stmt->fetch();
} else {
// Not logged in
return false;
}


The page is now white without any error reportings



Also some pictures of the database:







php session






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 23:42







Murat

















asked Nov 16 '18 at 21:56









MuratMurat

113




113








  • 1





    Enable error reporting if you haven't already.

    – Funk Forty Niner
    Nov 16 '18 at 22:01






  • 2





    Where are you setting $_SESSION['firstname'] ?

    – ksealey
    Nov 16 '18 at 22:02











  • You have to declare session start before anything. then you set the session variable. and then you can retreive it. you dont need a function that start a session. And we can not see where you set you session firstname var anywhere

    – MadeInDreams
    Nov 16 '18 at 22:05













  • try to add $_SESSION['firstname'] = 'MYNAME'; after the session_strat(); function and you should get something;

    – MadeInDreams
    Nov 16 '18 at 22:10






  • 4





    This is entirely the wrong way you should be setting sessions

    – Martin
    Nov 16 '18 at 22:14














  • 1





    Enable error reporting if you haven't already.

    – Funk Forty Niner
    Nov 16 '18 at 22:01






  • 2





    Where are you setting $_SESSION['firstname'] ?

    – ksealey
    Nov 16 '18 at 22:02











  • You have to declare session start before anything. then you set the session variable. and then you can retreive it. you dont need a function that start a session. And we can not see where you set you session firstname var anywhere

    – MadeInDreams
    Nov 16 '18 at 22:05













  • try to add $_SESSION['firstname'] = 'MYNAME'; after the session_strat(); function and you should get something;

    – MadeInDreams
    Nov 16 '18 at 22:10






  • 4





    This is entirely the wrong way you should be setting sessions

    – Martin
    Nov 16 '18 at 22:14








1




1





Enable error reporting if you haven't already.

– Funk Forty Niner
Nov 16 '18 at 22:01





Enable error reporting if you haven't already.

– Funk Forty Niner
Nov 16 '18 at 22:01




2




2





Where are you setting $_SESSION['firstname'] ?

– ksealey
Nov 16 '18 at 22:02





Where are you setting $_SESSION['firstname'] ?

– ksealey
Nov 16 '18 at 22:02













You have to declare session start before anything. then you set the session variable. and then you can retreive it. you dont need a function that start a session. And we can not see where you set you session firstname var anywhere

– MadeInDreams
Nov 16 '18 at 22:05







You have to declare session start before anything. then you set the session variable. and then you can retreive it. you dont need a function that start a session. And we can not see where you set you session firstname var anywhere

– MadeInDreams
Nov 16 '18 at 22:05















try to add $_SESSION['firstname'] = 'MYNAME'; after the session_strat(); function and you should get something;

– MadeInDreams
Nov 16 '18 at 22:10





try to add $_SESSION['firstname'] = 'MYNAME'; after the session_strat(); function and you should get something;

– MadeInDreams
Nov 16 '18 at 22:10




4




4





This is entirely the wrong way you should be setting sessions

– Martin
Nov 16 '18 at 22:14





This is entirely the wrong way you should be setting sessions

– Martin
Nov 16 '18 at 22:14












1 Answer
1






active

oldest

votes


















0














I have fixed the problem, I was missing a } at the end of the set $_SESSION script






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345970%2fsessionfirstname-returns-everytime-blank%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I have fixed the problem, I was missing a } at the end of the set $_SESSION script






    share|improve this answer




























      0














      I have fixed the problem, I was missing a } at the end of the set $_SESSION script






      share|improve this answer


























        0












        0








        0







        I have fixed the problem, I was missing a } at the end of the set $_SESSION script






        share|improve this answer













        I have fixed the problem, I was missing a } at the end of the set $_SESSION script







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 10:34









        MuratMurat

        113




        113
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345970%2fsessionfirstname-returns-everytime-blank%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python