Jump to content
xisto Community
Amezis

Problem With A Login Script

Recommended Posts

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 9

Here'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

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

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

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

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 9

Your 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

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

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

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

When the design of the script allows that, you should :)

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.