Jump to content

Page Redirect After Login


unemployment

Recommended Posts

I have written some php that forces login before accessing certain pages on my site.  When a user sends an private message to another user, they are notified via email.  In the email they can then click the view message link to take them right to the message, but if they aren't logged in they are sent to the login page.  I'd like them to be redirected to the message after logging in, but I'm getting a php error.

 

This is currently working for URL's like: domain.com/known-bugs

 

Does NOT work: http://domain.com/messaging?action=read&cid=130&utm_source=new_message&utm_medium=email&utm_campaign=direct_mesage_link

 

I think the query string is a problem in the script. To create this login feature. I am using...

 

$login = array(
'blogadd',
'messaging',
'company-settings',
'company-landing',
'company-create',
'company-join',
'account-settings',
'logout',
'home',
'newsadd',
'partnerRequest',
'known-bugs',
'reminders'
);

$page = substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4);

if (in_array($page, $login))
{
$urlSource = urlencode(curPageUrl());
header("Location: /login?onlogin=${urlSource}");
die();
}

 

curPageURL is just the full url of the current page.

 

WORKS: When I'm not logged in and I go to the known-bugs page I get redirected to http://domain.com/login?onlogin=http%3A%2F%2Fdomain.com%2Fknown-bugs

 

DOESN'T WORK: When I try and access messaging by clicking...

 

http://domain.com/messaging?action=read&cid=130&utm_source=new_message&utm_medium=email&utm_campaign=direct_mesage_link

 

I get redirected to:

http://domain.com/login?onlogin=http%3A%2F%2Fdomain.com%2Fmessaging%3Faction%3Dread%26cid%3D130%26utm_source%3Dnew_message%26utm_medium%3Demail%26utm_campaign%3Ddirect_mesage_link

 

Any thoughts as to what I am doing wrong?

 

 

 

Link to comment
Share on other sites

function curPageURL()
{
if (isset($_SERVER['HTTPS']))
{
	$url = 'https://';
}
else
{
	$url = 'http://';
}

if ($_SERVER['SERVER_PORT'] !== '80')
{
	$url .= "{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}{$_SERVER['REQUEST_URI']}";
}
else
{
	$url .= "{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
}

return $url;
}

Link to comment
Share on other sites

What is line 177 in login.php?

 

Line 177 is where the "You must be logged in" text starts

 

if (isset($_GET['onlogin']))
{
	$url = urldecode($_GET['onlogin']);

	if (filter_var($url, FILTER_VALIDATE_URL))
	{
		preg_match('@^(?:http://)?([^/]+)@i',
			$url, $matches);
		$url_page_name = end(explode(DIRECTORY_SEPARATOR, $url));
		$host = $matches[1];

		// get last two segments of host name
		preg_match('/[^.]+\.[^.]+$/', $host, $matches);

		if ($matches[0] != 'pitchbig.com')
		{
			unset($url);
		}
	}
	else
	{
		unset($url);
	}

	if (isset($url))
	{
		// print_array($page_names);die();
		?>
		<p class="errormessage info">
			You must be logged in to access our "<?php echo $page_names["{$url_page_name}"]; ?>" page. Please log in below.
		</p>	
		<?php
	}
}

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.