Warning: Cannot modify header information -
headers already sent by (output started at L:\php_files\t\test6.php:13) in L:\php_files\t\test6.php on line 14
We will start with conditional redirection which reads the status of the member and redirect them based on their permission levels. For example the permission level for a general member is 1, permission level of veterans is 2 and permission level for site admin is 3. Once the member loges in using a common login process, the permission level set for the member is collected from the table and posted to the page where the permission is to be checked and redirection is to be applied. Here we will not discuss how to get the permission level but assume that the variable $permission has one of the three values 1, 2 or 3. We will use PHP switch command to match the value of $permission and then redirect to appropriate page. Read the basic of PHP redirection page to know how it works. Here is the simple code to handle this conditional redirection.
switch ($permission)
{
case 1:
header ("Location: member-page.php"); // redirect to member page
break;
case 2:
header ("Location: veteran-page.php"); // redirect to veteran page
break;
case 3:
header ("Location: admin-page.php"); // redirect to admin page
break;
default:
header ("Location: index.php"); // redirect to main page if no permission is set
break;
}
You can see different on the value of the $permission page will be redirected to different areas. We have also set on default redirection to take care if no $permission level is set.
case 1:
$msg="Welcome to the member area";
header ("Location: member-page.php?msg=$msg"); // redirect to member page
break;
This way we can redirect the browser to a different page with some message or variable. Note that it is good idea to urlencode the message string before sending to redirected page. soham | 27-01-2009 |
I am trying to use this method, but gives me a warning that it can\'t modify header information as it has already been sent earlier. Help please? I am trying to use ob_start() and ob_end_flush(), but still doesn\'t work. |
smo | 28-01-2009 |
You are sending some output before ( above this line ) the redirection is executed. Check the page source to see what is that tag or text coming to browser before the redirection command. |
vanita | 12-05-2009 |
pls tell me author of php and how to maintain session login time and logout time details in database |
smo | 13-05-2009 |
Rasmus Lerdorf. It is easy to store login time as while verifying the id and password you can store the time in another table along with userid. But logout is the problem. If the member is clicking the logout button then you can store them otherwise you have to assume the time and update the table. Read the Who is online script to know how this can be done. |
Samy | 27-12-2010 |
Hi, I am looking something like this scrip. I want to play a first time video which is working fine, but it happens that display in every page that I move on, I want to play a different video clip once the user is selecting another link. How can use the SWITCH case, and What LOCATION I should use. I am working with Joomla CMS. Thanks |