Amezis 0 Report post Posted September 9, 2005 I'm making a simple login script, but it doesn't seem to work like I want. The error messages work, but if I actually write the right username and password, it won't work. Here's the message I get: Warning: Cannot modify header information - headers already sent by (output started at /home/ngnorge/public_html/fsm/index.php:7) in /home/ngnorge/public_html/fsm/logginn/login.php on line 9Here's the script: login.php <?php include('config.php');if($action == "submit"){ if(($userinput == "")||($passinput == "")){ echo "$noinfo"; } else { if(($userinput == $username)&&($passinput == $password)){ header( "Location: $location" ); } else { //this is line 9, where the problem occurs... Is there really a problem here? echo "$badinfo"; } }}include('form.php');?> config.php<?php$username = "my-username";$password = "a-secret-password";$location = "http://fsm.neongames.trap17.com/meny.php";$badinfo = "Wrong username/password, please try again";$noinfo = "You did not enter info in all fields, please fill out all fields.";?> form.php<form name="form1" method="post" action=""><input name="userinput" type="text" id="userinput" size="16" onfocus="this.value=''" value="Username"><br><input name="passinput" type="password" id="passinput" size="16" onfocus="this.value=''" value="password"><br><input type="submit" name="Submit" value="Logg inn"><input name="action" type="hidden" id="action" value="submit"></form> Share this post Link to post Share on other sites
HmmZ 0 Report post Posted September 9, 2005 It's always very useful to carefully read your error, they usually contain the solution (with a bit of logic thinking) aswell. The same thing is with your error, its a common error, but it always states the problem line at the end, line 9. When i read on your line 9 i read: Header( "Location: $location" ); ... sorry but i do not think that is actually possible, because the syntax of that is: Header("Location: [url="https://sedo.com/us/services/broker-service/?language=us?tracked=&partnerid=&language=us ); When outputted to your browser, it could be seen right...IF the browser translates it, if it stops at the '$' then there is no way you will see your variable translated, wich means it will not redirect wich mean it will display an error, try putting in a full url and see how it goes.. Hope that helps Share this post Link to post Share on other sites
Amezis 0 Report post Posted September 9, 2005 Ummm... still not working... I don't understand why...I still get the same message even if I change $location to http://www.myadress.com/... Share this post Link to post Share on other sites
Spectre 0 Report post Posted September 9, 2005 If enclosed in double quotes, a variable will be replaced by it's value - so "Location: $location" would become "Location: x" (if x were the value of $location), but 'Location: $location' would remain exactly as is. This is why it's faster and more efficient to use single quotes where possible. However, $location doesn't seem to have been assigned a value within the code shown, so it may or may not work. But anyway, that isn't the problem. The problem is that you are sending output to the client prior to attempting to send headers. Headers are sent accompanying the first lot of data sent to the client, after which they cannot be recalled or modified. Take a look at this thread. According to the error description, the output is started in index.php on line 7. So take a look there. Oh, and on another, not-really-related note, I think the HTTP specification mentions that 3xx redirections containing a 'Location' header (which inform the client of where the page can be found) that an explicit URI must be specified (eg. website.com/file), but most clients/browsers are capable of automatic name substitution. Share this post Link to post Share on other sites
Amezis 0 Report post Posted September 9, 2005 Oh I just discovered something... The script itself works, but it's when I try to include the login thingy to my main page that the problem occurs. So, how can it be fixed?I am not really interrested in information on why it happens, I just want to know how to fix it Share this post Link to post Share on other sites
mike_savoie 0 Report post Posted September 9, 2005 Warning: Cannot modify header information - headers already sent by (output started at /home/ngnorge/public_html/fsm/index.php:7) in /home/ngnorge/public_html/fsm/logginn/login.php on line 9Your error message explains all you need to know. You should try googling errors to find the fix. With this code header( "Location: $location" ); you are sending new header information, which cannot happen after there has already been headers sent, ie output to the screen. To send a custom header, or using your code; the header function MUST be the very first line of code within the page. Just try putting your error in google to find a better explanation. Share this post Link to post Share on other sites
Amezis 0 Report post Posted September 9, 2005 Yay I figured it out... I needed to include the config.php file on the top of the document, means on the first line. It works now Thanks everybody for helping. Share this post Link to post Share on other sites
djax 0 Report post Posted September 20, 2005 include('config.php'); -- dont use that function when you put in that fail information, what you want to keep secret,when something goes wrong, then others may see that...use better require('config.php'); when something goes wrong then your script stops working Share this post Link to post Share on other sites
vitrus 0 Report post Posted October 12, 2005 Just fully delete the "header( "Location: $location" );" ...And write a new method that takes care of this stuff...my advice is to use <body onLoad=""> ... good luck! Share this post Link to post Share on other sites
Amezis 0 Report post Posted October 14, 2005 No, it works now, I just needed to put the header thingy on the top of the page (above the <html> tag) Share this post Link to post Share on other sites
vitrus 0 Report post Posted October 15, 2005 When the design of the script allows that, you should Share this post Link to post Share on other sites