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>

171 Like 44 Dislike
Previous php-forum Next php-forum
Other php-forum

Replacing a string on click of a button
Hi! Is there a way to replace a string on a click of a text link?

This is what I've come up w

Coefficient of a Restitution Hints
Hello. I was wondering if anyone can give me hints on how to write this program...

The coeffi

problems with search form numerical "between" sending by php
I am trying to display the results of a search, on a sql database, on a web page. I set up html &quo

EXplanation help
Hey all,

I am still fairly new to PHP programming and I am trying to put together a page wher

Convert Binary String to Decimal
Trying to Get:
Decimal: 305419896

Out of:
Binary String: xV4

Why use interfaces in PHP (OOP)
I am learning OOP in PHP and its been a pretty good learning experience so far. What I didn't unders

header redirect problems? please help
Ok i am making a site that generates youtube thumbnails and i am generating an image that displays 1

Transform value 0 in no and 1 in yes help needed
Hello,
I have this in the table: "value" type int 0 to represent false and 1 to represe

value not going in data base
hello friends....
i am having a working javascript....when i am selecting any

how to read and write into a word document using php...?
hi,
I need,reading and writting into a word document using php.




Thank u inadva

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash