Jump to content


Photo

Login script


  • Please log in to reply
1 reply to this topic

#1 Ink

Ink
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 28 July 2006 - 10:24 AM

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 http://munchmoller.com/ink/blogg.php (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:
<?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");
}
}
?>


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 July 2006 - 11:49 AM

Try this 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();
}

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users