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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshaykr
    New Member
    • Jan 2010
    • 1

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

    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:

    Code:
    <?php
    	session_start();
    ?>
    
    <html>
     <head>
    	
    	<title>
    		 My Profile
    	</title>
     </head>
     <body>
      <div  align=center>
    	<?php
    		include("header.php");
    		include("db_open.php");
    
    		printProfile();
    
    		include("db_close.php");
    		include("footer.php");
    	?>
       </div>
     </body>
    </html>
    
    <?php
    	function printProfile() {
    		if( isset($_SESSION['myusername']) ) {
    			$username = $_SESSION['myusername'];
    		}
    		else {
    			$username = '';
    		}
    
    		echo '<div class=centerfixed>';
    
    		echo '<table>';
    		echo '<tr>';
    		echo '<td >';
    
    		if( $username ) {
    			printProfileDetails( $username );
    		}
    		else {
    			echo '<p align=center><br/><br/>You are not logged in!!!';
    			echo '<a href="login.php">Please Login</a>';
    			echo '</p>';
    		}
    		echo '</td>';
    
    		echo '</tr>';
    		echo '</table>';
    
    		echo '</div>';
    	}
    
    	function printProfileDetails( $username ) {
    		$query = 'SELECT * FROM user_info WHERE USER_NAME="'.$username.'"';
    		$result = mysql_query( $query );
    		if( !$result ) {
    			die( "Could not query the database: <br/>".mysql_error() );
    		}
    		while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
    			$detail = $row['USER_NAME'];
    			echo '<table align=center class=display>';
    
    			echo '<tr class=header>';
    			echo '<th colspan=2>User Profile Details</th>';
    			echo '</tr>';
    
    			echo '<tr class=display>';
    			echo '<th class=display>&nbsp Username</th>';
    			echo '<td class=display>'.$detail.'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display1>';
    			echo '<th class=display>&nbsp Name</th>';
    			echo '<td class=display>'.$row['FIRST_NAME'].' '.$row['MIDDLE_NAME'].' '.$row['LAST_NAME'];
    			echo '</td>';
    			echo '</tr>';
    
    			echo '<tr class=display>';
    			echo '<th class=display>&nbsp Education</th>';
    			echo '<td class=display>'.$row['EDU_QUAL'].'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display1>';
    			echo '<th class=display>&nbsp Institute Name</th>';
    			echo '<td class=display>'.$row['INST_NAME'].'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display>';
    			echo '<th class=display>&nbsp Job Category</th>';
    			echo '<td class=display>'.$row['JOB_CATEGORY'].'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display1>';
    			echo '<th class=display>&nbsp Current Job Location</th>';
    			echo '<td class=display>'.$row['CURR_JOB_LOC'].'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display>';
    			echo '<th class=display>&nbsp Experience</th>';
    			echo '<td class=display>'.$row['EXPERIENCE'].'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display1 >';
    			echo '<th class=display>&nbsp Current CTC</th>';
    			echo '<td class=display>'.$row['CURRENT_CTC'].'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display>';
    			echo '<th class=display>&nbsp Expected CTC</th>';
    			echo '<td class=display>'.$row['EXPECTED_CTC'].'</td>';
    			echo '</tr>';
    
    			echo '<tr class=display1>';
    			echo '<th class=display>&nbsp Joining Time</th>';
    			echo '<td class=display>'.$row['JOINING_TIME'].'</td>';
    			echo '</tr>';
    
    
    			$contactid = $row['CONTACT_ID'];
    			$query   = "SELECT * FROM contact_info WHERE CONTACT_ID='$contactid'";
    			$result1 = mysql_query( $query );
    			if( !$result1 ) {
    				die( "Could not query the database: <br/>".mysql_error() );
    			}
    			$row1 = mysql_fetch_array($result1, MYSQL_ASSOC);
    			if( $row1 ) {
    				echo '<tr class=display>';
    				echo '<th class=display>&nbsp Address</th>';
    				echo '<td class=display>'.$row1['ADDRESS_1'].' '.$row1['ADDRESS_2'].' '.$row1['ADDRESS_3'];
    				echo '</td>';
    				echo '</tr>';
    
    				echo '<tr class=display1>';
    				echo '<th class=display>&nbsp City</th>';
    				echo '<td class=display>'.$row1['CITY'];
    				echo '</td>';
    				echo '</tr>';
    
    				echo '<tr class=display>';
    				echo '<th class=display>&nbsp State</th>';
    				echo '<td class=display>'.$row1['STATE'];
    				echo '</td>';
    				echo '</tr>';
    
    				echo '<tr class=display1>';
    				echo '<th class=display>&nbsp Country</th>';
    				echo '<td class=display>'.$row1['COUNTRY'];
    				echo '</td>';
    				echo '</tr>';
    
    				echo '<tr class=display>';
    				echo '<th class=display>&nbsp Pincode</th>';
    				echo '<td class=display>'.$row1['PINCODE'];
    				echo '</td>';
    				echo '</tr>';
    
    				echo '<tr class=display1>';
    				echo '<th class=display>&nbsp Phone</th>';
    				echo '<td class=display>'.$row1['PHONE_OFF_1'];
    				echo '</td>';
    				echo '</tr>';
    
    				echo '<tr class=display>';
    				echo '<th class=display>&nbsp Mobile</th>';
    				echo '<td class=display>'.$row1['MOBILE_1'];
    				echo '</td>';
    				echo '</tr>';
    
    				echo '<tr class=display1>';
    				echo '<th class=display>&nbsp EMail</th>';
    				echo '<td class=display>'.$row1['EMAIL_1'];
    				echo '</td>';
    				echo '</tr>';
    			}
    
    			echo '</table>';
    		}
    	}
    ?>
    Could anybody help me to find out the problem as to why the session gets expired?
    Thanking you in anticipation!
    Last edited by Dormilich; Jan 28 '10, 07:07 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    can’t see anything wrong with this code, maybe some of your session settings are causing it.

    Comment

    • dgreenhouse
      Recognized Expert Contributor
      • May 2008
      • 250

      #3
      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_tra ns_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?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Maybe a dumb question... Do you have cookies enabled?
        If not, is session.use_tra ns_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_tra ns_sid value.

        Comment

        • dgreenhouse
          Recognized Expert Contributor
          • May 2008
          • 250

          #5
          Originally posted by Dormilich
          if cookies are disabled, the session id is automaticly put in the URL, independently of the session.use_tra ns_sid value.
          Thanks... I thought with session.use_tra ns_sid disabled, the session data wouldn't be put in the URL when cookies are disabled... Hmmm...

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I only know that, because I explicitly make those settings in my website.

            Comment

            • kovik
              Recognized Expert Top Contributor
              • Jun 2007
              • 1044

              #7
              The problem could be caused elsewhere in your code. Do you have any other references to the session with session_* functions?

              Comment

              Working...