473,248 Members | 1,427 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,248 software developers and data experts.

PHP sessions

i am using php 5.2.5. i have a php script like this:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7. <body>
  8. <?php
  9. ob_start();
  10. $host="localhost"; // Host name
  11. $username="root"; // Mysql username
  12. $password="dhanshi"; // Mysql password
  13. $db_name="adi"; // Database name
  14. $tbl_name="users"; // Table name
  15.  
  16. // Connect to server and select databse.
  17. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  18. mysql_select_db("$db_name")or die("cannot select DB");
  19.  
  20. // Define $myusername and $mypassword
  21. $myusername=$_POST['name'];
  22. $mypassword=$_POST['pass'];
  23.  
  24. // To protect MySQL injection 
  25. $myusername = stripslashes($myusername);
  26. $mypassword = stripslashes($mypassword);
  27. $myusername = mysql_real_escape_string($myusername);
  28. $mypassword = mysql_real_escape_string($mypassword);
  29.  
  30. $sql="SELECT * FROM $tbl_name WHERE name='$myusername' and pass=md5('$mypassword')";
  31. $result=mysql_query($sql);
  32.  
  33. // Mysql_num_row is counting table row
  34. $count=mysql_num_rows($result);
  35. // If result matched $myusername and $mypassword, table row must be 1 row
  36. $r=mysql_fetch_array($result);
  37.  
  38. $value=$r['value'];
  39.  
  40.  if($count==1){
  41.  
  42.   session_register("myusername");
  43. session_register("mypassword");
  44.  
  45. //echo $value;
  46. //echo '<META HTTP-EQUIV="Refresh" Content="0; URL=login_success.php">';  
  47. switch($value)
  48. {
  49. case "1";
  50. case "2";
  51.  echo '<META HTTP-EQUIV="Refresh" Content="0; URL=tl.php">';  
  52.  break;
  53.  case "3";
  54.  echo '<META HTTP-EQUIV="Refresh" Content="0; URL=l2.php">';  
  55.  break;
  56.  case "4";
  57. echo '<META HTTP-EQUIV="Refresh" Content="0; URL=l3.php">'; 
  58.  
  59.  default:
  60. echo '<META HTTP-EQUIV="Refresh" Content="0; URL=l3.php">'; 
  61.  
  62.  exit;
  63. }
  64.  
  65.  
  66. }
  67. else {
  68. echo '<META HTTP-EQUIV="Refresh" Content="0; URL=wrong.php">';  
  69. }
  70. ob_end_flush();
  71. ?>
when the script runs, i get a warning:


Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\adi\check.php:8) in C:\xampp\htdocs\adi\check.php on line 42.

Line 8 and 42 is highlighted here.

Can this problem be solved?
Aug 30 '08 #1
2 1162
Atli
5,058 Expert 4TB
Hi.

You need to call session_start() before anything is added to the output. It should be the first thing on the page.

The session functions, like session_register, are deprecated and shouldn't be used.
I suggest you take a look at my PHP Session article to see how sessions should be used in PHP5.
Aug 30 '08 #2
Hi.

You need to call session_start() before anything is added to the output. It should be the first thing on the page.

The session functions, like session_register, are deprecated and shouldn't be used.
I suggest you take a look at my PHP Session article to see how sessions should be used in PHP5.
HI Atli,

Ur suggestion works. Thanks a lot.
Aug 31 '08 #3

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

Similar topics

2
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
3
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server...
3
by: Will Woodhull | last post by:
Hi, I'm new here-- I've been reading the group for a couple of days. Nice group; I like the way n00b33 questions are handled. I've been using a Javascript routine in index.html to determine a...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
12
by: D. Shane Fowlkes | last post by:
This is a repost (pasted below). Since my original post, I've double checked the system clock and set all IIS Session Timeout values to 10 minutes. Still ...the problem occurs. I've also...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
22
by: magic_hat60622 | last post by:
Hi all. I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e.,...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.