Connecting Tech Pros Worldwide Help | Site Map

error message on session_register

anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#1: Jul 8 '09
hi ive been using a login code which uses sql & db its quite simple and has been working great.....but as i have just gone to do a final test on the site i've built starting from the login page i get the following error message...

"Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/theau10/public_html/resources/checklogin.php:1) in /home/theau10/public_html/resources/checklogin.php on line 30

Warning: Cannot modify header information - headers already sent by (output started at /home/theau10/public_html/resources/checklogin.php:1) in /home/theau10/public_html/resources/checklogin.php on line 32"

I don't know why it is doing this as it has been working great before.

here is the login code

Expand|Select|Wrap|Line Numbers
  1. <title>: : : members online resource centre</title><?php
  2. $username="theau10_tawUser";
  3. $password="auction10";
  4. $database="theau10_resources";
  5.  
  6. // Connect to server and select databse.
  7. $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
  8.  
  9. mysql_select_db("$database") or die("Unable to select database!");
  10.  
  11. // username and password sent from form
  12. $myusername=$_POST['myusername'];
  13. $mypassword=$_POST['mypassword'];
  14.  
  15. // To protect MySQL injection (more detail about MySQL injection)
  16. $myusername = stripslashes($myusername);
  17. $mypassword = stripslashes($mypassword);
  18. $myusername = mysql_real_escape_string($myusername);
  19. $mypassword = mysql_real_escape_string($mypassword);
  20.  
  21. $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
  22. $result=mysql_query($sql);
  23.  
  24. // Mysql_num_row is counting table row
  25. $count=mysql_num_rows($result);
  26. // If result matched $myusername and $mypassword, table row must be 1 row
  27.  
  28. if($count==1){
  29. // Register $myusername, $mypassword and redirect to file "login_success.php"
  30. session_register("myusername");
  31. session_register("mypassword");
  32. header("location:tsandcs.php");
  33. }
  34. else {
  35. header("location:incorrect.php");
  36. }
  37. ?>
  38.  
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#2: Jul 8 '09

re: error message on session_register


ive tried again and this message came up

Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#3: Jul 8 '09

re: error message on session_register


ok ive read up session_register is deprecated and that the use of $_SESSION is prefered.

ive changed my code to the following but i still get a error message of "Warning: Cannot modify header information - headers already sent by (output started at /home/theau10/public_html/resources/checklogin.php:1) in /home/theau10/public_html/resources/checklogin.php on line 32"

session_register("myusername");
session_register("mypassword");

my new code is

Expand|Select|Wrap|Line Numbers
  1. <title>: : : members online resource centre</title><?php
  2. $username="theau10_tawUser";
  3. $password="auction10";
  4. $database="theau10_resources";
  5.  
  6. // Connect to server and select databse.
  7. $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
  8.  
  9. mysql_select_db("$database") or die("Unable to select database!");
  10.  
  11. // username and password sent from form
  12. $myusername=$_POST['myusername'];
  13. $mypassword=$_POST['mypassword'];
  14.  
  15. // To protect MySQL injection (more detail about MySQL injection)
  16. $myusername = stripslashes($myusername);
  17. $mypassword = stripslashes($mypassword);
  18. $myusername = mysql_real_escape_string($myusername);
  19. $mypassword = mysql_real_escape_string($mypassword);
  20.  
  21. $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
  22. $result=mysql_query($sql);
  23.  
  24. // Mysql_num_row is counting table row
  25. $count=mysql_num_rows($result);
  26. // If result matched $myusername and $mypassword, table row must be 1 row
  27.  
  28. if($count==1){
  29. // Register $myusername, $mypassword and redirect to file "login_success.php"
  30. $_SESSION["myusername"] = "$myusername";
  31. $_SESSION["mypassword"] = "$mypassword";
  32. header("location:tsandcs.php");
  33. }
  34. else {
  35. header("location:incorrect.php");
  36. }
  37. ?>
  38.  
Member
 
Join Date: Feb 2009
Location: Romania/London
Posts: 88
#4: Jul 8 '09

re: error message on session_register


Its due to this:

<title>: : : members online resource centre</title>

You cannot send any output to the browser before you use a header() call.

Just remove it and it should work fine.
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#5: Jul 8 '09

re: error message on session_register


ok ill try that.....thank you...

since session_is_registered has deprecated as well i will have to work on a different way to check if a session is registered.....has anyone got any suggestions to point me in the right direction?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,635
#6: Jul 8 '09

re: error message on session_register


Quote:

Originally Posted by anfetienne View Post

has anyone got any suggestions to point me in the right direction?

the manual entry for sessions at php.net
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#7: Jul 8 '09

re: error message on session_register


ok i still keep getting a header error, i have removed the title as said and i get "Warning: Cannot modify header information - headers already sent by (output started at /home/theau10/public_html/resources/checklogin.php:2) in /home/theau10/public_html/resources/checklogin.php on line 33" for the following code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $username="theau10_tawUser";
  3. $password="auction10";
  4. $database="theau10_resources";
  5.  
  6. // Connect to server and select databse.
  7. $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
  8.  
  9. mysql_select_db("$database") or die("Unable to select database!");
  10.  
  11. // username and password sent from form
  12. $myusername=$_POST['myusername'];
  13. $mypassword=$_POST['mypassword'];
  14.  
  15. // To protect MySQL injection (more detail about MySQL injection)
  16. $myusername = stripslashes($myusername);
  17. $mypassword = stripslashes($mypassword);
  18. $myusername = mysql_real_escape_string($myusername);
  19. $mypassword = mysql_real_escape_string($mypassword);
  20.  
  21. $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
  22. $result=mysql_query($sql);
  23.  
  24. // Mysql_num_row is counting table row
  25. $count=mysql_num_rows($result);
  26. // If result matched $myusername and $mypassword, table row must be 1 row
  27.  
  28. if($count==1){
  29. // Register $myusername, $mypassword and redirect to file "login_success.php"
  30. session_start();
  31. $_SESSION['myusername'] = $myusername;
  32. $_SESSION['mypassword'] = $mypassword;
  33. header("location: tsandcs.php");
  34. }
  35. else {
  36. header("location: incorrect.php");
  37. }
  38. ?>
  39.  
Reply