Creating a new login prompt for website

root said:
ok... in that case this should work for you...

Code:
<?php

ob_start();

$user_name = "ALEC";
$pass_word = "password";

$username = @$_POST['username'];
$password = @$_POST['password'];

if(($user_name == $username)&&($pass_word == $password))
{
header('Location: index_1.html');
}
else
{
echo '
<form method="POST">
<input type="text" name="username"><br />
<input type="password" name="password"><br />
<input type="submit">
</form>
';
}
?>

you can obviously change the username and password to whatever you like.
ok thanks! i'll try it out
 
Although with that method, anyone can just go to supposed index_1.html and have total access. Whereas, you could do something like this, roots script slightly modified:
Code:
<?php
session_start();

$user_name = "ALEC";
$pass_word = "password";

$username = @$_POST['username'];
$password = @$_POST['password'];

if(($user_name == $username)&&($pass_word == $password))
{
$_SESSION['Verified'] = "Yes";
header('Location: index_1.html');
}
else
{
echo '
<form method="POST">
<input type="text" name="username"><br />
<input type="password" name="password"><br />
<input type="submit">
</form>
';
}
?>
And on index_1.html or whereever it is redirecting (make a php page):
Include this:
Code:
<?php
session_start();
if ( (!isset($_SESSION['Verified'])) )
	{
		exit(); // if not logged in, show a blank page
	} else {
	
	// your sites code here....
	
	}
?>
 
Dyamito said:
Although with that method, anyone can just go to supposed index_1.html and have total access. Whereas, you could do something like this, roots script slightly modified:
Code:
<?php
session_start();

$user_name = "ALEC";
$pass_word = "password";

$username = @$_POST['username'];
$password = @$_POST['password'];

if(($user_name == $username)&&($pass_word == $password))
{
$_SESSION['Verified'] = "Yes";
header('Location: index_1.html');
}
else
{
echo '
<form method="POST">
<input type="text" name="username"><br />
<input type="password" name="password"><br />
<input type="submit">
</form>
';
}
?>
And on index_1.html or whereever it is redirecting (make a php page):
Include this:
Code:
<?php
session_start();
if ( (!isset($_SESSION['Verified'])) )
	{
		exit(); // if not logged in, show a blank page
	} else {
	
	// your sites code here....
	
	}
?>
ok thanks, i'm going to try this tommorrow. +1
 
I'm not trolling for members root. For all you know I could have been giving him Buzz's e-mail address

stop trying to be smart and consider this for one moment.

Giving someone buzz's email address is of absolutly no help to this forum what-so-ever...

the whole point of a forum is that people ask questions and other people answer in the thread...

that way when the next person comes along and searches for a login script, they can find one, not get presented with a dead end thread that was someone who was supposed to be a great member of the forums just leaving threads dead ended with no answer to the question.

I think that you miss the point that the forums are not only meant to help the person asking the question, but are also open to help all and sundry who want answers.

for Christs sake you admin your own forum, surely you have some awareness of what consitutes a useful post and what doesn't


-------------------------
as for the sessions.

yes, I had thought about sessions, but Mike said he wasn't bothered about making it too secure.

Dyamito, you cut off the ob_start,
i assume that this PHP file will be included somewhere half way down a page, so he'll need that to buffer the outpu headers, else the headers will be sent and can't be changed to add session information...

Do you have output buffering turned on for your test server...? (wouldn't show as a problem if you did..)
 
Even if you weren't being secure, that's really basics, anyone could get there. Although, I haven't really been programming in a while so I even had trouble with that script, so if I make a mistake, it seems root is able to correct me.
 
Back
Top Bottom