News:

Wondering if this will always be free?  See why free is better.

Main Menu

Php Question

Started by Alan S, August 06, 2006, 11:31:01 AM

Previous topic - Next topic

Alan S

I have a simple php pass protect page script

<?php

// Define your username and password
$username = "smithalan2";
$password = "theteenzone";


if (
$_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password ) {

?>



but i want to have 2 usernames and 2 passwords , im not sure what code to edit though , im guessing i'd add another variable like $username2 = " ***"; or something but im not sure what i'd add on line if ($_POST['txt................etc?

Help Would be appreciated
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Alan S

Anyone?? this is the actual whole code

<?php

// Define your username and password
$username = "smithalan2";
$password = "theteenzone";


if (
$_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password ) {

?>

<h1>Login</h1>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <p><label for="txtUsername">Username:</label>
    <br /><input type="text" title="Enter your Username" name="txtUsername" /></p>

    <p><label for="txtpassword">Password:</label>
    <br /><input type="password" title="Enter your password" name="txtPassword" /></p>

    <p><input type="submit" name="Submit" value="Login" /></p>

</form>

<?php

}
else {

?>

<p><font color="white">No Staff News Yet But Check Back Soon For More Details!</font></p>

<?php

}

?>
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Alan S

emm *bump*      anyone?????
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

SleePy

thats one messed up script.
should be like this:

if ($_POST['txtUsername'] == $username && $_POST['txtPassword'] == $password ) {

That says if username and password are correct it will display your page. otherwise give them a login screen. maybe and error 2.
then you can double it up easy

if (($_POST['txtUsername'] == $username && $_POST['txtPassword'] == $password ) || ($_POST['txtUsername'] == $username2 && $_POST['txtPassword'] == $password2 )) {

Im glad you disabled it agaisn't url insertion. but i would take it a step further.
md5 your password to add some security on it. maybe your name to if you want. could use some other encryption as well like adding your site name in and such.

just create a php page with a simple md5 in it
<?
echo md5($_GET['a']);
?>

do a=yourpassword in url and it will give md5 of the password. put it in place of our password

then change this password part in your if statement
$txtPassword = md5($_POST['txtPassword']);
Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

JayBachatero

Why not just link it to SMF?
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Alan S

That was just a little script i was playing around on a html/php website.
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Rudolf

How's this?

<?php

// Define your username and password
$usernames = array("username1",'username2','username3');
$passwords = array('password1','password2','password3');

$key = array_search($_POST['txtUsername'],$usernames);
if (
$key === false && array_search($_POST['txtPassword'],$passwords) !=$key) {

?>


You can have as many username-password pair you wish.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Alan S

Thanks ! , i wasnt actually planning on using it on a template at the moment but im getting a idea of something i'll be able to use it in!
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Advertisement: