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
Display error above the login forum help!
Hi guys. just so you know im not asking for someone to do this for me I just need to be pointed in t
Libraries in C++
Hi all,
I have two libraries. one is based targeted on linux platform and uses another li
void* and sizeof()
Hi,
Using void* and sizeof is it possible to get the value of the object ?
I understan
how to make database item unique
Hey guys,
is it possible to do this:
I have the database item $title being pulled for
extract data
Code: <div class="post hentry uncustomized-post-template">
Form a inline view based on the results of the previous query?
Hi Experts,
Can we form a inline view on the results of a previous query (another inline view)?
Inserting a check in checkbox from array value
Hello all,
I have a bit of code that works for a select option box, but does not work for my chec
Customizing message/behavior
Hi,I'm using the ASP.NET membership/authorization controls in my application. Some parts of my appli
Best way to check for end of a record and send it back to the first record
I'm hoping someone can help me out and explain the best way to accomplish this.
What I'm doin
Form Help
Here is the form:
Line number On/Off | Expand/Contract<? include("../include/sess