I cannot put it on top of the page... because I have to process the script first...
the page 'proclogin.php' contains only script...no html....
Main Topics
Browse All TopicsDear Experts,
I have a script that processes logins...and at the end, depending on what the result is, the client should be redirected
to one page or another, here an example:
if ($g_loginstatus == "Succesfull")
{
header("index.php?cmd=summ
}
if ($g_loginstatus == "unverified")
{
header("index.php?cmd=unve
}
the problem is that this doesn't work, I always get:
"Warning: Cannot modify header information - headers already sent by (output started at /home/.sites/75/site8/web/
is there an easy way to redirect clients depending on variables?
(something like <%response.redirect("http:
Thank you in advance!
Dave.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well, your header should be like:
header('Location: index.php?cmd=summary');
exit();//it's good practive to exit from the script immediately after.
The main issue is, you can't send any output(i.e html) before sending http headers. They have to be sent to the browser first.
Not even a single white-space. Try to keep any script processing that may lead to a redirect above all of your output.
Hope that helps.
Hi,
Correct me if I'm wrong, but I assume you have 3 pages. Your login page, proclogin.php, then index.php (which decides where to send the user).
I don't know how you structured proclogin.php, but maybe this outline would help you.
1. Check if there were actually entries in the form
2. Check if the entries were actually right
3. If entries were right set session variables or cookies
4. If you want to pass variables, now's the time
5. Redirect where applicable
And like the other experts said, put your redirection code before the <head></head> tags.
So in index.php, you'll just have to check the status of the variables with isset and $_GET.
Hope this helps!
;-)
If you need to rewrite your total script to make sure no output starts, and don't have the time for it, you might want to use an output buffer: ob_start(). This starts the buffer, and will keep all output in it (and not send it to a browser). You can then clear the buffer before redirecting with ob_end_clear(). This is not the most effective way to code, but it might be a quick solution to the problem.
The error is most likely either due to a new line character or a space inserted somewhere before <?php or after ?>.
Please check the following:
1. Make sure there is absolutely nothing being sent to the browser before the header() functions are called. This includes spaces. If your code looks like this:
Start here ->
<?php
if ($g_loginstatus == "Succesfull")
{
header("index.php?cmd=summ
}
if ($g_loginstatus == "unverified")
{
header("index.php?cmd=unve
}
?>
<- end here
NOTE: Please notice that I have deliberately left an empty line between "?>" and "<-end here". This is an error and will cause your header redirection to fail with the warning:
"Warning: Cannot modify header information - headers already sent by (output started at /home/.sites/75/site8/web/
Make sure there is no space or newlines before <?php or after ?>
yea, well. Javascript is client side and won't work if javascript is desabled....
>> it seems very strange that a powerful language like PHP... doesn't have an easier way to redirect the client... and the few solutions are header dependent...
I don't think it can get any easyer than that. :) There are tons of functions that can make your coding fast and easy but only if you know that they exist.
Cheers
No, not twice just annother header (you can send several headers).
to redirect header should look like this... and don't forget headers bust be sent before any output or use ob_start(); ...
header("Location: http://www.example.com/ind
cheers
Business Accounts
Answer for Membership
by: mleebPosted on 2005-03-29 at 15:05:06ID: 13657474
All you have to do is place that chunk of code at the top of the page before the "content" starts so it is part of the header and it should work fine.