0

This is the other code statement in php, the opposite of my other question, it's about time to finish updating the log after finishing the session login

<?php 
    include ('connect.php');/*to connect to database with oracle 11g*/

    session_start();
    $_SESSION = array();

    $email = $_SESSION["EMAIL_USER"];
    $passw = $_SESSION["PASS_USER"];

    $query = "UPDATE LOGIN SET OUT_TIME_LOGIN = LOCALTIMESTAMP WHERE EMAIL_USER = '$email' AND PASS_USER = '$passw';";
    $sid = oci_parse($conn, $query);
    $result = oci_execute($sid);
    $dbarray = oci_fetch_array($sid);

    unset ($_SESSION);

    if(ini_get("session.use_cookies")){
       $params = session_get_cookie_params();
       setcookie(session_name(), '', time() - 50000,
       $params["path"], $params["domain"],
       $params["secure"], $params["httponly"]);
    }

    session_destroy();
    session_commit();
    /**/
    header("location: ../menu.html");
    ?>

when I finish the logon session, was supposed to update the table with the login time to exit to exemples: LOCALTIMESTAMP where email_user = '$email';

and when I try log out, I received error

Undefined index: EMAIL_USER AND PASS_USER

and in my other question, PHP - Parse error: syntax error, unexpected end of file, I re-edited the codes and I made this

$query = "SELECT * FROM login WHERE user_email = '$email' AND user_pass= '$passw'";
$sid = oci_parse($conn, $query);
$result = oci_execute($sid);
$dbarray = oci_fetch_array($sid);

if (($dbarray["user_email"] == $email) && ($dbarray["user_pass"] == $passw)) {
     session_start();
     $_SESSION["user_email"] = $email;
     $_SESSION["user_pass"]  = $passw;
            switch ($dbarray["type_user_id"]) {
                case 1:
                    header("Location: admin.php");
                    break;
                default:
                    echo "<script> alert('ERROR:'); history.back() </script>";
                    exit;
                    break;
            }
        }

and now I intend to do the opposite to get the email and password of the online session any suggestion?

Community
  • 1
  • 1
Renata P Souza
  • 255
  • 3
  • 20
  • in both codes you are using different session `$_SESSION["EMAIL_USER"]; ` and below code '$_SESSION["user_email"]' if you change this `$_SESSION["EMAIL_USER"]; ` to this '$_SESSION["user_email"]' and so as this `$_SESSION["PASS_USER"];` to this `$_SESSION["user_pass"];` it may resolve the problem – Shehary Jul 24 '15 at 04:38
  • by the way you also don''t need this `$_SESSION = array();` – Shehary Jul 24 '15 at 04:46
  • I tried and worked but the table login is not update the OUT_TIME_LOGIN – Renata P Souza Jul 24 '15 at 04:59
  • just `OUT_TIME_LOGIN` not updating or its blank or there is nothing when you update? – Shehary Jul 24 '15 at 05:01
  • will add this to answer but there is another problem in your update query – Shehary Jul 24 '15 at 05:02
  • is worked but know I think the problem is update query and I change all email_user and pass_user to user_email and user_pass – Renata P Souza Jul 24 '15 at 05:04
  • yeah i sorted that in answer check answer – Shehary Jul 24 '15 at 05:05

1 Answers1

1

By looking at both of the codes, I see following errors

In First code $_SESSION variables are

$email = $_SESSION["EMAIL_USER"];
$passw = $_SESSION["PASS_USER"];

But in 2nd code when you are fetching data from database and loading variables to Session

 $_SESSION["user_email"] = $email;
 $_SESSION["user_pass"]  = $passw;

So change these

$email = $_SESSION["EMAIL_USER"];
$passw = $_SESSION["PASS_USER"];

To this

$email = $_SESSION["user_email"];
$passw = $_SESSION["user_pass"];

This will resolve your following error

Undefined index: EMAIL_USER AND PASS_USER

and in your first code you don't need $_SESSION = array();

In your 2nd code you are fetching data with following query

$query = "SELECT * FROM login WHERE user_email = '$email' AND user_pass= '$passw'";

and in your first code you are updating data with following query

$query = "UPDATE LOGIN SET OUT_TIME_LOGIN = LOCALTIMESTAMP WHERE EMAIL_USER = '$email' AND PASS_USER = '$passw';";

change you update query because you are referring to right table but wrong table and col names

$query = "UPDATE login SET OUT_TIME_LOGIN = LOCALTIMESTAMP WHERE user_email = '$email' AND user_pass = '$passw';";
//you need to check `OUT_TIME_LOGIN` col name in your database too i m sure its wrong too

Also you have to change this LOCALTIMESTAMP To this, first define $datetime

$datetime = date('Y-m-d H:i:s');

so final update query will be like

$query = "UPDATE login SET out_time_login = '$datetime' WHERE user_email = '$email' AND user_pass = '$passw';";

and you asked "get the email and password of the online session"

In your PHP code you can

echo $_SESSION["user_email"];
echo $_SESSION["user_pass"];

Or in HTML

<input type="text" name="email" value="<?php echo $_SESSION["user_email"];?>">
<input type="text" name="pass" value="<?php echo $_SESSION["user_pass"];?>">
Shehary
  • 9,926
  • 10
  • 42
  • 71
  • thanks @shehary, everything is worked and just the table login don´t update the OUT_TIME_LOGIN as I intended to do – Renata P Souza Jul 24 '15 at 05:21
  • check the answer i explained that part too :) also make sure `OUT_TIME_LOGIN` is the right col name, no margin of error in spellings or upper or lower case letters, what if its like `out_time_login` – Shehary Jul 24 '15 at 05:22
  • $localtime = localtime();, dont update the table – Renata P Souza Jul 24 '15 at 05:26
  • paste your query here and confirm that OUT_TIME_LOGIN is right col name on login table? – Shehary Jul 24 '15 at 05:28
  • what's your time zone? I again update the answer, the update query part, check and try again. – Shehary Jul 24 '15 at 05:30
  • I tried to create an user with this date so everythig is worked, and I made tried in sql developer this `SELECT * FROM LOGIN WHERE USER_EMAIL = 'user@email.pt' AND USER_PASS = '123456'; UPDATE LOGIN SET TIME_OUT_LOGIN = LOCALTIMESTAMP WHERE USER_EMAIL = 'user@email.pt' AND USER_PASS = '123456'; ` and the table login update normal but with the php codes with squery don´t do nothing – Renata P Souza Jul 24 '15 at 05:39
  • ok i think its in Europe, forgive me my lack of knowledge, you need to add this line in before `session_start` `date_default_timezone_set('Europe/London');` and then echo $datetime; and see if you get your local time – Shehary Jul 24 '15 at 05:40
  • in the beginning, I made in sql developer `ALTER SESSION SET NLS_LANGUAGE ='PORTUGUESE'; ALTER SESSION SET NLS_TERRITORY = 'PORTUGAL'; ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YYYY'; ALTER SESSION SET NLS_TIME_FORMAT = 'HH24:MI:SS'; ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'HH24:MI:SS';` – Renata P Souza Jul 24 '15 at 05:46
  • all is worked, just `$query`don´t update te table with the session opened – Renata P Souza Jul 24 '15 at 05:48
  • ok so problem resolved, all of them ? – Shehary Jul 24 '15 at 05:49
  • Can a paste your query u mentioned in comment with u create users – Shehary Jul 24 '15 at 07:06
  • the user is create in same same like login I used insert all, the codes is this in this link http://pastebin.com/713btMUG – Renata P Souza Jul 24 '15 at 07:57
  • I dont see `TIME_OUT_LOGIN` in the pastebin so either it doesnot exist in login table or its name is different – Shehary Jul 24 '15 at 08:03
  • see here I update the codes, http://pastebin.com/BG98vYzx, `TIME_OUT_LOGIN` and `DATE_LOGIN`beginnig `NULL` to I update later – Renata P Souza Jul 24 '15 at 08:03
  • its not `TIME_OUT_LOGIN` it is `out_time_login` there is very very very big difference, and also its not `DATE_LOGIN` its `date_login`, you have to be Careful with this, if table name is `login` then in your query must be `login` you cant use `Login` or `LOGIN` it will not do anything – Shehary Jul 24 '15 at 08:09
  • last update http://pastebin.com/DUdFKCM7, @shehary, thanks for your help and for your time, it is taking and I go to school maybe later we can solve here in Portugal, in Europe, it's day and to go to school, is well and thanks again – Renata P Souza Jul 24 '15 at 08:10
  • no problem man, have nice day at school. – Shehary Jul 24 '15 at 08:12
  • I changed all and test and still in the same and I´m tired maybe later, maybe my teacher can help me, your solution is correct, I don´t understand why the codes worked just just does not do anything to update the login table – Renata P Souza Jul 24 '15 at 08:12
  • I've been analyzing the code more closely and I managed to solve the problem, your answer was correct, I do not analyzed more thoroughly the code, but has worked and thank again – Renata P Souza Jul 25 '15 at 00:35