Jump to content

Recommended Posts

Hello all,

 

I'm new to any kind of coding, but I recently graduated college with an English degree and decided to try to become a technical writer, but quickly realized I would need to learn some basic coding to publish stuff as many companies are moving away from paper.  Anyway, that's the background to why I'm about to ask a really simple question:

 

I wrote a login script, and it rejects people correctly who don't have the correct credentials, and it accepts the people that do, but while the failed attempts send the appropriate alert (the alert also pops up when u first open the page, which if you all can figure out why and stop it, that would be awesome, but its not the main problem), for those who do log in it does not send them to the link that I'm trying to send them to upon log in.  Instead, they stay on the same page, but the login text boxes are gone.  Any help would be appreciated, thanks.  Here is the code:

<html>

<body style="background-color:rgb(240,230,200);font-family:Times;font-size:110%;">

<p style="text-align:center;font-family:Arial;font-size:250%"> ///text removed for privacy///</p>

<p style="text-align:center;font-family:Arial;font-size:200%"> ////text removed for privacy </p>

<CENTER><img src="////removed for privacy/////" width="700" height="500"/></Center>

<p style="text-align:center;"> To access the site, please use enter your User ID and Password. </p>

<center>

<?php error_reporting (E_ALL ^ E_NOTICE); ?>

<?php

session_start();

include("passwords.php");

if ($_POST["ac"]=="log") { 

    if ($USERS[$_POST["username"]]==$_POST["password"]) {

          $_SESSION["logged"]=$_POST["username"];

    } else {

          echo 'Please enter a vaild Username and Password';

    };

};

if (array_key_exists($_SESSION["logged"],$USERS)) 

    header("index.html");

else {

echo "<script>alert('Please enter valid Username and Password')</script>";

    echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> ';

    echo 'Username: <input type="text" name="username" /><br />';

    echo 'Password: <input type="password" name="password" /><br />';

    echo '<input type="submit" value="Login" />';

    echo '</form>';

}

?>

</center>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/245378-login-link-not-working/
Share on other sites

sorry, unsure what you mean by code tag, first post here, or anywhere regarding code.  the buttons currently are fine as they are - when the page loads the first time, and when it rejects a user.  however, instead of linking to the next page if their username and password are correct, it simply keeps them at the same page (even url is the same) but the input fields are gone.  I want to make it where it goes to a whole other page when they login correctly.  also, i'm not sure why the alert is appearing before they even attempt to login the first time, but as it's not affecting functionality, it's only a minor issue.

when creating a post here, one of the 'buttons' is the # sign. If you click on it, there will be an opening and closing 'code tag'. By placing your code between these two tags it makes it easier for people to distinguish what part of your post is code and what part is explanation/question/etc

Ok, then if this will help, here is the code again:

 

<html>
<body style="background-color:rgb(240,230,200);font-family:Times;font-size:110%;">
<p style="text-align:center;font-family:Arial;font-size:250%"> ///text removed for privacy///</p>
<p style="text-align:center;font-family:Arial;font-size:200%"> ////text removed for privacy//// </p>
<CENTER><img src="////removed for privacy/////" width="700" height="500"/></Center>
<p style="text-align:center;"> To access the site, please use enter your User ID and Password. </p>
<center>
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php 
session_start(); 
include("passwords.php"); 
if ($_POST["ac"]=="log") {  
     if ($USERS[$_POST["username"]]==$_POST["password"]) {
          $_SESSION["logged"]=$_POST["username"]; 
     } else { 
          echo 'Please enter a vaild Username and Password'; 
     }; 
}; 
if (array_key_exists($_SESSION["logged"],$USERS))   
    header("index.html");
    else {
    echo "<script>alert('Please enter valid Username and Password')</script>";
     echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> '; 
     echo 'Username: <input type="text" name="username" /><br />'; 
     echo 'Password: <input type="password" name="password" /><br />'; 
     echo '<input type="submit" value="Login" />'; 
     echo '</form>'; 
   }
?>
</center>
</body>
</html>

 

What I really need to know is why the link in line 20

header("index.html");

is not working.

While you should look at the link, the simple solution here is to do this:

 

<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start(); 
include("passwords.php"); 
if ($_POST["ac"]=="log") {  
     if ($USERS[$_POST["username"]]==$_POST["password"]) {
          $_SESSION["logged"]=$_POST["username"]; 
     } else { 
          echo 'Please enter a vaild Username and Password'; 
     }; 
}; 
if (array_key_exists($_SESSION["logged"],$USERS))   
    header("index.html");
   }
?>
<html>
<body style="background-color:rgb(240,230,200);font-family:Times;font-size:110%;">
<p style="text-align:center;font-family:Arial;font-size:250%"> ///text removed for privacy///</p>
<p style="text-align:center;font-family:Arial;font-size:200%"> ////text removed for privacy//// </p>
<CENTER><img src="////removed for privacy/////" width="700" height="500"/></Center>
<p style="text-align:center;"> To access the site, please use enter your User ID and Password. </p>
<center>
<?php
   // I wouldn't code this here, but i'm too lazy to take all your php off of it.
   
    echo "<script>alert('Please enter valid Username and Password')</script>";
     echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> '; 
     echo 'Username: <input type="text" name="username" /><br />'; 
     echo 'Password: <input type="password" name="password" /><br />'; 
     echo '<input type="submit" value="Login" />'; 
     echo '</form>'; 
?>
</center>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.