PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm new to php (i just started learning yesterday!!!) and i want to make a login page. The user logins to an Oracle 9i server. the problem is that i want to personalize the pages for each user. For example i want to execute a specific sql statement for the specific user. my code 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>";
}
}
?>
the problem is when the user logins i get the following warnings:
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
...the whole script. the problem is that i want to start the session when the user logs in succefully. so if i put the session_start at the beginning of the script it wouldn't help (i think, i'm not sure)
you can save the file as OracleCon.inc it will work but this could be a security issue, as the file could be read without being passed through PHP. rather call the file .php.
You can call the session_start function after the user has been successfully logged in, the only requirement is that no information ie any html, plain text or headers have been sent back to the browser by the script! So just make sure you dont have any echo or print commands before the session_start function.
If you include a file with a .inc extension into a file with a .php extension then any PHP in the .inc file will be parsed and the simplest way to find this out is to try it. The issue in using .inc extensions for your included files is not related to what happens when you include them in a PHP page but what happens if someone manages to guess the files name and tries to call it up in a web browser. If the .inc extension is not set to be parsed as PHP by the webserver then any sensitive information in the .inc file (including passwords) will be available to the person calling it up in their web browser.