...

View Full Version : Resolved In-file login script



Pcfr43k
01-27-2010, 12:01 PM
Hello,

I try to write a login script that can be part of the file.
Like this:
{index.php

{index page}

{login}

{restricted page}
}

So I wrote a script but used the GOTO command.

<?

$user = 'admin';
$pass = 'pass';

$userinput = $_POST['userinput'];
$passinput = $_POST['passinput'];

$error = 'Wrong login, try again.';

echo "<html><head><title>Login script</title></head><body>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
Username:<br/>
<input type='text' name='userinput'/><br/>
Password:<br/>
<input type='password' name='passinput'/><br/>
<input type='submit' value='Login' />
</form></body></html>";

if($user==$userinput)
{
if($pass==$passinput)
{goto page;}
else {echo $error;}
}
else {echo $error;}

page:
echo "<p>This content is visable after logging in</p>";
?>

I don't know if this works, but I want this to work on lower version PHP servers.
So I adjusted the script:

<?

$user = 'admin';
$pass = 'pass';

$userinput = $_POST['userinput'];
$passinput = $_POST['passinput'];

$error = 'Wrong login, try again.';

echo "<html><head><title>Login script</title></head><body>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
Username:<br/>
<input type='text' name='userinput'/><br/>
Password:<br/>
<input type='password' name='passinput'/><br/>
<input type='submit' value='Login' />
</form></body></html>";

if($user==$userinput)
{
if($pass==$passinput)
{echo "<p>This content is visable after logging in</p>";}
else {echo $error;}
}
else {echo $error;}

?>

But this is resulting in a white page.

What am I doing wrong?

The scripts I write are as small and simple as is possible by me.

angst
01-27-2010, 01:41 PM
try this;



<?
$user = 'admin';
$pass = 'pass';

$userinput = $_POST['userinput'];
$passinput = $_POST['passinput'];

$LoginFrm = "<html><head><title>Login script</title></head><body>
<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>
Username:<br/>
<input type='text' name='userinput'/><br/>
Password:<br/>
<input type='password' name='passinput'/><br/>
<input type='submit' value='Login' />
</form></body></html>";

if(isSet($userinput)){
if($user == $userinput && $pass == $passinput){
echo "<p>This content is visable after logging in</p>";
} else {
echo "<p>Wrong login, try again.</p>";
echo $LoginFrm;
}
} else {
echo $LoginFrm;
}
?>

Pcfr43k
01-27-2010, 01:52 PM
Yes! That works, thanks.

But what I want to try is to keep the login as one block.
Thats why I like PHP 5.3 and up, because of the GOTO command.

Is there some way to achieve this in PHP 5.2 and lower?

So like this:
{index.php

{login}

{index content}
}

Instead of now:
{index.php

{login start

{index content}
login end}
}

mlseim
01-27-2010, 02:04 PM
Use PHP sessions for log-in, and then once they log in, you can check
the login on any other page. They stay logged-in until they log out or
until they close their browser.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum