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
please help me... my password gets encrypted but not able to get in database
hai guys,
please help me... in the following function my password gets encrypted but no
array_map() probably obvious mistake
The code below is part of a class to escape strings, but should also accept an array, using array_ma
filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h
Preg_match with an array
is there an away to use preg_match with an array?
i want to check a string with an array to s
turning an array into a string then poping it into a db
Hi im just wondering how you get a requested array into a single string then pop it into the db so f
Converting RGB values to HEX
Code: <?PHP
$file_handle = fopen("colors/rgb.csv", "r");
wh
foreach and array need help combining
Hi guys.
Here's the code
Code: array(
'tag' => 'code',<
Need help in log in and log out?
hi there all of u. i have recently created a site for someone. i have placed log in and log out and
How to kill asynchronous postback / current postback?
Hi,here is my problem:I have a web site with many pages of which some may take time to process resul
please, need help coding this voting for your favorite car polling system.
hi, my code needs a lot of work, but i want to be able to let users vote on their favorite car, upda