PHP Session data not passing!!!

by 18 replies
22
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?
#programming #data #passing #php #session
  • 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.
    • [ 1 ] Thanks
    • [2] replies
    • 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?
    • 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
  • 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.
    • [ 1 ] Thanks
    • [1] reply
    • 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.
      • [1] reply
  • check '$prepass = md5($pass);'
    $pass = .....
    maybe you forget to delcalre $pass
    • [1] reply
    • nope, it comes via post from the login page. It is in the code above.
  • ouw sorry, my bad..
    cause i don't see $pass = $_POST['pass'];
  • Is this how the beginning of the file looks?

    It should look more like

    • [1] reply
    • 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?
  • Try this link for some help with this issue - cmshelplive.com
  • 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.
  • Banned
    [DELETED]
  • 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
  • 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.
    • [1] reply
    • 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
  • 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

Next Topics on Trending Feed

  • 22

    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: