session login and logout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mubs
    New Member
    • Mar 2007
    • 77

    session login and logout

    Hi,

    On my website i am trying to end a session and return to another page but i keep gettin this error..

    Object not found!
    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.


    <?
    session_start() ;
    if (!session_is_re gistered(myuser name)) {
    header("locatio n:mainlogin.php ");
    }
    ?>

    <html>
    <head><title>We lcome</title>
    </head>
    <body>
    <h1> Login successful</h1>

    <p>
    <a href="logout.ph p"> Log Out!</a></p>


    </body>
    </html>
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    mainlogin.php is the problem?
    It's saying the page doesn't exist - no way I can tell if the page does or doesn't exist because I have no idea. But the server is saying it doesn't. Are you linking to the correct directory? Check the filename and extension.

    Also, session_registe r is deprecated. Use $_SESSION['index'] instead.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Mubs.

      You're setting a Location: header, but then you continue to output HTML.

      Which do you want? To redirect the browser to a different page, or to display content for the page? You can't have it both ways, I'm afraid.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by pbmods
        Heya, Mubs.

        You're setting a Location: header, but then you continue to output HTML.

        Which do you want? To redirect the browser to a different page, or to display content for the page? You can't have it both ways, I'm afraid.
        You must of overlooked it!

        He sets the header in an IF check. Therefore, either it redirects or shows the html.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Originally posted by markusn00b
          You must of overlooked it!

          He sets the header in an IF check. Therefore, either it redirects or shows the html.
          I see the if... but there's neither an else nor an exit statement. This might not be causing the problem, but it's rather wasteful to output HTML that the User will never see.

          IE also is extraordinarily picky about header problems, so I say it's worth a shot.

          Either add an exit statement after the header call:

          [code=php]
          if (!session_is_re gistered(myuser name)) {
          header("locatio n:mainlogin.php ");
          exit;
          }
          [/code]

          Or enclose your HTML in an else block:
          [code=php]
          if (!session_is_re gistered(myuser name)) {
          header("locatio n:mainlogin.php ");
          }
          else
          {

          ?>
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          .
          .
          .
          </html>
          <?php } ?>
          [/code]
          Last edited by pbmods; Jun 27 '08, 12:13 AM. Reason: Removed XML declaration because OP has short tags turned on.

          Comment

          • Mubs
            New Member
            • Mar 2007
            • 77

            #6
            Originally posted by pbmods
            I see the if... but there's neither an else nor an exit statement. This might not be causing the problem, but it's rather wasteful to output HTML that the User will never see.

            IE also is extraordinarily picky about header problems, so I say it's worth a shot.

            Either add an exit statement after the header call:

            [code=php]
            if (!session_is_re gistered(myuser name)) {
            header("locatio n:mainlogin.php ");
            exit;
            }
            [/code]

            Or enclose your HTML in an else block:
            [code=php]
            if (!session_is_re gistered(myuser name)) {
            header("locatio n:mainlogin.php ");
            }
            else
            {

            ?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            .
            .
            .
            </html>
            <?php } ?>
            [/code]

            thanx for replies ppl..i have managed to get it working..

            Comment

            Working...