royalhunt
09-20-2002, 10:37 AM
i just started yesterday working with php. i have a problem. i want to allow a user login to an Oracle 9i server and keep his login information to each page he is visiting. my code is the following:
<?php
include "OracleCon.inc";
$username = $HTTP_POST_VARS['username'];
$password =$HTTP_POST_VARS['password'];
if (isset($username) && isset($password)) {
$oracle = new OracleCon($username, $password, "DEV_ORION");
if ($oracle->ConnectToDB()){
if (session_start()){
echo "session started<br>";
}
$connection=array(serialize($oracle));
session_register("connection");
header("Location: search.php");
exit;
}else{
header("Location: fail.php");
exit;
}
}
?>
<html>
<head>
<title>Oracle Login - Start Page</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<h2>Oracle Login - Start Page</h2>
<form action="login2.php" method="POST">
Username: <input name="username" type="text" /><br />
Password: <input name="password" type="password" /><br />
<input type="submit" value="Log in" />
</form>
</body>
</html>
and the code for OracleCon.inc is the following:
<?php
class OracleCon{
var $username;
var $password;
var $alias;
var $conn;
var $stmt;
var $sql_statement;
function OracleCon($username, $password, $alias){
$this->username=$username;
$this->password=$password;
$this->alias=$alias;
}
function ConnectToDB(){
$this->conn = OCIPLogon($this->username, $this->password, $this->alias);
if (!OCIError()){
return true;
}else{
return false;
}
}
function DisconnectFromDB(){
OCILogOff($this->conn);
}
function CreateStatement(){
$this->stmt="select DEMO_ID, DSC from patsavouris.demo where user_name='".$this->username."'";
}
function ExecuteStatement(){
$this->sql_statement = OCIParse($this->conn, $this->stmt, 1);
OCIExecute($this->sql_statement);
}
function ShowResults(){
echo "<TABLE BORDER=1>";
echo "<TR><TH>ID</TH><TH>DSC</TH>";
while (OCIFetch($this->sql_statement)){
echo "<TR>";
$num_cols = OCINumCols($this->sql_statement);
for ($i = 1; $i <= $num_cols; $i++) {
$column_value = OCIResult($this->sql_statement,$i);
echo "<TD>$column_value</TD>";
}
echo "</TR>";
}
echo "</TABLE>";
}
}
?>
when i login using the form i get the following messages:
Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\php\login2.php:10) in c:\program files\apache group\apache\htdocs\php\login2.php on line 13
Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\php\login2.php:10) in c:\program files\apache group\apache\htdocs\php\login2.php on line 13
session started
Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\php\login2.php:10) in c:\program files\apache group\apache\htdocs\php\login2.php on line 18
what is wrong (probably with the session)?
<?php
include "OracleCon.inc";
$username = $HTTP_POST_VARS['username'];
$password =$HTTP_POST_VARS['password'];
if (isset($username) && isset($password)) {
$oracle = new OracleCon($username, $password, "DEV_ORION");
if ($oracle->ConnectToDB()){
if (session_start()){
echo "session started<br>";
}
$connection=array(serialize($oracle));
session_register("connection");
header("Location: search.php");
exit;
}else{
header("Location: fail.php");
exit;
}
}
?>
<html>
<head>
<title>Oracle Login - Start Page</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<h2>Oracle Login - Start Page</h2>
<form action="login2.php" method="POST">
Username: <input name="username" type="text" /><br />
Password: <input name="password" type="password" /><br />
<input type="submit" value="Log in" />
</form>
</body>
</html>
and the code for OracleCon.inc is the following:
<?php
class OracleCon{
var $username;
var $password;
var $alias;
var $conn;
var $stmt;
var $sql_statement;
function OracleCon($username, $password, $alias){
$this->username=$username;
$this->password=$password;
$this->alias=$alias;
}
function ConnectToDB(){
$this->conn = OCIPLogon($this->username, $this->password, $this->alias);
if (!OCIError()){
return true;
}else{
return false;
}
}
function DisconnectFromDB(){
OCILogOff($this->conn);
}
function CreateStatement(){
$this->stmt="select DEMO_ID, DSC from patsavouris.demo where user_name='".$this->username."'";
}
function ExecuteStatement(){
$this->sql_statement = OCIParse($this->conn, $this->stmt, 1);
OCIExecute($this->sql_statement);
}
function ShowResults(){
echo "<TABLE BORDER=1>";
echo "<TR><TH>ID</TH><TH>DSC</TH>";
while (OCIFetch($this->sql_statement)){
echo "<TR>";
$num_cols = OCINumCols($this->sql_statement);
for ($i = 1; $i <= $num_cols; $i++) {
$column_value = OCIResult($this->sql_statement,$i);
echo "<TD>$column_value</TD>";
}
echo "</TR>";
}
echo "</TABLE>";
}
}
?>
when i login using the form i get the following messages:
Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\php\login2.php:10) in c:\program files\apache group\apache\htdocs\php\login2.php on line 13
Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\php\login2.php:10) in c:\program files\apache group\apache\htdocs\php\login2.php on line 13
session started
Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\php\login2.php:10) in c:\program files\apache group\apache\htdocs\php\login2.php on line 18
what is wrong (probably with the session)?