Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts

    Need help with a function for redirecting

    Hi!
    I made this code as a function:

    Code:
    function isLoggedIn() 
            {
                    session_start();
                if (isset($_SESSION['ulogovan']))
                {
                    echo 'You are logged as: ' . $_SESSION['ulogovan'];
                    
                }
                else
                {
                    echo 'Your are not logged...';
                    header("location:login_form.php");
                    
                }
                
            }
    Ok, the problem is:
    If I upload the whole project to my web server and try the code I got all the time the error because of the "header()" function and php.ini settings something like this:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter...
    or

    Warning: Cannot modify header information - headers already sent by...
    Ok, I know why this happen but how to make an IF-ELSE checking and redirecting to another page if the ELSE statement is reached without the "header()" function?

    BUT!
    I have to track the logged user session too so I know on other pages if the real logged in user are the one who visits the member area...

    I have no option to change the php.ini file on the server because it is out of my administration reach and I have no access to that.

    Any idea?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    session_start() must be the first line in your php code/page.

    You can't have anything outputted to the browser before session_start or a header.

  • Users who have thanked Nightfire for this post:

    joda (02-20-2012)

  • #3
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts
    Sorrty but dosen't work.
    I got from the admin personal a mail where they say the output_bufferin is set to off in php.ini and it will be off.

    Any idea pls ?

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    So you deleted echo 'Your are not logged...'; and moved session_start() to the very top of the page?

  • Users who have thanked Nightfire for this post:

    joda (02-20-2012)

  • #5
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts
    Thank's for suggestion, it worked!


  •  

    Posting Permissions

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