Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7649367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:56:49+00:00 2026-05-31T10:56:49+00:00

I have been trying to figure out this issue I am having with PHP

  • 0

I have been trying to figure out this issue I am having with PHP and Session cookies. For some reason, when I go to a new page within the same server, the sesion variable is not populating, but the session_id() is. And then if I go back and log back in, it works?? I have tried a few links on here and googled around, but nothing seems to work.

class SessionRepository
{

public $errors;

public function StartSession()
{
session_start();
}

public function SetUserSession($userName,$fullName)
{
        // Start session
        $this->StartSession;

        // Make sure there isn't something already set
        /*if (isset($_SESSION['userName']))
            unset($_SESSION['userName']);
        */
        // Make sure there isn't something already set
        /*if (isset($_SESSION['fullName']))
            unset($_SESSION['fullName']);
*/
        $_SESSION['userName'] = $userName;
        $_SESSION['fullName'] = $fullName;


}

public function CheckLogin($userName)
{
        $this->StartSession;
        if(empty($_SESSION[$userName]))
        {
            return false;
        }
        return true;
}

public function DestroyUserSession()
{
    $this->StartSession;

    session_destroy();
}

}






include("useritemrepository.php");
include('UserItem.php');
include('sessionrepository.php');
include('login.php');

if(!isset($_POST['submitcreds']))
{
    LoginPage($loginerror);
}
else
{


if ($_SERVER["REQUEST_METHOD"] == "POST")
{
        $userName = $_POST["userName"];
        $password = md5($_POST["password"]);

        $session = new SessionRepository();
        $userRepository = new UserItemRepository();

        $loggedin = $userRepository->LoginUser($userName,$password);

        if($userRepository->errors !="")
                    echo $userRepository->errors;

        if ($loggedin->UserName =="")
        {
            $loginerror = "Invald Credentials, Please try again";

            LoginPage($loginerror);
        }
        else
        {
        $fullName = $loggedin->FirstName . " " . $loggedin->LastName;

        // Build Session 
        $session->SetUserSession($userName,$fullName);
        echo "Session:" . $_SESSION["fullName"] ." ". $_SESSION["userName"];
        LoggedIn();
        exit();
        }

    }
    }

Then Here is the login page (login.php)

session_start();
function LoginPage($loginerror)
{

        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <title>
        Cold Calling Center
        </title>
        <link rel='stylesheet' href='site.css'/>
        </head>

        <body>

        <br/>
        <br/>
        <br/>
        <div id="wrapper" class="wrapper" width="600px" height="600px">
        <form name="login" action="<? $_SERVER["PHP_SELF"];?>" method="post">
        <span id="login-header" class="login-header"><? echo $loginerror;?></span>
        <br/>
        <br/>
        <span id="header">Welcome to Cold Calling Central</span>

        <table id="login-table">
        <th id="table-header">Login Form</th>
        <tr id="login-row">
        <td id="login-cell">UserName:</td>
        <td id="login-cell"><input type="text" name="userName"/></td>
        </tr>

        <tr id="login-row">
        <td id="login-cell">Password:</td>
        <td id="login-cell"><input type="password" name="password"/></td>
        </tr>
        <tr id="login-row">
        <td id="login-cell"><input type="submit" name="submitcreds" value="Login"/></td>

        </tr>
        <tr id="login-table">
        <td id="login-row"><a href="forgotPassword.php">Forgot Password</a></td>
        </tr>
        <tr id="login-table">
        <td id="login-row"><a href="register.php">Not Registered?</a></td>
        </tr>
        </table>
        <input type="hidden" name="PHP_AUTH_USER"/>

        </form>
        </div>

        </body>

        </html>
 }

function RedirectToPage()
{
$url ="loggedin.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<META HTTP-EQUIV="Refresh"
      CONTENT="1; URL=<? 
      /*Redirect user to their page upon update */
      echo $url;?>">
<title>Thank you for logging in</title>
<link rel="stylesheet" type="text/css" media="screen" href="briefing.css"/>
</head>

<body>
<div id="shadow">
<div id="wrapper">
<div id="branding"></div> 
<div id="content">

<h2></h2>


<table class="briefing" width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="2"><h4>Thank you for logging in <? echo $_SESSION['fullName'];?>.. you are now being redirected to your page!</h4></td>
        <td>&nbsp;</td>
    </tr>



</table>


</div>


</div>
</div>
</body>
</html>
<?
}

function LoggedIn()
{?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="HTML Tclassy for Linux (vers 6 November 2007), see www.w3.org">
<title>Registration</title>
<link rel='stylesheet' href='site.css' type="text/css">
</head>
<body>
    <div id="wrapper" class="wrapper">
        <span id="login-header" class="login-header"><? echo "Welcome: " . $_SESSION['fullName']; ?></span>

                <ul id="menu-List" class="menu-list">
                <li class="list-item"><a class="menu-link" href="loggedin.php">Home</a></li>
                <li class="list-item"><a class="menu-link" href="test.php">Home</a></li>
                <li class="list-item"><a class="menu-link" href="index.php">Home</a></li>
                <li class="list-item"><a class="menu-link" href="index.php">Home</a></li>
                </ul>
    </div>

</body>
</html>
}

And here is the page off of one of the links in the landing page. When I use the link to go to test.php, (the code below, it does not carry the Fullname session, but if I go back and login again, it works?

session_start();
echo session_id();
echo "Name: " . $_SESSION["fullName"];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:56:50+00:00Added an answer on May 31, 2026 at 10:56 am

    put
    session_start();
    always at the very top of your page!

    so here it will probably work:

       <?
        session_start();
        include("useritemrepository.php");
        include('UserItem.php');
        include('sessionrepository.php');
        include('login.php');
        ...
    

    because: if there is a single space outside of (or more) in the other files you include. Session_start will not work. This space will be written to the output and session_start can not modify the http header of the page. Usually you get an error/warning/notice when that happens. So enable your errors or look for the error-logfile. Since you are starting -> put the warnings and errors in the output and make shure you disable them when you deploy.

    in essence 3 pieces of adivce:

    1. session_start always goes first
    2. no html in functions/classes
    3. get the html out of your code and include “html/login.php” by using small variables
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been trying to figure this out but i just can't.... for some
I have been Trying to figure this out for some time now. I have
I have been trying for hours to figure this out. I have some JSON
I have been trying to figure this out for way to long tonight. I
I am fairly new to Emacs and I have been trying to figure out
been trying to figure out Android layouts and having a bit of an issue.
I have been banging my head against the wall trying to figure out this
I have been trying to figure out a solution but nothing has really presented
I have been trying to figure out a way to tag several methods from
I have been going mad trying to figure out why my scripts weren't working,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.