![]() |
PHP Session data not passing!!! Hi guys. I'm back again with another issue that makes no sense at all... :D. 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? |
Re: PHP Session data not passing!!! 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. |
Re: PHP Session data not passing!!! Quote:
|
Re: PHP Session data not passing!!! 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. |
Re: PHP Session data not passing!!! 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. |
Re: PHP Session data not passing!!! Quote:
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? |
Re: PHP Session data not passing!!! 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> |
Re: PHP Session data not passing!!! Quote:
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 |
Re: PHP Session data not passing!!! check '$prepass = md5($pass);' $pass = ..... maybe you forget to delcalre $pass |
Re: PHP Session data not passing!!! Quote:
|
Re: PHP Session data not passing!!! ouw sorry, my bad.. cause i don't see $pass = $_POST['pass']; |
Re: PHP Session data not passing!!! Quote:
It should look more like Quote:
|
Re: PHP Session data not passing!!! Try this link for some help with this issue - cmshelplive.com |
Re: PHP Session data not passing!!! Quote:
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? |
Re: PHP Session data not passing!!! 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. |
Re: PHP Session data not passing!!! 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 |
Re: PHP Session data not passing!!! 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. |
Re: PHP Session data not passing!!! Quote:
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 :D |
Re: PHP Session data not passing!!! 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 |
| All times are GMT -6. The time now is 04:31 PM. |