LexHammer Posted December 18, 2009 Share Posted December 18, 2009 On my page, when a user login he's redirects to user_home.php. I made it also to open the chat screen when the user login. This is the code: // USER IS LOGGED IN, FORWARD TO USER HOME if( $user->user_exists ) { header("Location: user_home.php"); header("javascript:launchChat();"); exit(); } The problem is that every time, the user open user_home.php, the chat screen reloads (the user is loged out and loged in to the chat). How to make the chat screen loads ONLY THE FIRST time, when the user login? Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/ Share on other sites More sharing options...
teynon Posted December 18, 2009 Share Posted December 18, 2009 I dont know if you are using sessions or what, but when a user logs in, create a session variable or cookie like so $_SESSION['newLogin']=1; Then on the other pages do this: if ($_SESSION['newLogin']==1) { $_SESSION['newLogin']=0; header("javascript:launchChat();"); } Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/#findComment-979722 Share on other sites More sharing options...
LexHammer Posted December 18, 2009 Author Share Posted December 18, 2009 I dont know if you are using sessions or what, but when a user logs in, create a session variable or cookie like so $_SESSION['newLogin']=1; Then on the other pages do this: if ($_SESSION['newLogin']==1) { $_SESSION['newLogin']=0; header("javascript:launchChat();"); } Yes, i use sessions. But which page is "the other page" ? The code i gave is from login.php. The page that is is opened after login is user_home.php Which code should go where? I guess the code in login.php should looks like // USER IS LOGGED IN, FORWARD TO USER HOME if( $user->user_exists ) { header("Location: user_home.php"); if ($_SESSION['newLogin']==1) { $_SESSION['newLogin']=0; header("javascript:launchChat();"); } exit(); } Am i wrong? Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/#findComment-979736 Share on other sites More sharing options...
teynon Posted December 18, 2009 Share Posted December 18, 2009 Ok, on your login page, it is setting the session variables. So set $_SESSION['newLogin']=1; on the session page where you would log in. The login page should forward the user to a different page. On that page, do this: if ($_SESSION['newLogin']==1) { $_SESSION['newLogin']=0; header("javascript:launchChat();"); } Now, i'm not positive, but i'm pretty sure that if you send header("Location: blah.html"); and you are not buffering your output, it will immediately redirect that page. This means that anything that follows will not be processed. So you have to send that command before your send the header location command. Because I'm not positive that that is true, I also follow up a header("Location: blah"); with a die(); Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/#findComment-980131 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 $_SESSION[variable] = "thisisone"; more efieciant Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/#findComment-980134 Share on other sites More sharing options...
LexHammer Posted December 19, 2009 Author Share Posted December 19, 2009 Not working... nothing happens. I found this code in the login, which i have forgoten that is threre, which is for a "getting started" wizard, that guides you only the first time when you login to the page. This is the code // CHECK FOR REDIRECTION URL if(isset($_POST['return_url'])) { $return_url = $_POST['return_url']; } elseif(isset($_GET['return_url'])) { $return_url = $_GET['return_url']; } else { $return_url = ""; } $return_url = urldecode($return_url); $return_url = str_replace("&", "&", $return_url); if($return_url == "") { $return_url = "user_home_started.php"; } Can this be modified to work with the chat, but to apply every time on login, not just the first time? Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/#findComment-980476 Share on other sites More sharing options...
LexHammer Posted December 19, 2009 Author Share Posted December 19, 2009 Anybody???? Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/#findComment-980559 Share on other sites More sharing options...
LexHammer Posted December 21, 2009 Author Share Posted December 21, 2009 ?????? Quote Link to comment https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/#findComment-981410 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.