al3x8730 Posted August 22, 2008 Share Posted August 22, 2008 I run a great website (although new) called IM Share @ http://imshare.us.to But I have a problem, when you log in there's no redirection to the home page, so if you're in like IE and you click on another tab, you just get logged out. So I'll post my log in PHP file, and could you please help me add a redirection to the home page or something that won't log me out? php log in file: <?php // config include_once "../config.php"; // controllers switch($_REQUEST['action']) { case 'submit': if($member_id = verifyLogin($_REQUEST['email'], $_REQUEST['password'])) { $messages = array("return" => "success", "message" => "Successfully signed into your account!"); // set session hash $member = getMemberById($member_id); $_SESSION['sessionhash'] = ( sha1( $member['id'] ) . sha1( $member['password_salt'] ) . sha1( SESSION_SALT ) ); } else { $messages = array("return" => "error", "message" => "You provided incorrect details"); } $smarty->assign("messages", $messages); break; default: // show register form } // view $smarty->display( "login.tpl" ); ?> Link to comment https://forums.phpfreaks.com/topic/120904-redirection-help-please/ Share on other sites More sharing options...
Fadion Posted August 22, 2008 Share Posted August 22, 2008 Probably it's me, but i don't get the "new tab and logout" part. Anyway, you can redirect the user using header() or meta refresh. The header() must be used before any output is sent to the browser, meaning no html or echo before it. Write this after you authenticate the user login and set the session variable. <?php header('Location: page.php'); ?> or use the meta refresh: <?php echo '<meta http-equiv="refresh" content="0;url=page.php">'; ?> Link to comment https://forums.phpfreaks.com/topic/120904-redirection-help-please/#findComment-623273 Share on other sites More sharing options...
al3x8730 Posted August 22, 2008 Author Share Posted August 22, 2008 Probably it's me, but i don't get the "new tab and logout" part. Anyway, you can redirect the user using header() or meta refresh. The header() must be used before any output is sent to the browser, meaning no html or echo before it. Write this after you authenticate the user login and set the session variable. <?php header('Location: page.php'); ?> or use the meta refresh: <?php echo '<meta http-equiv="refresh" content="0;url=page.php">'; ?> I'm kind of new to this stuff, but I'm trying to learn, where exactly would I put that. I already looked that up and tried something like and, but I probably put it in the wrong spot. Help? Link to comment https://forums.phpfreaks.com/topic/120904-redirection-help-please/#findComment-623275 Share on other sites More sharing options...
Fadion Posted August 22, 2008 Share Posted August 22, 2008 Did you write that code or you just found it. I'm asking as if did, you should know where to put it. Anyway, the idea is to place the redirect code where the you want the script execution to end. Your code uses smarty so I'm not really sure what's happening there. It should be after you display the successful login message (you should use meta refresh), or just get rid of the message and do a redirect immediately after you set the session. <?php $_SESSION['sessionhash'] = ( sha1( $member['id'] ) . sha1( $member['password_salt'] ) . sha1( SESSION_SALT ) ); header('Location: page.php'); ?> Link to comment https://forums.phpfreaks.com/topic/120904-redirection-help-please/#findComment-623284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.