www.webdeveloper.com
Results 1 to 6 of 6

Thread: I'm going crazy!PHP "IF" NOT WORKING AT ALL! please help

  1. #1
    Join Date
    Sep 2012
    Posts
    12

    Unhappy I'm going crazy!PHP "IF" NOT WORKING AT ALL! please help

    Hey there...
    Last night I started writing a simple code for login...It's simple but one "if" does not work at all! here is my code:
    PHP Code:

    <?php
    session_start
    ();


    if(empty(
    $_SESSION['login']))
    {

    header("Location: http://mywebsite.com/");

    }
    .
    .
    .
    I tried even "if(1==1)"!! but still not working! Please somebody help

  2. #2
    Join Date
    Jul 2005
    Location
    faisalabad, punjab, pakistan
    Posts
    241
    try printing a string in place of header.

  3. #3
    Join Date
    Sep 2012
    Posts
    12
    I tried it already...I put an echo before and after if and it works!...the problem is with "if"

  4. #4
    Join Date
    Dec 2012
    Posts
    5
    I tried the code and it works for me as it is.The problem isn't in these lines.

  5. #5
    Join Date
    May 2004
    Location
    chennai, tamil nadu, India
    Posts
    443
    Quote Originally Posted by enrique View Post
    Hey there...
    Last night I started writing a simple code for login...It's simple but one "if" does not work at all! here is my code:
    PHP Code:

    <?php
    session_start
    ();


    if(empty(
    $_SESSION['login']))
    {

    header("Location: http://mywebsite.com/");

    }
    .
    .
    .
    I tried even "if(1==1)"!! but still not working! Please somebody help
    have you tried printing $_SESSION['login'] ?
    Chris, Senior Developer,
    Php laravel developers,
    www.chrisranjana.com

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,246
    Do some debugging, and remember that nothing can be output to the client prior to either the session_start() or the header() function calls.
    PHP Code:
    <?php
    ini_set
    ('display_errors'true);
    error_reportgin(E_ALL);

    session_start();

    error_log("before if():\n".var_export($_SESSIONtrue));

    if(empty(
    $_SESSION['login']))
    {
        
    error_log("In the if()");
        
    header("Location: http://mywebsite.com/");
        exit; 
    // <<<  assuming you don't want any other code to process past this point?
    }

    error_log("after if()");
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles