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

Link to comment
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();"); }

 

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.