Jump to content

How to make URL loads only on login


LexHammer

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/185573-how-to-make-url-loads-only-on-login/
Share on other sites

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

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?

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();

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.