• Hello,I am using the wp function wp_signon and wp_logout to maintain the different users.The login process is successfully done but when i refresh the page the user is getting logged out automatically.I am writing the code in the header.php file.When i refresh the page the wp_logout function which is also on the same header.php file gets executed.The following is my code.Thanks in advance for all the help and advice.God bless you.

    <body>
    <div id="templatemo_container">
    <div id="templatemo_header">
        <div id="out_mission_section">
          <p>
                Lorem ipsum dolor sit amet, consec tetur adipi scing elit. Nullam sollici tudin libero. Maece nas posuere congue massa. <a>/subpage.html">more...</a>
          </p>
        </div>   
    
         <div id="daily_bible_verse_section">
            <p> Do to others as you would have them do to you. </p>
              <div id="bible_verse">Luke 6:31</div>
            </div>
         </div>
    
         <div id="templatemo_menu">
                 <?php wp_nav_menu(); ?>
                  <div id="statusbar">
                <table>
                <tr>
                <td>
                <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="aform" target="_top" >
                Login Id :<input type="text" name="log" id="log" value="" />
                Password :<input type="password" name="pwd" id="pwd" value="" />
                <input type="submit" name="login" value="Login" />
                <input type="reset" name="login" value="Reset" />
                </form>
                </td>
                <td width="100px" align="right">
                <label>Welcome : </label></td>
                <td width="150px"> <?php
    
    	    if(is_user_logged_in())
    	    {
    
    		$current_user = wp_get_current_user();
    		echo $current_user->user_login;
    	    }
    	    else
    	   {
    		echo "Guest";
    	   }
    	  ?>
            </td>
                <td width="100px" align="right">
              <form id="frmlogin" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
                <a>" onClick="<?php wp_logout();  ?>">Logout</a>
                </form>
                </td></tr>
                </table>
    
                </div>
                 <?php global $wpdb;
    			if($_POST['log'] != "" && $_POST['pwd'] != "")
    			{
    
    				$res=$wpdb->get_results('select * from login where uname="'.$_POST['log'].'" and pass="'.$_POST['pwd'].'"');
    
    			    if($wpdb->num_rows)
    				{
    					foreach($res as $result)
    					{
    
    						$credentials = array();
    			    		$credentials['user_login'] = $result->uname;
    			    		$credentials['user_password'] = $result->pass;
    			    		$credentials['remember'] = true;
    			    		$user = wp_signon( $credentials, false );
    						wp_redirect( home_url() ); exit;	
    
    					}
    			}
    
    			} ?>
        </div>

    [Please post code or markup between backticks or use the code button. Or better still – use a pastebin. Your posted code has now been permanently damaged/corrupted by the forum’s parser.]

The topic ‘Automatically getting logged out’ is closed to new replies.