La redirección de usuario después de iniciar sesión envía diferentes encabezados

i have this form which makes possible the redirection of the user after he has logged in, what i intend to do is that, after the user arrives at a certain page, i have the condition, if !session->redirect to login.php else, redirect to another page!

What may be wrong with my code here?

<?php include_once("db/envato_db.php"); session_start(); if(!$_SESSION['gal_id']){

header("location:login.php"); // Redirect to login.php page } else {    header('location:galleries.php'); // Redirect to login.php page }

?>

preguntado el 28 de agosto de 12 a las 11:08

Well, the redirect is commented ... It can't work. -

1 Respuestas

Debería ser:

<?php

  include_once("db/envato_db.php");
  session_start();

  if(!$_SESSION['gal_id'])
  {
      header('Location: login.php'); // Redirect to login.php page
  }
  else
  {    
      header('Location: galleries.php'); // Redirect to login.php page
  }

?>

Respondido 28 ago 12, 11:08

I tried it this way.. it doesn't work either, if i set something in the else part, like echo "test" it works, just the redirection doesn't// - Alba

@Alb j0k is right. When i reformatted your code, I un-wittingly corrected it. The redirect was on the same line a comment prior to it. This meant that the second part of your conditition wasn't ever being met. +1 - Fluffeh

@Fluffeh: Technically, the space isn't needed, however the capitalisation is likely important - Mateo Scharley

@MatthewScharley Fair enough, I have learned a new thing today :) - Fluffeh

@Fluffeh: I'm 90% sure that the spec allows for an arbitrary amount of space between the colon and the first parts of the value (including none), but for the sake of consistency and human readability most implementations use a single space between the colon and value. :) - Mateo Scharley

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.