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
PDO returns erroneous columns from within pdt
Hi All,
This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns a
Problem with the Update command used with a sqldataadapter
I'm connected to a database on an SQL Server and I'm using a sqldataadapter, sqlconnection, sqldatas
What are causes of a connection-timeout with fopen()?
Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.
SHOW TABLES Help
Hi all
I have the following
Code: [Select]<?php
$sql = "SHOW TABLES&quo
$_POST variable un-useable
I'm trying to use a $_POST variable in a mysql update statement but i can't use it for some unknown
$action = "insert"; //$action = $_GET['action'];
$action = "insert";
//$action = $_GET['action'];
why is this invalid type? I am
Why do I get this error?
Error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or
How to store checkbox array in a session, and then be able to add to it?
I'm trying to store an array of checkbox values into a session array, sort of like a shopping cart,
Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",
substr(I_NAME, IN
how to use two buttons with php
hi i have one form. there are three fields which are to be filled by the user. and then there are tw