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 11 of 11
  1. #1
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Redirect with Sessions

    I am using sessions to authorize users. I would like to re-direct a user from one page to another, but using sessions sends header information immeadiately. include() doesn't work either. how can i re-direct users after sending session headers?
    "There is more than one way to do it."

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Location
    Jackson, Georgia
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just print a meta refresh tag to the page
    Designer's Toolz; Web & software development community.

    Get your coding questions answered:
    DTZ Forums

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would like to re-direct a user from one page to another, but using sessions sends header information immeadiately.

    Are you sure?
    I do that all the time. I have a session_start() on top of each page (inside an include of course) and i can redirect just fine. We are talking about stuff like
    PHP Code:
    session_start();
    $_SESSION['test']='going to redirect';
    header('Location: test.php');
    die(); 
    right ?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    when using
    PHP Code:
    session_start();
    header("Location: list.php"); 
    i get the error
    Warning: Cannot modify header information - headers already sent by (output started at /home/web/save.php:9) in /home/web/save.php on line 25

    i'll use the meta-refresh thingy...
    "There is more than one way to do it."

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The code you posted is not the code you actually used to get the error.
    Post the complete code --> all the 25 top lines.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #6
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    session_start();
    if (!isset(
    $_SESSION['authed']) || $_SESSION['authed'] != true) {
        require 
    'functions.php';
        
    display_login();
        exit;
    }
    $file $_POST['file'];
    echo 
    "<P>$file</P>";
    $rte $_POST['rte1'];
    echo 
    "<DIV>$rte</DIV>";
    $handle fopen('pages/'.$file"r");
    $contents fread ($handlefilesize ('pages/'.$file));
    fclose($handle);
    if (!
    is_writable($file)) {
        echo 
    "<P>$file is not writeable</P>";
    }
    $array explode('<!-- editable content -->'$contents);
    $array[1] = $_POST['rte1'];
    $handle1 fopen('pages/'.$file"w");
    $string implode("<!-- editable content -->"$array);
    fwrite($handle1$string);
    fclose($handle1);

    header("Location: list.php"); 
    "There is more than one way to do it."

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to redirect, then NO OUTPUT should have been sent to the browser. The

    echo "<P>$file</P>"; // Line 9 probably
    echo "<DIV>$rte</DIV>";
    echo "<P>$file is not writeable</P>";

    shouldn'ty be there.
    It's the first of these echo's that causes the error.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #8
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for fixing it.

    i was being really dumb. i added those in before for some debugging, and never even crossed my mind.
    "There is more than one way to do it."

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome.

    It's always little things like this (PS : trust the errormessages )
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #10
    New Coder
    Join Date
    Mar 2004
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can also use a function
    Thats what I ended up doing And it works great

    Code:
    Function redirect()
    {
    
    
       header('Location: ./index.php');
    
    
    }
    basically
    Just be sure there isnt any html tags in just yet, cause that was screwing my pages up there

  • #11
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Well that function is completely useless. You're just adding pointless extra filesize to do exactly the same as what the header would do on it's own


  •  

    Posting Permissions

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