Web Hosting Talk







View Full Version : PHP Challenge #5


DoobyWho
08-12-2002, 04:54 PM
TODO: Write a script to submit a username and password to enter a page. If the username and password does not match the variable hardcoded in the script show the login form again with an error message. The password field should be private so that as you type you'll see ****. Upon correct login display a list of banners in an array from a select box to display (you can use either a single or multi-dimensional array). Upon choosing a banner and pressing submit, then have the script print the banner to the browser. This will allow for an account of banners that only a person with the correct username/password can get in and view by image path. Use either a for() or while() loop to create the dropdown SELECT box with the available banners in the array and hidden form tags to transfer the validated password. This should all be one self-contained script with NO include() or require() files.

SicChild
08-12-2002, 04:55 PM
What's the winning prize?

dbzgod
08-12-2002, 05:26 PM
I believe its just a challenge. No prize.

Studio64
08-12-2002, 06:52 PM
Well... It sure as hell aint pretty but, it works :D


<title>PHP Challenge #5</title>
<?

function login()
{
?>
<form action="pchal.php">
<input type="hidden" name="loc" value="verify">
User : <input type="text" name="user" value=""><br>
Pass : <input type="password" name="pass" value="">
<input type="submit" value="login">
</form>
<?
}
function check($user, $pass)
{ return (($user == "php") && ($pass == "challenge")); }
function display_banners($user, $pass)
{
// Banner Array
$num_ban = 4;
$banner[1][1] = "Banner #1";
$banner[1][2] = "banner/1.jpg";
$banner[2][1] = "Banner #2";
$banner[2][2] = "banner/2.jpg";
$banner[3][1] = "Banner #3";
$banner[3][2] = "banner/3.jpg";
$banner[4][1] = "Banner #4";
$banner[4][2] = "banner/4.jpg";

?>
<form action="pchal.php">
<input type="hidden" name="user" value="<?echo $user?>">
<input type="hidden" name="pass" value="<?echo $pass?>">
<input type="hidden" name="loc" value="banner">
<select name="ban">
<?
for ($x = 1; $x <= $num_ban; $x++)
{
?><option value="<?echo $banner[$x][2]?>"><?echo $banner[$x][1]?></option><?
}

?>
</select>
<input type="submit" value="Choose Banner">
</form><hr>
<a href="pchal.php">Log Out</a>
<?
}

if (!isset($loc))
login();
else
{
$auth = 0;
if ($loc == "verify")
{
if (isset($user) && isset($pass))
if (check($user, $pass))
$loc = "display";
else
{
?>Login Failed<br><?
login();
}
}
if (($loc == "display") && check($user, $pass))
display_banners($user, $pass);

if (($loc == "banner") && check($user, $pass))
{
?><img src="<?echo $ban?>"><?
display_banners($user, $pass);
}
}
?>

http://www.std64.com/pchal.php

Working version

I'm sure others will have cleaner versions :)

tzdesigner
08-12-2002, 07:07 PM
Nice script-It worked

DoobyWho
08-13-2002, 01:53 AM
Good job :)

SicChild
08-13-2002, 08:31 PM
sorry. seemed like this guy was just getting people to make scripts for him for free while you think it's a *challenge*. heh. Sorry, I must be mistaken.

RackNine
08-13-2002, 08:46 PM
sorry. seemed like this guy was just getting people to make scripts for him for free while you think it's a *challenge*. heh. Sorry, I must be mistaken.

PHP Challenge #6-

Mow my lawn.

-Matt