Author Topic: Php script login script using oracle 11g wont work. Sessions not working.  (Read 1891 times)

0 Members and 1 Guest are viewing this topic.

Offline mboley370Topic starter

  • Irregular
  • Posts: 13
    • View Profile
The script will find the data in my database.  If i comment out userSession on the next page that  the script below will go to it works fine.  However that  means there is something wrong with the area below when its assigning variables to my session.  I am not sure whats going on, but my sessions aren't working.

This is my first test ever on an wamp server using oracle enterprise 11g on a Windows Vista.

What am i doing wrong?

The code below

<?php require_once("includes/userSession.php"); ?>
<?php 
require_once("includes/connection.php"); ?>
<?php 
require_once("includes/functions.php"); ?>
<?php
if (staffLogged_in()) {
redirect_to("staffArea.php");
}
$message="";
//check to see if submit button was pressed
if (isset($_POST['submit']) || isset($_POST['submit_x'])) { // Form has been submitted.

//check to see if fields are not empty
if($_POST['email'] =="" || $_POST['password'] ==""){
$message "Please fill in both fields.";

} else {
//I used addslashes instead of mySQLprep from function.php since oracle won't support it.
//Will probably move to stripslashes then post my variables below that
//$email = trim(addslashes($_POST['email']));
$email = ($_POST['email']);
$password =($_POST['password']);
//$password = trim(addslashes($_POST['password']));
// Check database to see if username and the password exist there.
//$query = "SELECT staffMemberID, smFirstName ";
//$query .= "FROM staffMember ";
//$query .= "WHERE smEmail = '{$email}' ";
//$query .= "AND smPassword = '{$password}' ";
//$query .= "LIMIT 1";
// Oracle wont support limit 1
$query "SELECT staffMemberID, smFirstName FROM staffMember WHERE smEmail = '{$email}' AND smPassword = '{$password}'";
//$query = "select staffMemberID, smFirstName from staffMember";
$result_set oci_parse($conn$query);
oci_execute($result_set);
confirm_query($result_set);

// there was mysql_num_row which is returns the number of rows in a result.  I tried oci_num_rows but got many errors
if (oci_fetch($result_set)==1) {
$found_user oci_fetch_array($result_setOCI_ASSOC+OCI_RETURN_NULLS);
//set session variables if user found
$_SESSION['logged_in'] = "yes";
$_SESSION['firstName'] = $found_user['smFirstName'];
$_SESSION['staffMemberID'] = $found_user['staffMemberID'];
redirect_to("staffArea.php");
} else {
$message "Email / Password combination incorrect.<br />
Please make sure your caps lock key is off and try again."
;
}

} else { 
// Form has not been submitted.
if (isset($_GET['logout']) && $_GET['logout'] == 1) {
$message "You are now logged out.";

if (isset(
$_GET['error']) && $_GET['error'] == 1) {
$message "Sorry but you must be logged in to view that page.";

$email "";
$password "";
}
?>



The code below is for my sessionUser Page that the above script links to for its session commands.  The function staff_confirm_logged_in() is where my codes getting caught at.  I get the error associated with that function below every time if i don't comment out my session going to the next page.

<?php
	
session_start();
function 
staffLogged_in(){
	
	
if(isset(
$_SESSION['staffMemberID']) && ($_SESSION['logged_in'] =="yes") && isset($_SESSION['firstName'])){
	
	
	
return 
true;
	
	
} else {
	
	
	
return 
false;
	

	
	
}
	
}
	

	
function 
staff_confirm_logged_in() {
	
	
if (!
staffLogged_in()) {
	
	
	
redirect_to("staffLogin.php?error=1");
	
	
}
	
}
?>

« Last Edit: June 21, 2010, 05:55:59 PM by mboley370 »

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
And what error it is that you get?
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline mboley370Topic starter

  • Irregular
  • Posts: 13
    • View Profile
Its just using my error I have setup which would be this. 

Sorry but you must be logged in to view that page

It says this, because it uses this in the next page to load the page.  It makes sure that the users is logged in.

At the top before anything it makes sure with a funciton that points to this code.

function staff_confirm_logged_in() {
      if (!staffLogged_in()) {
         redirect_to("staffLogin.php?error=1");
      }

The error jumps back to my staffLogin.php page where it spits out the error for error=1 which is error

Sorry but you must be logged in to view that page

So its getting to the next page, but failing to use sessions and I tested this because if i edit out the sessions on the next page and to check if my user is logged in.  I get to the next page.  Without commenting anything about sessions it shows me the error that i am not logged in.
« Last Edit: June 21, 2010, 06:13:28 PM by mboley370 »

Offline mboley370Topic starter

  • Irregular
  • Posts: 13
    • View Profile
I figured it out.