Session variable not being created

Asked

Viewed 81 times

1

I’m creating a redirect, coming from a link of email, for the user to access such link, URL. However, the problem is that I am not being able to set the session to this URL!
Can someone help me?

Follow the code as it is:

logon.php:

if (isset($_POST["login"])){
$email = $_POST["email"];
$password = $_POST["password"];

$tabela_usuarios = "SELECT * FROM owner WHERE owner_email='$email' AND password='$password' ";

$resul = mysql_query($tabela_usuarios);

$regs = mysql_num_rows($resul);

if ($regs <> 0){
    $owner_id = mysql_result($resul, 0, "owner_id");
    $userName = mysql_result($resul, 0, "owner_firstName");

    session_start();

    $_SESSION['owner_id'] = $owner_id;
    $_SESSION['owner_firstName'] = $userName;

if(isset($_SESSION['redirectURL'])) {

  $url = $_SESSION['redirectURL'];

  unset($_SESSION['redirectURL']);
  header("Location: ".$url);
} else {
  header("Location: default.php");
}
}else{
    header("Location: ../index.html");
}
}

Login validation code:

include_once("con/conexao.php");
session_start();

$owner_id = $_SESSION['owner_id'];
$userName = $_SESSION['owner_firstName'];

if($userName == ""){
   $_SESSION['redirectURL'] = "TESTANDO!!!";
   var_dump($_SESSION);
   //header("Location: ../index.php");
}
  • Shows some error?

  • No @Andrébaill. Dou um var_dump e ela não aparece... Somente as outras duas owner_id e iserName.

  • Try inserting session_start at the beginning of the file.

  • But it’s at the beginning of the archive, @André Baill... Or I didn’t understand you.

  • Remove session_start(); from the middle of your code and put in the first line of execution, just after opening the php tag: <?php session_start();

  • That’s what I said @Kaduamaral :) It’s the same situation. put session_start() at the beginning of the file, because in between it never works.. At least with me, it never worked!

  • I changed and keeps appearing NULL, in var_dump.

  • @Andrébaill, I took session_start from where I was and moved to the first line. .

  • @Kaduamaral, you have another suggestion?

  • Any errors displayed? Enable errors ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); to make sure that...

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.