aztec Posted January 23, 2008 Share Posted January 23, 2008 Hello Is it possible using PHP to redirect a user after login='true to a protected page and login='false' to a public page without them having to click a link. I would like to implement this automatic option into my login script. I would also like to thank Fyorl and Revraz for the help and advice they gave that enabled me to wright this script. Regards Quote Link to comment https://forums.phpfreaks.com/topic/87415-solved-page-re-direct/ Share on other sites More sharing options...
runnerjp Posted January 23, 2008 Share Posted January 23, 2008 i use variables so define ( "REDIRECT_AFTER_LOGIN", "http://www.site.com); // - where should we redirect members after logging in? so my login function would look summat like <?php session_start(); require_once ( 'settings.php' ); if ( array_key_exists ( '_submit_check', $_POST ) ) { if ( $_POST['username'] != '' && $_POST['password'] != '' ) { $query = 'SELECT ID, ect ' . DBPREFIX . 'users WHERE Username = ' . $db->qstr ( $_POST['username'] ) . ' AND Password = ' . $db->qstr ( md5 ( $_POST['password'] ) ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); if ( $row->Active == 1 ) { set_login_sessions ( $row->ID, $row->Password, ( $_POST['remember'] ) ? TRUE : FALSE ); header ( "Location: " . REDIRECT_AFTER_LOGIN ); } elseif ( $row->Active == 0 ) { $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link.'; } elseif ( $row->Active == 2 ) { $error = 'You are suspended!'; } } else { $error = 'Login failed!'; } } else { $error = 'Please use both your username and password to access your account'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87415-solved-page-re-direct/#findComment-447117 Share on other sites More sharing options...
$username Posted January 23, 2008 Share Posted January 23, 2008 With a combo of an if statement and header("Location: http://$host$uri/$extra"); it should be easy for you Example If ($login == 1){ ("Location: yourpage.php"); }else{ ("Location: notyour.php"); } Brett Quote Link to comment https://forums.phpfreaks.com/topic/87415-solved-page-re-direct/#findComment-447128 Share on other sites More sharing options...
aztec Posted January 23, 2008 Author Share Posted January 23, 2008 Hello Thanks to you both for your input. I will try to code each option to see which one works best for me. I will mark it as solved, but I may have return to the subject later. Regards Quote Link to comment https://forums.phpfreaks.com/topic/87415-solved-page-re-direct/#findComment-447172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.