0

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 }

?>
1
  • Well, the redirect is commented ... It can't work.
    – j0k
    Aug 28, 2012 at 10:32

1 Answer 1

1

It should be:

<?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
  }

?>
5
  • 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//
    – Alb
    Aug 28, 2012 at 10:35
  • @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
    Aug 28, 2012 at 10:36
  • 1
    @Fluffeh: Technically, the space isn't needed, however the capitalisation is likely important Aug 28, 2012 at 10:38
  • @MatthewScharley Fair enough, I have learned a new thing today :)
    – Fluffeh
    Aug 28, 2012 at 10:39
  • @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. :) Aug 28, 2012 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.