Jump to content
xisto Community
shobhonny

Problem With Custom Login Script I am having an error on custom login script

Recommended Posts

Warning: Cannot modify header information - headers already sent by (output started at /home/addacafe/public_html/login/login.php:1) in /home/addacafe/public_html/login/login.php on line 62
Warning: Cannot modify header information - headers already sent by (output started at /home/addacafe/public_html/login/login.php:1) in /home/addacafe/public_html/login/login.php on line 63

Warning: Cannot modify header information - headers already sent by (output started at /home/addacafe/public_html/login/login.php:1) in /home/addacafe/public_html/login/login.php on line 66



http://forums.xisto.com/no_longer_exists/


The script is wonderful. But when I try to login with registered username and pass I get this error. Any Idea how I can fix this?

Share this post


Link to post
Share on other sites

I can't tell exactly without seeing the script, but it seems like you've got an issue with getting headers sent after page content. Headers that change, say, the "location" of the page that come after page content has already been printed (via echo or otherwise) cause nasty little errors like the ones it says. What's actually done on lines 62, 63 and 66 of the script that it mentions?

Share this post


Link to post
Share on other sites

1. Make sure there is nothing before the session_start() in the code.

<?php session_start();    rest of code

2. I would change from "echo header("Location:"); to a meta refresh because meta refresh gives you options of using variables if you need em.

I used to get that problem when i tried to Post a login to the same page with the True result as a header location

Share this post


Link to post
Share on other sites

Meta refresh is possible using HTML.

<?phpecho '<meta http-equiv="refresh" content="0;url=http://gotoSomewhere.com/" />';?>
Remember that meta refresh can make problems and can be disabled.Using headers redirecting to website is more faster.If you use meta refresh few miliseconds user will see how admin or control panel is.
So meta refresh usually can be hacked...I am not 100% sure that script can avoid clicking a link and destroying website if you use Meta refresh.

Share this post


Link to post
Share on other sites

The idea of Meta Refresh is just to redirect a user, so like when you login on certain sites you see a "Redirecting... If you dont see the next page within 5 seconds click HERE" or "logging in... please wait" and then the page automatically changes, you can use Meta Refresh with that.

I think meta refresh can use a time delay anyway, i could be wrong.

The basic error the OP is having is that PHP is trying to send out headers, either from header(...blah); or from the session start command. PHP needs these headers to be the first thing on the page, and they arent, somewhere the code has an Echo command (or maybe print etc...) or some plain HTML before the PHP starts, so you have a situation where half of the HTML page has already been made by PHP/HTML and then PHP tries to send out headers, which *must* be at the top of the page, and they get put in half way into the page and it all goes horribly wrong. Think of it like building a house with bricks and putting the foundations in half way up the building. Its impossible.

The solution is simply to move the header output up to the top of the page making sure nothing comes before it. IF the PHP code thats causing the error is included by another PHP script you need to take all the headers and session_start() commands to the top of that "master" page:

[u][b]page1.php:[/b][/u]<?//php page one... this page has an include in it as well as some other rubbish...echo "<HTML><HEAD><TITLE>My site</title>.....";include("page2.php")here is some other rubbish..................?>[u][b]page2.php:[/b][/u]<?headers("something.....");some other stuff...............?>
So you can see that page1.php includes the code from page2.php, but in page1.php we have ECHO and then include, so the actual layout of the code once page2 has been included is:

ECHO
HEADERS
Other stuff....

So even though the headers come at the very start of the second file in the grand scheme of the code, they actually come second after an ECHO (which sents output, hence the "Output already sent...." message)

If this is how the code is you need to move those HEADER commands to very top of the chain.
Edited by shadowx (see edit history)

Share this post


Link to post
Share on other sites

I think meta refresh can use a time delay anyway, i could be wrong.

Yes,yes meta refresh is made for that so with <meta http-equiv="refresh" content="0;url=http://gotosomewhere.com/; />
you will be redirected for 0 seconds,but if you change that parameter like this
<meta http-equiv="refresh" content="4;url=http://gotosomewhere.com/; />
you will be redirected for 4 seconds.That is replacing JavaScript function to redirect.So i don't like JavaScript only because its open-source and JavaScript can be disabled.If it wasn't i would add onmousemove on every my project :P

Share this post


Link to post
Share on other sites

http://forums.xisto.com/no_longer_exists/

The script is wonderful. But when I try to login with registered username and pass I get this error. Any Idea how I can fix this?


Dear friend it is difficult to say anything with out seeing the code and going through it. But you please check your session code. That is this code should be the begining of your page. So best of luck.

Share this post


Link to post
Share on other sites

The problem is that you're sending headers after they've already been sent. :PThe headers are sent at the end of the <head> tag. get the pattern?You need to put your php code before or in the head tags.

Share this post


Link to post
Share on other sites

to shadowx:
Your description is in error.

As soon as you issue the 'echo' statement, it is too late to issue another header statement.
Headers need to be sent to the Browser before anything else, even a blank space because when you send something to the Browser, headers are sent with it. (before, actually), and you can no longer issue a header statement.

You need to send the Headers before ANYTHING goes to the Browser.

Here are a couple of tricks to allow you to process html before the headers are sent.
1. use ob_start() to delay the output.

ob_start();echo stuff;send headers;ob_end();
2. save your output in a variable, output the headers, then send the variable string to the Browser
$var = "html output here";send headersecho $var

The session_start is a php command, and you can perform any number of php statements before the header AS LONG AS THE STATEMENTS DO NOT SEND OUTPUT to the browser.

Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.