simple session login problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank

    #1

    simple session login problem

    I created a php page that will create a session for a user. My problem
    is that once they are logged in, I dont know how to send them to the
    secure page. I dont know where to place the following lines of code:
    (also not sure where on the server the pages are placed)

    header("Locatio n: http://www.mysite.com/index.html");
    exit;

    Original code-------------------------------------------------
    <?
    session_start() ;
    ?>
    <html>
    <head>
    <title> </title>
    </head>
    <body>
    <?
    $_Username = "user";
    $_Password = "password";
    // If the form was submitted
    if ($_POST['Submitted'] == "True") {
    // If the username and password match up, then continue...
    if ($_POST['Username'] == $_Username && $_POST['Password'] ==
    $_Password) {
    // Username and password matched, set them as logged in and
    set the
    // Username to a session variable.
    $_SESSION['Logged_In'] = "True";
    $_SESSION['Username'] = $_Username;
    }
    }
    if ($_SESSION['Logged_In'] != "True") {
    echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] .
    "\">
    Username: <input type=\"textbox\ " name=\"Username \"><br />
    Password: <input type=\"textbox\ " name=\"Password \"><br />
    <input type=\"hidden\" name=\"Submitte d\" value=\"True\">
    <input type=\"Submit\" name=\"Submit\" >
    </form>";
    }
    else
    {
    echo "You are logged in as: <b>" . $_SESSION['Username'] . "</b>
    <br /><a href=\"" . $_SERVER['PHP_SELF'] .
    "?mode=logout\" >Logout</a>";
    }
    if ($_GET['mode'] == "logout") {
    session_start() ;
    $_SESSION = array();
    session_destroy ();
    echo "<META HTTP-EQUIV=\"refresh \" content=\"1; URL=" .
    $_SERVER['PHP_SELF'] . "\">";
    }
    ?>


    <p>&nbsp;</p>
    </body>
    </html>
  • Anthony

    #2
    Re: simple session login problem

    On 16 Oct 2004 12:42:34 -0700, emusic32@hotmai l.com (Frank) wrote:
    [color=blue]
    >I created a php page that will create a session for a user. My problem
    >is that once they are logged in, I dont know how to send them to the
    >secure page. I dont know where to place the following lines of code:
    >(also not sure where on the server the pages are placed)
    >
    >header("Locati on: http://www.mysite.com/index.html");
    >exit;[/color]

    Place it right after you create the sessions upon successful user
    login. You probably also want to check and verify the form variables
    for security.

    Anthony


    Comment

    • Frank

      #3
      Re: simple session login problem

      If I place it after a sucessful login, I get ....
      Warning: Cannot modify header information - headers already sent by
      (output started at /my server path/my site.com/login1.php:9) in /my
      server path/my site.com/login1.php on line 41


      successful login code...SNIP>>>> >>>>>>>>>>>>>>> >>>>>>>
      echo "You are logged in as: <b>" . $_SESSION['Username'] . "</b>
      <br /><a href=\"" . $_SERVER['PHP_SELF'] .
      "?mode=logout\" >Logout</a>";
      header("Locatio n: http://www.mysite.com/index.html");
      exit;[color=blue][color=green][color=darkred]
      >>>>>>>>>>>>>>> >>>>>>>>>>>>[/color][/color][/color]

      Anthony <cajuntechie@gm ail.com> wrote in message news:<109797049 0.76HQl5mnEbwbH 2IbEhxF+w@teran ews>...[color=blue]
      > On 16 Oct 2004 12:42:34 -0700, emusic32@hotmai l.com (Frank) wrote:
      >[color=green]
      > >I created a php page that will create a session for a user. My problem
      > >is that once they are logged in, I dont know how to send them to the
      > >secure page. I dont know where to place the following lines of code:
      > >(also not sure where on the server the pages are placed)
      > >
      > >header("Locati on: http://www.mysite.com/index.html");
      > >exit;[/color]
      >
      > Place it right after you create the sessions upon successful user
      > login. You probably also want to check and verify the form variables
      > for security.
      >
      > Anthony[/color]

      Comment

      • Lüpher Cypher

        #4
        Re: simple session login problem

        Frank wrote:[color=blue]
        > If I place it after a sucessful login, I get ....
        > Warning: Cannot modify header information - headers already sent by
        > (output started at /my server path/my site.com/login1.php:9) in /my
        > server path/my site.com/login1.php on line 41
        >
        >
        > successful login code...SNIP>>>> >>>>>>>>>>>>>>> >>>>>>>
        > echo "You are logged in as: <b>" . $_SESSION['Username'] . "</b>
        > <br /><a href=\"" . $_SERVER['PHP_SELF'] .
        > "?mode=logout\" >Logout</a>";
        > header("Locatio n: http://www.mysite.com/index.html");
        > exit;
        >[/color]

        You have to sent headers before the content, and you already echoed the
        login name. You can use buffered output (ob_* functions), or maybe
        accumulate output in a variable and then echo it at the end (although I
        don't see a readon why to output anything if you are redirecting anyway :))

        Comment

        Working...