Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 2nd Apr 2012, 01:40 PM   #1
Active Warrior
 
PHPSpaZ's Avatar
 
Join Date: 2012
Location: Madisonville, Tennessee
Posts: 52
Thanks: 21
Thanked 0 Times in 0 Posts
Default
PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Hi guys. I'm back again with another issue that makes no sense at all... .
I set a $_SESSION var on one page starting the session on both pages that use the var. So not starting the session is not the problem. ANYWAY I set it on one page and print it just to be sure that it is set, and it is. THEN I redir to another page, start the session and check the var and it is empty!!! It works for me on IE but not on my buddys pc using IE... It also doesnt work on chrome on either pc. This is the code that sets the var. THIS ONE WORKS BECAUSE I CAN ECHO IT ON THIS PAGE:

//JUST AN EXCERPT
$pwd = $row['pwd'];
$prepass = md5($pass);
if($prepass == $pwd){
$yes = "yes";
$_SESSION['MNCADMINLI'] = $yes;
}
if ($_SESSION['MNCADMINLI'] == 'yes'){
echo $_SESSION['MNCADMINLI'];
}
//IT ECHOS JUST FINE HERE


----------------------------------------------------------------
//THIS IS THE SECOND PAGE

session_start();
if ($_SESSION['MNCADMINLI'] == 'yes'){
//A BUNCH OF TABLES
echo $_SESSION['MNCADMINLI'];
}
//THIS DOES NOT WORK...
----------------------------------------------------------------
Anybody got a clue?

Doing what I can to help those I can -Me
PHPSpaZ is offline  
Unread 2nd Apr 2012, 02:49 PM   #2
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

A session is a relationship between the user browser and the server. The data in the session is stored in a cookie in the browser. If cookies are disabled in the browser you will not have the session data stored between pages.

Earnie Boyd is offline  
The Following User Says Thank You to Earnie Boyd For This Useful Post:
Unread 2nd Apr 2012, 02:54 PM   #3
Active Warrior
 
PHPSpaZ's Avatar
 
Join Date: 2012
Location: Madisonville, Tennessee
Posts: 52
Thanks: 21
Thanked 0 Times in 0 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Originally Posted by Earnie Boyd View Post

A session is a relationship between the user browser and the server. The data in the session is stored in a cookie in the browser. If cookies are disabled in the browser you will not have the session data stored between pages.
Thats just it, All the browsers I have tested on have had cookies enabled... I was doing the same thing with a cookie b4 but its not good for our purposes and it wasnt working properly either. It was the same code except I set cookie and it printed on the first page, and just like with session storing it did not print on the second page. Are there any noticeable problems with the code that jump out to you?

Doing what I can to help those I can -Me
PHPSpaZ is offline  
Unread 2nd Apr 2012, 03:27 PM   #4
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Make sure you're not outputting any data before the session_start. Note that any blank lines before <?php is considered output to the browser. Also you might want to use session_id() function to determine if a session is started already and use ob_start() to make sure that nothing is output to the browser before the session_start(). See PHP: session_start - Manual for more but you've probably been there already. I don't see anything staring at me that is wrong.

Earnie Boyd is offline  
The Following User Says Thank You to Earnie Boyd For This Useful Post:
Unread 2nd Apr 2012, 03:39 PM   #5
Active Warrior
 
PHPSpaZ's Avatar
 
Join Date: 2012
Location: Madisonville, Tennessee
Posts: 52
Thanks: 21
Thanked 0 Times in 0 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Thanks again, I def made sure there is not even so much as a pixel after <? and before session_start(); Ill try the session id and echo it.

Doing what I can to help those I can -Me
PHPSpaZ is offline  
Unread 2nd Apr 2012, 04:49 PM   #6
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Originally Posted by PHPSpaZ View Post

Thanks again, I def made sure there is not even so much as a pixel after <? and before session_start(); Ill try the session id and echo it.
Make sure there is nothing BEFORE the <?php in your file.

In addition to checking the session_id, probably the easiest way to see the contents is to dump the variable:

var_dump( $_SESSION );

You'll be able to see what's there and what isn't.

Do you have error display on so you can catch notices and such?

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
Unread 2nd Apr 2012, 05:23 PM   #7
Active Warrior
 
PHPSpaZ's Avatar
 
Join Date: 2012
Location: Madisonville, Tennessee
Posts: 52
Thanks: 21
Thanked 0 Times in 0 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Yeah, the top of the page before any information is sent is where I am starting the sessions. Im posting the whole code. Login page, process page, and display page.
-------------------------------------------------------------------------------------------
//login

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<center>
<form name="viewleads" action="http://www.mynewcity.com/adminliprocess.php" method="post">
E-Mail:<input type="text" name="email" id="email" /></br>
Password:<input type="password" name="pass" id="pass" /></br>
<input type="submit" id="submit" value="Log In" />
</form>
</center>
</body>
</html>

----------------------------------------------------------------------------------------
//process

<?
session_start();
function ticket_connect() {
$db_host = "NOTSHOWINGUTHIS";
$db_user = "NOTSHOWINGUTHIS";
$db_password ="NOTSHOWINGUTHIS";
$db_name = "NOTSHOWINGUTHIS";
//create database connection
$connection = @mysql_connect($db_host,$db_user,$db_password);
//if there is no connection then display a message letting the user know.
if($connection) {
@mysql_select_db($db_name, $connection);
}
else{
echo "ERROR!! Could not connect to the database at this time, we are sorry for the inconvenience. Please try again later.";
}
} // end function db_connect()
?>
<?
ticket_connect();
$result = mysql_query("SELECT email, pwd FROM administrators WHERE email='$email'") or die(mysql_error());
$row = mysql_fetch_array($result);
$pwd = $row['pwd'];
$prepass = md5($pass);
if($prepass == $pwd){
$yes = "yes";
$_SESSION['MNCADMINLI'] = $yes;
}
if ($_SESSION['MNCADMINLI'] == 'yes'){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<script type="text/javascript">
window.location="http://mynewcity.com/adminassignment.php";
</script>

<? } else {
echo "<center>Sorry, LOGIN FAILED! Please <a href='http://mynewcity.com/adminlogin.php'>CLICK HERE</a> to return and try again.</center>";
echo "***PWD**";
echo $pwd;
echo "***PREPASS***";
echo $prepass;
echo "***RESULT***";
echo $result;
echo "***ROW***";
echo $row;
echo "***EMAIL***";
echo $row['email'];
echo "***DBPWD***";
echo $row['pwd'];
echo "***RUHERE***";
echo $_SESSION['MNCADMINLI'];
//THIS ECHO WORKS!!!
}
?>
</body>
</html>

---------------------------------------------------------------------------------------
//Display

<?
session_start();
if ($_SESSION['MNCADMINLI'] == 'yes'){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Assignment Op Center</title>
</head>
<body>

<?
function ticket_connect() {
$db_host = "NOTSHOWINGUTHIS";
$db_user = "NOTSHOWINGUTHIS";
$db_password = "NOTSHOWINGUTHIS";
$db_name = "NOTSHOWINGUTHIS";
//create database connection
$connection = @mysql_connect($db_host,$db_user,$db_password);
//if there is no connection then display a message letting the user know.
if($connection) {
@mysql_select_db($db_name, $connection);
}
else{
echo "ERROR!! Could not connect to the database at this time, we are sorry for the inconvenience. Please try again later.";
}
} // end function db_connect()

ticket_connect();

$result = mysql_query("SELECT ticketID,created,lead_status,subject,lo_franchise, email,name,lead_email,lead_name FROM mynewci_ticket") or die(mysql_error());
$numrows= mysql_num_rows($result);
echo "<center><bold>There are $numrows leads in the system</bold></center>";
echo "<table id='tickettable' border='1'>";
echo "<th>Ticket Number</th><th>Capture Date</th><th>Status</th><th>Subject</th><th>Franchise</th><th>Lead Owner</th><th>Owner Name</th><th>Lead Email</th><th>Lead Name</th><th>Submit</th>";


$i = 0;

while($row = mysql_fetch_array( $result )) {

if($i <= $numrows){
$ticketID = $row['ticketID'];
$created = $row['created'];
$subject = $row['subject'];
$lo_franchise = $row['lo_franchise'];
$lo_email = $row['email'];
$lo_name = $row['name'];
$lead_email = $row['lead_email'];
$lead_name = $row['lead_name'];
$status = $row['lead_status'];
$oh = "id='$i'";
$on = "name='$i'";
$selstatus = "<form method='post' '$oh' '$on' action='http://mynewcity.com/assignleads.php'><tr><td>$ticketID</td><td>$created</td><td>$status</td><td>$subject</td><td>$lo_franchise</td><td>'$lo_email'</td><td>'$lo_name'</td><td>'$lead_email'</td><td>'$lead_name'</td><td><input type='hidden' name='ticketID' value='$ticketID'><input type='submit' name='doit' value='Assign Lead'></form></td></tr>";


// Print out the contents of each row into a table
echo $selstatus;
$i++;
}
}

}
echo "</table>";
?>
</body>
</html>

Doing what I can to help those I can -Me
PHPSpaZ is offline  
Unread 2nd Apr 2012, 07:18 PM   #8
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Originally Posted by Earnie Boyd View Post

The data in the session is stored in a cookie in the browser. If cookies are disabled in the browser you will not have the session data stored between pages.
Normally, only the ID of the session is stored in a cookie. The actual session data is stored on the server.

But it's possible to create a session without relying on cookies at all, by passing the session ID via a query string in the URL...

PHP: Passing the Session ID - Manual


Brandon Tanner is offline  
Unread 3rd Apr 2012, 12:36 AM   #9
Warrior Member
 
Join Date: 2012
Posts: 15
Thanks: 0
Thanked 3 Times in 2 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

check '$prepass = md5($pass);'
$pass = .....
maybe you forget to delcalre $pass
baronz is offline  
Unread 3rd Apr 2012, 12:52 AM   #10
Active Warrior
 
PHPSpaZ's Avatar
 
Join Date: 2012
Location: Madisonville, Tennessee
Posts: 52
Thanks: 21
Thanked 0 Times in 0 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Originally Posted by baronz View Post

check ' = md5();'
= .....
maybe you forget to delcalre
nope, it comes via post from the login page. It is in the code above.

Doing what I can to help those I can -Me
PHPSpaZ is offline  
Unread 3rd Apr 2012, 12:59 AM   #11
Warrior Member
 
Join Date: 2012
Posts: 15
Thanks: 0
Thanked 3 Times in 2 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

ouw sorry, my bad..
cause i don't see $pass = $_POST['pass'];
baronz is offline  
Unread 3rd Apr 2012, 06:38 AM   #12
HyperActive Warrior
War Room Member
 
Earnie Boyd's Avatar
 
Join Date: 2012
Posts: 290
Thanks: 13
Thanked 46 Times in 46 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

//process

<?
session_start();
Is this how the beginning of the file looks?

It should look more like

<?php
//process

session_start();

Earnie Boyd is offline  
Unread 3rd Apr 2012, 10:32 AM   #13
Warrior Member
 
Join Date: 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Try this link for some help with this issue - cmshelplive.com
CMSBunny is offline  
Unread 3rd Apr 2012, 03:28 PM   #14
Active Warrior
 
PHPSpaZ's Avatar
 
Join Date: 2012
Location: Madisonville, Tennessee
Posts: 52
Thanks: 21
Thanked 0 Times in 0 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Originally Posted by Earnie Boyd View Post

Is this how the beginning of the file looks?

It should look more like
No Earnie. I just put the space in there to make it easier to read. Absolutely nothing other than the php tag before the session_start();
And for Bunny, I am not willing to pay for help atm, I tried several services a week or so ago and was HIGHLY disappointed in the help I received. The people here are VERY smart and perfectly willing to help so Im gonna stick with them. Thanks for the info though, it may come in handy one day!

On another note, I called our hosting provider and they looked over my code only to tell me that it was well written, but not perfect, yet they saw no way that my code was the issue... They also checked every server log, NOTHING IS WRONG!!! I dont understand how my code validates -- AND there is no problem with the cloud server -- AND I know my browsers are set up correctly for this. I was stuck on this for a week before I even posted this and now I'm simply looking for a new method of authenticating...
Any Ideas?

Doing what I can to help those I can -Me
PHPSpaZ is offline  
Unread 3rd Apr 2012, 04:50 PM   #15
Warrior Extremist
 
xrampage16's Avatar
 
Join Date: 2012
Location: Orange, CA
Posts: 38
Thanks: 0
Thanked 4 Times in 4 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Are you absolutely sure that your browser is not at fault, or any anti-spam software? I would first check out using other browsers, and making sure that you have the most up to date browsers. Try Firefox and Chrome first, as they seem to be most able to work the best with things like "sessions". Also, aside from that, check that you have cookies and javascript turned on. I know that that is a stupid suggestion, but you might have heightened security on one of those controls which is preventing you the information from passing between pages.

Also, if you are still running into issues, remove all the content you are trying to pass, and make sure you can pass something like "test" between pages. If you are able to pass "test" successfully, then you might have an issue with the wrapping and unwrapping of the content, or you are using a character which is throwing everything off. At that point, you just need to drill down into the content until you find the culprit, and either convert it into something else, or remove it entirely.

Hope that helps.

Developer and Admin for Komputer King LLC hosting - Offering lightning fast web hosting and Quality Backlink Building
xrampage16 is offline  
Unread 4th Apr 2012, 12:43 AM   #16
Warrior Member
 
Join Date: 2012
Posts: 15
Thanks: 0
Thanked 3 Times in 2 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

do you have access to php.ini file?
if you do, this might help:
support.qualityunit.com/021373-How-To-Enable-Session-Support-for-PHP
baronz is offline  
Unread 5th Apr 2012, 01:22 PM   #17
HyperActive Warrior
War Room Member
 
Big Squid's Avatar
 
Join Date: 2009
Location: Living between LA & SD
Posts: 205
Thanks: 27
Thanked 36 Times in 33 Posts
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

I checked the code from your original post, and it works for me. I'm wondering if it has something to do with the JS redirect that's happening. I don't know why, but maybe you could check.
Big Squid is offline  
Unread 5th Apr 2012, 05:40 PM   #18
Active Warrior
 
PHPSpaZ's Avatar
 
Join Date: 2012
Location: Madisonville, Tennessee
Posts: 52
Thanks: 21
Thanked 0 Times in 0 Posts
Lightbulb
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

Originally Posted by Big Squid View Post

I checked the code from your original post, and it works for me. I'm wondering if it has something to do with the JS redirect that's happening. I don't know why, but maybe you could check.
It was actually a strange thing that took a long time to figure out and makes no sense whatsoever. My sessions would not store text info inside the session vars and pass them from the login process page to the actual content page after login was successful. I had to take out the session vars and use post data instead..... NOT JUST THAT but the data that I was passing via host WOULD NOT pass between the two pages if it was text
ie.
$_SESSION['MNCADMINLI'] = "THISTEXT";
Instead I had to use JS to send post data for authentication... Here is the working version...:

* indicates new page

************************************************** ******
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administrator Login</title>
</head>

<body>
<center>
<form name="viewleads" action="http://www.mynewcity.com/adminliprocess.php" method="post">
E-Mail:<input type="text" name="email" id="email" /></br>
Password:<input type="password" name="pass" id="pass" /></br>
<input type="submit" id="submit" value="Log In" />
</form>
</center>
</body>
</html>
************************************************** *******
<?
session_start();
?>
<?
include "func.php";
ticket_connect();
$result = mysql_query("SELECT email, pwd FROM administrators WHERE email='$email'") or die(mysql_error());
$row = mysql_fetch_array($result);
$pwd = $row['pwd'];
$prepass = md5($pass);

$pwtest = yup($prepass,$pwd);

if ($pwtest == true){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Processing Area Video Leads</title>
</head>

<body>
<form id="pwtesting" action="" method="">
<input type="hidden" id="pwtest" value="" />
<script type="text/javascript">
window.location="http://mynewcity.com/adminassignment.php?pwtest=<? echo $pwtest; ?>";
</script>
<?
} else {
echo "<center>Sorry, LOGIN FAILED! Please <a href='http://mynewcity.com/adminlogin.php'>CLICK HERE</a> to return and try again.</center>";
echo "***PWD**";
echo $pwd;
echo "***PREPASS***";
echo $prepass;
echo "***RESULT***";
echo $result;
echo "***ROW***";
echo $row;
echo "***EMAIL***";
echo $row['email'];
echo "***DBPWD***";
echo $row['pwd'];
echo "***RUHERE***";
echo $pwtest;

}
?>
</body>
</html>
************************************************** *******
<?
session_start();
include "func.php";
?>
<?
if ($pwtest == true){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Assignment Operations Center</title>
</head>
<body>

<?
ticket_connect();
$result = mysql_query("SELECT ticketID,created,lead_status,subject,lo_franchise, email,name,lead_email,lead_name FROM mynewci_ticket") or die(mysql_error());
$numrows= mysql_num_rows($result);

echo "<center><bold>There are $numrows leads in the system</bold></center>";
echo "<table id='tickettable' border='1'>";
echo "<th>Ticket Number</th><th>Capture Date</th><th>Status</th><th>Subject</th><th>Franchise</th><th>Lead Owner</th><th>Owner Name</th><th>Lead Email</th><th>Lead Name</th><th>Submit</th>";

$i = 0;

while($row = mysql_fetch_array( $result )) {

if($i <= $numrows){
$ticketID = $row['ticketID'];
$created = $row['created'];
$subject = $row['subject'];
$lo_franchise = $row['lo_franchise'];
$lo_email = $row['email'];
$lo_name = $row['name'];
$lead_email = $row['lead_email'];
$lead_name = $row['lead_name'];
$status = $row['lead_status'];
$oh = "id='$i'";
$on = "name='$i'";
$selstatus = "<form method='post' '$oh' '$on' action='http://mynewcity.com/assignleads.php'><tr><td>$ticketID</td><td>$created</td><td>$status</td><td>$subject</td><td>$lo_franchise</td><td>'$lo_email'</td><td>'$lo_name'</td><td>'$lead_email'</td><td>'$lead_name'</td><td><input type='hidden' name='ticketID' value='$ticketID'><input type='submit' name='doit' value='Assign Lead'></form></td></tr>";


// Print out the contents of each row into a table
echo $selstatus;
$i++;
}
}

} else {
echo "HELLO";
echo $pwtest;
}
echo "</table>";
?>
</body>
</html>
************************************************** *******
And that was it.... Works fine... I see massive quantities of AJAX training in my future

Doing what I can to help those I can -Me
PHPSpaZ is offline  
Unread 5th Apr 2012, 08:10 PM   #19
Geo
War Room Member
 
IM-software's Avatar
 
Join Date: 2010
Location: France
Posts: 24
Thanks: 14
Thanked 4 Times in 3 Posts
Blog Entries: 1
Default
Re: PHP Session data not passing!!!
Share on: 
fb share twitter share gplus share more share

At first check how session.auto_start is set up in your php.ini

session.auto_start = 1 |||| means no need to use session_start();

if you use session.auto_start = 0 try: <?php session_start(); ?>
At the very top of your file.

instead of

<?php
session_start();
?>

Make sure that you have:

session.cookie_lifetime = 0 |||| zero means: until browser is restarted
session.use_cookies = 1
session.use_only_cookies = 1 |||| as a protection

Restart apache

IM-software is offline  
Closed Thread


Bookmarks

Tags
data, passing, php, session


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:19 PM.