Ask a Question related to Macromedia Dynamic HTML, Design and Development.
-
Gamespy007 #1
Help with session_start()
Hi. I was tring to start a session my web page and tried using the
session_start(). However i keep gettin the warning:
Warning: session_start() [function.session-start]: Cannot send session cookie
- headers already sent by (output started at c:\wamp\www\********\index.php:3)
in c:\wamp\www\*******\index.php on line 4.
Am I gettin this error cause im hand coding. What should i do to correct it?
Gamespy007 Guest
-
Session_Start not firing
I'm workinbg in Visual Studio 2003. I'm experimenting with creating a session variable, and from all I can gather. the Session_Start event is not... -
Classes and session_start()
Hello there! I'm building a php system where I can put images in a zipfile and download it. I found some code to do this and created zip.php, a... -
session_start() problem
Hi, every time. This is a familiar question here, but the answers I found in this and other groups did not help. I get the : Warning: Cannot send... -
About Session_Start() with different Browser
Hi all, I am new to php. At first, I wrote a php script to generate a pdf file from a tex file and load that pdf file to the browser by call a... -
session_start()
Ian.H wrote: Just one clarification for the original poster, as I think this still might be semi-unclear to him. (Had he understood the manual... -
John Doe #2
Re: Help with session_start()
Gamespy007 wrote:
no> Hi. I was tring to start a session my web page and tried using the
> session_start(). However i keep gettin the warning:
>
> Warning: session_start() [function.session-start]: Cannot send session cookie
> - headers already sent by (output started at c:\wamp\www\********\index.php:3)
> in c:\wamp\www\*******\index.php on line 4.
>
> Am I gettin this error cause im hand coding.
as the message states, you can't send a session cookie after the headers> What should i do to correct it?
have been sent (unless you're using output buffering)
probably there is a space/blank line sended before or an HTML tag. post
the first lines of your code to see what's the problem
John Doe Guest
-
Gamespy007 #3
Re: Help with session_start()
I think i got the session_start() to work. But now i get the error of:
Warning: Cannot modify header information - headers already sent by (output
started at: c:\wamp\www\cyberstudents\db.php:15) in
c:\wamp\www\**********\login.php on line 45
There is something wrong with my header call to return to the index page. The
code im using is:
<?php
session_start();
include'db.php';
$username = $_POST['username'];
$password_usr = $_POST['password_usr'];
// checkin if the user exists
$sql_user_check = "SELECT * FROM users WHERE username='$username'";
$result_name_check = mysql_query($sql_user_check);
$usersfound = mysql_num_rows($result_name_check);
// if user not found, note that and end
if ($usersfound < 1) {
$error = "User $user not found.";
// if user does exist, continue with processing
} else {
// checking if passwords match
$sql_pass_get = "SELECT * FROM users WHERE username='$username'";
$user_info = mysql_fetch_array(mysql_query($sql_pass_get));
$password = $user_info['password_usr'];
// if doesn't match, note that and end
if ($password != $password_usr) {
$error = "Invalid password. Try again.";
// if do match, let in and pass on info to session variables
} else {
$_SESSION['usr_id'] = $user_info['usr_id'];
$_SESSION['username'] = $user_info['username'];
$_SESSION['password_usr'] = $user_info['password_usr'];
$_SESSION['email_address'] = $user_info['email_address'];
$_SESSION['firstname_usr'] = $user_info['firstname_usr'];
$_SESSION['lastname_usr'] = $user_info['lastname_usr'];
$_SESSION['level_usr'] = $user_info['level_usr'];
$_SESSION['regtime_usr'] = $user_info['regtime_usr'];
}
}
if (!$_SESSION['username']) {
if ($error) {
echo $error;
include 'login.html';
} else {
include 'index.php';
}
} else {
header("Location: index.php");
exit;
}
?>
The db.php file is:
<?
# database connection scripts
# the next 4 lines you can modify
$dbhost = 'localhost';
$dbusername = 'root';
$dbpasswd = 'password';
$database_name = 'cyberstudents';
#under here, don't touch!
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd" )
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
or die("Couldn't select database.");
?>
Gamespy007 Guest



Reply With Quote

