Jump to content


Photo

php login


  • Please log in to reply
6 replies to this topic

#1 whisperkay

whisperkay

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 12 December 2013 - 10:03 AM

Hello everyone. I am currently working on my first website, and i am encountering some problems with logging in users after registration. the site url is - www.eastlogicsystems.com. The error i am recieving goes thus -

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

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

 

the funniest thing is that the code is working fine on my local server, using xamp, but when it is hosted on an internent server, it refuses to work

 

 

This is my login.php code-

<?php
 // Connects to your Database
 
require_once("connect.php");
 //Checks if there is a login cookie
 if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM userinfo WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['pass1'])
{
}
else
{
header("Location: index2.php");

;
}
}
}

 //if the login form is submitted

 if (isset($_POST['submit'])) { // if form has been submitted



 // makes sure they filled it in

     if(!$_POST['username'] | !$_POST['pass1'])
     {

         die('You did not fill in a required field.');

     }

     // checks it against the database



     if (!get_magic_quotes_gpc())
     {

         $_POST['email'] = addslashes($_POST['email']);

     }

     $check = mysql_query("SELECT * FROM userinfo WHERE username = '".$_POST['username']."'")or die(mysql_error());



 //Gives error if user dosen't exist

 $check2 = mysql_num_rows($check);

 if ($check2 == 0) {

         die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>');

                 }

 while($info = mysql_fetch_array( $check ))     

 {

 $_POST['pass1'] = stripslashes($_POST['pass1']);

     $info['pass1'] = stripslashes($info['pass1']);

     $_POST['pass1'] = md5($_POST['pass1']);



 //gives error if the password is wrong

     if ($_POST['pass1'] != $info['pass1']) {

         die('Incorrect password, please try again.');

     }
else

 {

 
 // if login is ok then we add a cookie

      $_POST['username'] = stripslashes($_POST['username']);

      $hour = time() + 3600;

line 143 - setcookie(ID_my_site, $_POST['username'], $hour);

line 145 -  setcookie(Key_my_site, $_POST['pass1'], $hour);    

line 147 - header("Location: index2.php");


 //then redirect them to the members area


 }

 }

 }

 else

{    

 

 // if they are not logged in

 ?>
 <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
        <table width="80%" border="5" cellspacing="5" cellpadding="5">
  <tr>
    <td colspan="2" align="center">Login here</td>
   
  </tr>
  <tr>
    <td>Username</td>
    <td> <input name="username" type="text" value="" size="30" maxlength="20" /></td>
  </tr>
  <tr>
    <td>Password</td>
    <td> <input name="pass1" type="password" value="" size="30" maxlength="20" /></td>
  </tr>
  <tr>
    <td><input name="submit" type="submit" value="login" /></td>
    <td><a href="register.php">New User? Register</a></td>
  </tr>
</table>
 </form>
<?php

 }

 

 ?>

 Please i need help.


Edited by whisperkay, 12 December 2013 - 10:05 AM.


#2 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,624 posts

Posted 12 December 2013 - 10:21 AM

the output_buffering setting is turned on in your php.ini on your development system. if you turn it off, the code you develop will work regardless of the setting and will work on your current web hosting.


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#3 whisperkay

whisperkay

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 12 December 2013 - 10:37 AM

Thanks so much for your swift reply. Can you Tell me how to turn it off?



#4 khalilrumi

khalilrumi

    Member

  • Members
  • PipPip
  • 18 posts

Posted 13 December 2013 - 07:29 AM

Did you try ob_end_flush function?



#5 whisperkay

whisperkay

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 13 December 2013 - 03:41 PM

im a newbie in php. dont know about that@khalilrumi. i will be glad if u can help out



#6 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,624 posts

Posted 13 December 2013 - 03:58 PM

the suggestion to use ob_end_flush won't have any effect on your live server and at best is putting a band-aid on top of a special case condition on your development system.

 

did you even try to change the output_buffering setting in your php.ini?

 

btw - changing the setting won't fix anything, it will just make your development system operate the same as your live server and allow you to fix this problem in your code and avoid this problem in any future code you write and test on your development system.

 

edit: and i just noticed the forum section where this thread is at and the code/problem has nothing to do with the php application, frameworks... forum section. moving the php help forum section....


Edited by mac_gyver, 13 December 2013 - 04:01 PM.

multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#7 Firemankurt

Firemankurt

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts
  • LocationWashington State

Posted 30 December 2013 - 02:45 AM

The error you are getting is only the beginning of your challenge for building a log-on script.  You should take a look at or copy another log-on script and modify it to fit your user table.

 

My first google search turned up a reasonably simple start here:

http://www.phpeasyst...om/phptu/6.html

 

Read through it, modify it, run it, debug your changes until it works and you understand every line.  It took me a very long time to get it right and I am still perfecting my own log-in script today.

 

It is very easy to get it wrong.  Don't be discouraged.  When you are starting out it is sometimes much easier to cut and paste an example and then learn from it as you make it your own.

 

Also... Take time to indent and be consistent with your indentations and { } placement.  It makes debugging so much easier.

 

And lastly... It could just be that you have an extra space or line outside of your php tags causing the "Warning: Cannot modify header information" error.  That is why you need to clean up those indentations and brackets.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com