Jump to content

odysseusming

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

odysseusming's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. gevans - I pasted your code into the page.php page and it gave me: array(0) { }
  2. Yes - on the first attempt it just reloads the login page. But if I try to go to the page.php page first, it bounces me back to the login.php page (as it should) - and then if I try to login, it works on the first try. Makes me think it's something with the script on the page.php page. And I added the "die;" you suggested - still no luck. Any further thoughts...
  3. not sure what you mean by "validation code"? which code exactly?
  4. I'm trying to create a simple PHP login, where the user logs in on the first page (login.php), and if the login is correct, is directed to the second page (page.php). The problem with my code is that the user is required to login twice in order to be successfully taken to the second page (page.php). Here's my code: login.php page code: <?php session_start(); // Define your username and password $username = "a"; $password = "b"; # define a redirect url $redirect_url = "http://www.mydomain.com/page.php"; if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == "yes") { header("Location: $redirect_url"); } if (($_POST['txtUsername'] == $username) && ($_POST['txtPassword'] == $password)) { $_SESSION['logged_in'] = "yes"; header("Location: $redirect_url"); die; } ?> <h2>Please Login</h2> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p> <br/> <label for="txtUsername">Username*</label> <br/> <input name="txtUsername" type="text" id="txtUsername" size="30" /> <br/> <label for="txtPassword">Password*</label> <br/> <input name="txtPassword" type="password" id="txtPassword" size="30" /> <br/> <br/> <input name="Submit" type="submit" value="Login" /> </p> </form> page.php page code: <?php session_start(); if ($_SESSION['logged_in'] !== "yes") { header("Location: http://www.mydomain.com/login.php"); die; } ?> login successful
  5. thanks - but I pasted in that code and it's still requiring me to login twice...
  6. Still requiring me to login twice. My code now looks like this: login.php page code: <?php session_start(); // Define your username and password $username = "a"; $password = "b"; # define a redirect url $redirect_url = "http://www.mydomain.com/page.php"; if (($_POST['txtUsername'] == $username) && ($_POST['txtPassword'] == $password)) { $_SESSION['logged_in'] = "yes"; header("Location: $redirect_url"); die; } ?> <h2>Please Login</h2> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p> <br/> <label for="txtUsername">Username*</label> <br/> <input name="txtUsername" type="text" id="txtUsername" size="30" /> <br/> <label for="txtPassword">Password*</label> <br/> <input name="txtPassword" type="password" id="txtPassword" size="30" /> <br/> <br/> <input name="Submit" type="submit" value="Login" /> </p> </form> page.php page code: <?php session_start(); if ($_SESSION['logged_in'] !== "yes") { header("Location: http://www.mydomain.com/login.php"); die; } ?> successful
  7. Yeah - I can't figure it out. If I try to first go to the "page.php" page, it redirects me back to the "login.php" as it's supposed to - and then I can login successfully on the first try. But if I go straight to the "login.php" page, I have to login twice.
  8. Thanks - those changes got me to the "page.php" page, but I had to login twice? Any thoughts...
  9. I'm trying to create a simple PHP login, where the user logs in on the first page (login.php), and if the login is correct, is directed to the second page (page.php). I don't want the user to be able to access the second page without logging in, but I'm having trouble getting the code to work. login.php page code: <?php // Define your username and password $username = "a"; $password = "b"; # define a redirect url $redirect_url = "http://www.mydomain.com/page.php"; if (($_POST['txtUsername'] == $username) && ($_POST['txtPassword'] == $password)) { if (!$_SESSION) { session_start(); } $_SESSION['logged_in'] = "yes"; header("Location: $redirect_url"); die; } ?> <h2>Please Login</h2> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p> <br/> <label for="txtUsername">Username*</label> <br/> <input name="txtUsername" type="text" id="txtUsername" size="30" /> <br/> <label for="txtPassword">Password*</label> <br/> <input name="txtPassword" type="password" id="txtPassword" size="30" /> <br/> <br/> <input name="Submit" type="submit" value="Login" /> </p> </form> page.php page code: <?php if ($_SESSION['logged_in'] !== "yes") { header("Location: http://www.mydomain.com/login.php"); die; } ?> successful
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.