467,211 Members | 1,213 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,211 developers. It's quick & easy.

error message on session_register

anfetienne
256MB
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.  
Jul 8 '09 #1
  • viewed: 5654
Share:
6 Replies
anfetienne
256MB
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
Jul 8 '09 #2
anfetienne
256MB
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.  
Jul 8 '09 #3
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.
Jul 8 '09 #4
anfetienne
256MB
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?
Jul 8 '09 #5
Dormilich
Expert Mod 8TB
@anfetienne
the manual entry for sessions at php.net
Jul 8 '09 #6
anfetienne
256MB
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.  
Jul 8 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Maciej Nadolski | last post: by
10 posts views Thread by Cenker Sisman | last post: by
2 posts views Thread by Philip D Heady | last post: by
3 posts views Thread by Amy Kimber | last post: by
11 posts views Thread by mishrarajesh44 | last post: by
1 post views Thread by Kurda Yon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.