Session is not saving
Posted on
16th Feb 2014 07:03 pm by
admin
I am not trying to do anything too fancy, I am just trying to get some $_SESSION data to save and use it on the next page, but so far no luck.
Its saving some data to $_SESSION['name'] and then loading the header, but that header re-directs using another header command (no whitespace obviously) and then on that page, it has a php include that i need to call the superglobal $_SESSION['name']. At the moment i just want to print the thing, i will deal with functionality once i can actually pass the session data to the next page.
Input page has:
Code:
$sql = "SELECT UID FROM User
WHERE Username='$_POST[username]'
AND Password='$_POST[password]'
AND CID='$_POST[CompanyID]';";
$result = mysql_query($sql);
$num = mysql_numrows($result);
if ($num == 1) {
$sql = "SELECT CompanyName FROM Company WHERE CID ='$_POST[CompanyID]';";
$result2 = mysql_query($sql);
$companyname = mysql_result($result2, 0);
$id = mysql_fetch_assoc($result);
setcookie("nameofcookie", $value, time()+3500);
//setcookie("auth", "yes", time()+300);
//setcookie("id", $id['id']);
//setcookie("username", $id['username']);
$successful = "Location: ./".$companyname."/index.php";
session_start();
$_SESSION['name'] = $_POST['CompanyID'].$_POST['username']; //companyID.username is the format for session name.
session_write_close();
mysql_close();
header ($successful); //where to go if successful
} else {
header ('Location: login.php'); // where to if fail
}
?>
And I am trying to call $_SESSION['name'] on the other page, but the piece of code is inside a small <div> include, loaded by the header page.
header page calls this:
index.php (which re-directs to)
<?php
header( 'Location: ./menu/' ) ;
?>
Code: <HTML> BLAH BLAH BLAH
</head>
<body>
<?php include '../includes/pageheader.php'; ?>
<more html>
Here is the contents of that include (pageheader.php).
Code: <div id="headerbar">
<a href="index.php"><img alt="Solace Logo" src="../images/solacelogo.jpg" class="solacelogo" /></a>
<ul id="toppageoption">
<li><a href="../help.php">Help</a></li>
<li><a href="../changecompany.php">Change Company</a></li>
<li><a href="../logout.php">Logout (<?php echo $_SESSION['name']; ?>)</a></li>
</ul>
</div>
No comments posted yet
Your Answer:
Login to answer
171
44
Other forums
Retrieving innerHTML with cURL?
Hey all (sorry I know I'm a leecher, but I soon won't be. This is my first PHP project, but not my l
private constructor
Hello,
Can we create a constructor as private? If yes, what is the use of it? If no, why can'
Pass sql into pl/sql and create RMAN duplicate script.
Hi,
I'm new to pl/sql and I'm trying to write a script that will generate some RMAN comma
Help If user voted, block them
On my Prayer request site, i let users Click a button to Pray for somone that has posted a pray, i g
Google voice
I currently have a form in html, but I want it in php so the information is not in the source code.<
dinamic "textboxes"?
Ey all, my first post here, i hope its not a hard one
I display mysql results in a table
Posting to another Site?
I have software that people install.
When they install it, is there a way to make it post their d
foreach and array need help combining
Hi guys.
Here's the code
Code: array(
'tag' => 'code',<
Login logout link help
Hi all,
Im new to php and Im having trouble creating a login/logout link for my page that dis
function not returning the correct value
I have a program that needs to return a value from a function. I have an output statement inside the