473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

error message on session_register

anfetienne
424 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
6 6009
anfetienne
424 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
424 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
hoopy
88
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
424 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
8,658 Expert Mod 8TB
@anfetienne
the manual entry for sessions at php.net
Jul 8 '09 #6
anfetienne
424 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

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

Similar topics

11
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in...
10
by: Cenker Sisman | last post by:
My problem is I cannot set session variables correctly. I have tried both PHP 4.2.2 and 4.3.3, with register_global is ON. But I cannot manage to see the desired result. My configuration for PHP...
2
by: Philip D Heady | last post by:
is this valid? session_register('variable1','variable2','variable3','etc'); If not, how can you register a bunch all at once without having to use a line for each variable?
3
by: Amy Kimber | last post by:
Hello, I have a file upload page, and I've had it working fine, it was beautiful :-) Anyway, the powers that be moved hosts... and it doesn't work now. The file name is correct, the directory...
3
by: lkrubner | last post by:
I'm getting this error: Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/httpd/vhosts/publicdomainsoftware.org/httpdocs/pdsIncludes/McSessionInfo.php...
20
by: cmbcorp | last post by:
Hi, I have been playing around with a simple php login script and im getting an error message when i attempt to log in with the username and password i set in the sql table. The error message is...
11
by: mishrarajesh44 | last post by:
i am facing problem in php session.. my code is giving error.. i am giving my code and error message below.. my code:- <?php if(isset($_POST)) { if(empty($password)){echo "No...
1
by: Kurda Yon | last post by:
Hi All, is that OK if I declare the same variable in the same file several times? For example somewhere in the beginning of a file I have session_register("cat") and than, somewhere in the...
5
by: Mubs | last post by:
Hi, I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out.. could any1...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.