Jump to content

Login script


Ink

Recommended Posts

Hey I got some problems with this logginscript, I dont know how to get the loginform to disapare when the bloggform apars... and when i try to use the wrong password it wont tell me that its wrong...
try it at [url=http://munchmoller.com/ink/blogg.php]http://munchmoller.com/ink/blogg.php[/url] (it wont blogg on my page as that obyusly would be a bit dumb:P anny one that can help me?

here is the code:
[code]<?php

$username = "ink";
$password = "pass";
$realdate  = date("d.m.Y");
$username2 = $_POST['userlog'];
$password2 = $_POST['passlog'];
?>

<form name="form" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    <label for="userlog">Username:</label><br />
    <input type="text" name="userlog">
    <br /><label for="passlog">Password:</label><br />
    <input type="password" name="passlog">
    <br /><input type="submit" name="Submit" value="Login"><br />
</form>

<?php

if($username2 != $username and $password2 != $password){ 
if(($username != $username2) and ($password != $password2)){
  echo "Wrong.<br /><a href=index?side=blogg>Back</a>"; 
  exit;
}else{

?>

<div align="center"><h2>Nytt blogginnlegg.</h2></div>
<form name="form2" action="index.php?side=bloggsend" method="post" class="style1">
<label for="date">Dato:</label><br /> 
    <input type="text" name="date" class="text2" value="<?php echo $realdate;?>"><br />
<label for="headline">Overskrift</label><br />
    <input type="text" name="headline" class="text2"> <br />
Innlegg:<br />
    <textarea cols="75" rows="25" name="mld" class="text2"></textarea>
    <br /><div align="right">-Ink</div>
    <input name="submit" type="submit" class="knapp" value="Send">
    <input name="reset" type="reset" class="knapp" value="Reset">
    <br />
</form>
Gamle innlegg: <br /><br />

<?php
$fil=fopen("news.txt", "r");
$innhold=fread($fil, filesize("news.txt"));
fclose($fil);
echo("$innhold");
}
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/15872-login-script/
Share on other sites

Try this code:
[code]<?php
// setup a function to display our login form
function displayForm($user='', $pass='')
{
    echo '<form name="form" method="post" action="' . $_SERVER['PHP_SELF'] .'">
  <label for="userlog">Username:</label><br />
    <input type="text" name="userlog" value="' . $user .'"><br />
  <label for="passlog">Password:</label><br />
    <input type="password" name="passlog" value="' . $pass .'"><br />
  <input type="submit" name="Submit" value="Login">
</form>';
}

//check that the user has submitted the login form
if(isset($_POST['Submit']))
{
    $username = "ink";
    $password = "pass";
    $realdate  = date("d.m.Y");
    $username2 = $_POST['userlog'];
    $password2 = $_POST['passlog'];

    // if the form has been submitted we'll now check the username and password
    if($username2 != $username and $password2 != $password)
    {
        // if the chekc didnt pass we'll display the following message
        echo 'Invlid Username or Password, try again';

        // and show our login form.
        displayForm($username2, $password2);
    }
    // User has logged in succesfully, s we display the blog
    else
    {
?>
<div align="center"><h2>Nytt blogginnlegg.</h2></div>

<form name="form2" action="index.php?side=bloggsend" method="post" class="style1">
  <label for="date">Dato:</label><br />
    <input type="text" name="date" class="text2" value="<?php echo $realdate;?>"><br />
  <label for="headline">Overskrift</label><br />
    <input type="text" name="headline" class="text2"><br />
  Innlegg:<br />
  <textarea cols="75" rows="25" name="mld" class="text2"></textarea><br />
  <div align="right">-Ink</div>
    <input name="submit" type="submit" class="knapp" value="Send">
    <input name="reset" type="reset" class="knapp" value="Reset">
</form>
Gamle innlegg:<br />
<br />
<?php
        $fil = fopen("news.txt", "r");
        $innhold = fread($fil, filesize("news.txt"));
        fclose($fil);
        echo $innhold;
    }
}
// user hasnt submitted the form yet, so we'll display the form.
else
{
    displayForm();
}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/15872-login-script/#findComment-65103
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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