By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

the session gets expired in the php after login by the users!

P: 1
Hi Friends, Please help me on the following:
1. the session gets expired in the php after login by the users!

Iam using the code as follow:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     session_start();
  3. ?>
  4.  
  5. <html>
  6.  <head>
  7.  
  8.     <title>
  9.          My Profile
  10.     </title>
  11.  </head>
  12.  <body>
  13.   <div  align=center>
  14.     <?php
  15.         include("header.php");
  16.         include("db_open.php");
  17.  
  18.         printProfile();
  19.  
  20.         include("db_close.php");
  21.         include("footer.php");
  22.     ?>
  23.    </div>
  24.  </body>
  25. </html>
  26.  
  27. <?php
  28.     function printProfile() {
  29.         if( isset($_SESSION['myusername']) ) {
  30.             $username = $_SESSION['myusername'];
  31.         }
  32.         else {
  33.             $username = '';
  34.         }
  35.  
  36.         echo '<div class=centerfixed>';
  37.  
  38.         echo '<table>';
  39.         echo '<tr>';
  40.         echo '<td >';
  41.  
  42.         if( $username ) {
  43.             printProfileDetails( $username );
  44.         }
  45.         else {
  46.             echo '<p align=center><br/><br/>You are not logged in!!!';
  47.             echo '<a href="login.php">Please Login</a>';
  48.             echo '</p>';
  49.         }
  50.         echo '</td>';
  51.  
  52.         echo '</tr>';
  53.         echo '</table>';
  54.  
  55.         echo '</div>';
  56.     }
  57.  
  58.     function printProfileDetails( $username ) {
  59.         $query = 'SELECT * FROM user_info WHERE USER_NAME="'.$username.'"';
  60.         $result = mysql_query( $query );
  61.         if( !$result ) {
  62.             die( "Could not query the database: <br/>".mysql_error() );
  63.         }
  64.         while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
  65.             $detail = $row['USER_NAME'];
  66.             echo '<table align=center class=display>';
  67.  
  68.             echo '<tr class=header>';
  69.             echo '<th colspan=2>User Profile Details</th>';
  70.             echo '</tr>';
  71.  
  72.             echo '<tr class=display>';
  73.             echo '<th class=display>&nbsp Username</th>';
  74.             echo '<td class=display>'.$detail.'</td>';
  75.             echo '</tr>';
  76.  
  77.             echo '<tr class=display1>';
  78.             echo '<th class=display>&nbsp Name</th>';
  79.             echo '<td class=display>'.$row['FIRST_NAME'].' '.$row['MIDDLE_NAME'].' '.$row['LAST_NAME'];
  80.             echo '</td>';
  81.             echo '</tr>';
  82.  
  83.             echo '<tr class=display>';
  84.             echo '<th class=display>&nbsp Education</th>';
  85.             echo '<td class=display>'.$row['EDU_QUAL'].'</td>';
  86.             echo '</tr>';
  87.  
  88.             echo '<tr class=display1>';
  89.             echo '<th class=display>&nbsp Institute Name</th>';
  90.             echo '<td class=display>'.$row['INST_NAME'].'</td>';
  91.             echo '</tr>';
  92.  
  93.             echo '<tr class=display>';
  94.             echo '<th class=display>&nbsp Job Category</th>';
  95.             echo '<td class=display>'.$row['JOB_CATEGORY'].'</td>';
  96.             echo '</tr>';
  97.  
  98.             echo '<tr class=display1>';
  99.             echo '<th class=display>&nbsp Current Job Location</th>';
  100.             echo '<td class=display>'.$row['CURR_JOB_LOC'].'</td>';
  101.             echo '</tr>';
  102.  
  103.             echo '<tr class=display>';
  104.             echo '<th class=display>&nbsp Experience</th>';
  105.             echo '<td class=display>'.$row['EXPERIENCE'].'</td>';
  106.             echo '</tr>';
  107.  
  108.             echo '<tr class=display1 >';
  109.             echo '<th class=display>&nbsp Current CTC</th>';
  110.             echo '<td class=display>'.$row['CURRENT_CTC'].'</td>';
  111.             echo '</tr>';
  112.  
  113.             echo '<tr class=display>';
  114.             echo '<th class=display>&nbsp Expected CTC</th>';
  115.             echo '<td class=display>'.$row['EXPECTED_CTC'].'</td>';
  116.             echo '</tr>';
  117.  
  118.             echo '<tr class=display1>';
  119.             echo '<th class=display>&nbsp Joining Time</th>';
  120.             echo '<td class=display>'.$row['JOINING_TIME'].'</td>';
  121.             echo '</tr>';
  122.  
  123.  
  124.             $contactid = $row['CONTACT_ID'];
  125.             $query   = "SELECT * FROM contact_info WHERE CONTACT_ID='$contactid'";
  126.             $result1 = mysql_query( $query );
  127.             if( !$result1 ) {
  128.                 die( "Could not query the database: <br/>".mysql_error() );
  129.             }
  130.             $row1 = mysql_fetch_array($result1, MYSQL_ASSOC);
  131.             if( $row1 ) {
  132.                 echo '<tr class=display>';
  133.                 echo '<th class=display>&nbsp Address</th>';
  134.                 echo '<td class=display>'.$row1['ADDRESS_1'].' '.$row1['ADDRESS_2'].' '.$row1['ADDRESS_3'];
  135.                 echo '</td>';
  136.                 echo '</tr>';
  137.  
  138.                 echo '<tr class=display1>';
  139.                 echo '<th class=display>&nbsp City</th>';
  140.                 echo '<td class=display>'.$row1['CITY'];
  141.                 echo '</td>';
  142.                 echo '</tr>';
  143.  
  144.                 echo '<tr class=display>';
  145.                 echo '<th class=display>&nbsp State</th>';
  146.                 echo '<td class=display>'.$row1['STATE'];
  147.                 echo '</td>';
  148.                 echo '</tr>';
  149.  
  150.                 echo '<tr class=display1>';
  151.                 echo '<th class=display>&nbsp Country</th>';
  152.                 echo '<td class=display>'.$row1['COUNTRY'];
  153.                 echo '</td>';
  154.                 echo '</tr>';
  155.  
  156.                 echo '<tr class=display>';
  157.                 echo '<th class=display>&nbsp Pincode</th>';
  158.                 echo '<td class=display>'.$row1['PINCODE'];
  159.                 echo '</td>';
  160.                 echo '</tr>';
  161.  
  162.                 echo '<tr class=display1>';
  163.                 echo '<th class=display>&nbsp Phone</th>';
  164.                 echo '<td class=display>'.$row1['PHONE_OFF_1'];
  165.                 echo '</td>';
  166.                 echo '</tr>';
  167.  
  168.                 echo '<tr class=display>';
  169.                 echo '<th class=display>&nbsp Mobile</th>';
  170.                 echo '<td class=display>'.$row1['MOBILE_1'];
  171.                 echo '</td>';
  172.                 echo '</tr>';
  173.  
  174.                 echo '<tr class=display1>';
  175.                 echo '<th class=display>&nbsp EMail</th>';
  176.                 echo '<td class=display>'.$row1['EMAIL_1'];
  177.                 echo '</td>';
  178.                 echo '</tr>';
  179.             }
  180.  
  181.             echo '</table>';
  182.         }
  183.     }
  184. ?>
Could anybody help me to find out the problem as to why the session gets expired?
Thanking you in anticipation!
Jan 28 '10 #1
Share this Question
Share on Google+
6 Replies


Dormilich
Expert Mod 5K+
P: 8,639
can’t see anything wrong with this code, maybe some of your session settings are causing it.
Jan 28 '10 #2

dgreenhouse
Expert 100+
P: 250
I'm assuming that this is the code that's run after login.php is already run...

Maybe a dumb question... Do you have cookies enabled?
If not, is session.use_trans_sid turned on? Although that's a security risk.

Are you handling the setting up of the Session properly in login.php?

Why don't you post the relevant parts of login.php?
Jan 28 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
Maybe a dumb question... Do you have cookies enabled?
If not, is session.use_trans_sid turned on? Although that's a security risk.
if cookies are disabled, the session id is automaticly put in the URL, independently of the session.use_trans_sid value.
Jan 28 '10 #4

dgreenhouse
Expert 100+
P: 250
@Dormilich
Thanks... I thought with session.use_trans_sid disabled, the session data wouldn't be put in the URL when cookies are disabled... Hmmm...
Jan 28 '10 #5

Dormilich
Expert Mod 5K+
P: 8,639
I only know that, because I explicitly make those settings in my website.
Jan 28 '10 #6

kovik
Expert 100+
P: 1,044
The problem could be caused elsewhere in your code. Do you have any other references to the session with session_* functions?
Jan 28 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.