Forum Moderators: coopster
So far I have this:
<?php
if(Session::isLoggedIn()){
?>
IF LOGGED IN - THE USER SHOULD BE REDIRECTED TO THE WANTED SITE (1)
<?
}
else{
echo "IF NOT LOGGED IN THE USER SHOULD BE REDIRECTED TO ANOTHER SITE";
}
?>
How should i make the redirections?
Or is there a better way to achieve the same effect?
(1) fx. if the user clicks on "menuitem2" the user should be sent to "menuitem2.htm" if logged in. Otherwise the user should be sent to "pleaselogin.htm"
Thanks in advance :-)
function page_redirection($url, $type_redirect='301') {
// Do not redirect if headers already sent
if( headers_sent() ) {
// Also you may need to close session
// session_write_close();
exit();
}
header("HTTP/1.1 " . $type_redirect);
header('Location: ' . $url);
// Also you may need to close session before exiting
// session_write_close();
exit();
}
So then you can call the function with a URL for each case you mentioned.
You could try passing the urls in it.
1. [www1.example.com...]
2. [www2.example.com...]
<?php
If ($_SESSION['example_sessioncompany'])
{
}
else{
header("Location: http://example.com/login");
}
?>
I use this snippet in all my "you have to be logged in to veiw" pages.
[edited by: eelixduppy at 7:34 pm (utc) on Feb. 25, 2009]