473,573 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error message on session_registe r

anfetienne
424 Contributor
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_registe r() [function.sessio n-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 6019
anfetienne
424 Contributor
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_global s is enabled. You can disable this functionality and this warning by setting session.bug_com pat_42 or session.bug_com pat_warn to off, respectively. in Unknown on line 0
Jul 8 '09 #2
anfetienne
424 Contributor
ok ive read up session_registe r 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_registe r("myusername") ;
session_registe r("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 New Member
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 Contributor
ok ill try that.....thank you...

since session_is_regi stered 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 Recognized Expert Moderator Expert
@anfetienne
the manual entry for sessions at php.net
Jul 8 '09 #6
anfetienne
424 Contributor
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
3145
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 /home/krecik/public_html/silnik.php on line 251 Line 208: print ( "error: " . mysql_error()); Line 251: session_register("uprawnienia", "zalogowany"); I can...
10
9578
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 4.2.2 is Redhat Linux 8.0 apache_1.3.28 php 4.2.2 What I am doing wrong ? Thank you in advance,
2
2796
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
7086
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 where it's going on the server is correct (checked through prints etc.). I've changed the dir to 777 (is that right?) and this is what I get on the...
3
1633
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 on line 34 This is line 33 to line 36 of that class:
20
2370
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 as follows: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/greenpos/public_html/test4/checklogin.php on...
11
2300
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 password specified";}
1
2331
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 middle of the file, I have again session_register("cat"). Can the second declaration destroy the value of the variable cat? Is that OK if I...
5
2349
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 help.. error:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\checklogin.php on line 18 Wrong...
0
7746
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7986
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6358
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5258
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3701
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.