School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / php101 Refresh the current page Week #5 ADVANCED To-Do Assignment
 

 (#9 2003-08-07 16:10:55) Post Reply
Page 0 1

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #5 Advanced TO-DO ASSIGNMENT: 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, then 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.

Post this assignment here so that we can offer comment/critique for you, but also post a URL to the working copy of the script and post the complete source code of the script in your post.

scriptname.php <-- script name

Good luck to you!

 

 (#66 2003-08-19 14:03:21) Post Reply
Page 0 1

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

Heres the URL for my working script:
http://www.katikai.com/ee/assi...0Assignment.php

Heres the URL for all my past projects:
http://www.katikai.com/ee/assignment

Heres my script:

inside 'Week #5 Advanced To-Do Assignment.php'


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #5 Advanced To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<center>
<form method="post" action="username.php">
<input type="hidden" name="action" value="false" />
Username: <br />
<inputtype="text" value="Username" name="username" id="username" onfocus="this.value=''" /><br />
Password: <br />
<input type="password" value="Password" name="password" id="password" onfocus="this.value=''" /><br />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</center>
</body>
</html>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #5 Advanced To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<center>
<?php
//Check to see if you have just come from the first form (that form had set action to false)
if($action=='false'){
//Check to see if the login details are correct
if($username=='Sk8rRIMuk'&$password=='havoctheman'){
//If they are print a welcome message
print("<p>Welcome$username</p>");}
//If they are not correct print an error message and a back link
else{print('<p>Sorry the inputted Username and Password were
incorrect please <a href="Week #5 Advanced To-Do Assignment.php"
>click here to go back</a> and enter the correct username and password</p>'
);}}
//Set the banner arrays
$banner=array(
'<a href="http://www.n00bstories.com" target="_blank"><img src="n00bstories.jpg" border="0" alt="n00bstories" /></a>',
'<a href="http://www.google.co.uk" target="_blank"><img src="google.gif" border="0" alt="Google UK" /></a>',
'<a href="http://www.eagames.com" target="_blank"><img src="eagames.jpg" border="0" alt="EA Games" /></a>',
'<a href="http://www.katikai.com" target="_blank"><img src="katikai.png" border="0" alt="Katikai Webhosting" /></a>'
);
//Set the options to be used in form and be compared
$option=array('n00bstories','Google','EAGames','KatiKai');
?>
<!--Enter The Banner Form-->
Please select a banner:<br />
<form method="post" action="username.php" />
<input type="hidden" name="action" id="action" value="true" />
<select name="formbanner" id="formbanner">
<?phpfor($i=0;$i<4;$i++){
print(
"<option value="$i">$option[$i]</option>");//Set the options via a for()
}?>
</select>
<input type="submit" value="Submit" />
</form>
<?php
//Process the banner forms results
if($action=='true'){
if(
$formbanner=='0'){print($banner[0]);}
if(
$formbanner=='1'){print($banner[1]);}
if(
$formbanner=='2'){print($banner[2]);}
if(
$formbanner=='3'){print($banner[3]);}
}
?>
</center>
</body>
</html>



Still not done week 3 advanced could somebody help me: msnm/e-mail = sk8rrimuk@hotmail.com


 

 (#67 2003-08-19 14:13:17) Post Reply
Page 0 1

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

Sorry forgot to say the Username is Sk8rRIMuk and the Password is havoctheman :)

 

 (#160 2003-09-05 08:08:11) Post Reply
Page 0 1

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

Somebody help!. . . Please!

The following is the code I have written for this assignment. I get a parse error on line 17. I can't see where I am going wrong. Maybe the whole thing is wrong. I need some advice.



<HTML>
<HEAD>
<TITLE>PHP Basic Assignment 5</TITLE>
</HEAD>
<BODY>
<?php
if ($action == "true"){
if (
$username=='phpstudent' & $password=='phptest'){
print(
"Username and Password Accepted");
//Script to store banners in a multidimensional array
//Three banners in three categories
$bannercategory1 = array('BANNERCAT1BAN1.jpg','BANNERCAT1BAN2.jpg','BANNERCAT1BAN3.jpg');
$bannercategory2 = array('BANNERCAT2BAN1.jpg','BANNERCAT2BAN2.jpg','BANNERCAT2BAN3.jpg');
$bannercategory1 = array('BANNERCAT3BAN1.jpg','BANNERCAT3BAN2.jpg','BANNERCAT3BAN3.jpg');
$banners = array($bannercategory1, $bannercategory2, $bannercategory3);
//Script to display banners from the above array
<form method="post" action="phpadvassignment5.php">
<
input type="hidden" name ="action1" value="true">
<
select name="bannerselect">
//Loop to populate the select box.
if ($action1 == "true"){
for (
$i = 0; $i = (count($banners)-1); $i++) {
for (
$j = 0; $j = (count($banners[$i]-1); $j++){
<
option value =

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /web/sites/tdavid/non_public_system/parsemsg.php on line 94

"$banners[$i][$j]\">}}
</select>
</form>
exit
}
exit;
}
else
{
print("
Username and Password are incorrect. Please enter correct values.");
}}
?>
<center>Please enter the username and password to continue:<br>
<b>Hint:</b><br> Username: phpstudent<br> Password:phptest
<form method = "
post" action = "phpbasicassignment5.php">
<input type="
hidden" name = "action" value = "true">
<input type="
text" name="username"><br>
<input type="
password" name="password"><br>
<input type="
submit" value="submit">
</center>
</FORM>
</BODY>
</HTML>



 

 (#176 2003-09-09 16:30:13) Post Reply
Page 0 1

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

to donnie...

i think i found your problem, you gotta put a print(" before the first form because, dont forget you're working with php, it needs to know WHAT is goinna be printed, the way it was it would not be printed because php only prints what is commanded to print

although i havent been able to test it with the change because you noticed there's a part that says "Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /web/sites/tdavid/non_public_system/parsemsg.php on line 94", you probably have forgotten the print command again :)

anyway, add all the prints necessary (dont forget to close them with the "); beleive me i passed half an hour trying to figure that out :P) and try it again, if it doesnt work post the code again and if the error still prevents part of your code to be shown leave your email or what type of messenger you use so you can send me a copy of your file to see whats wrong to make that error

hope that helps :)

 

 (#177 2003-09-09 16:33:40) Post Reply
Page 0 1

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

oh yeah i forgot my own code :P



<html>
<body>
<?
$banners
= array("<img src=\"banner1.jpg\">","<img src=\"banner2.jpg\">","<img src=\"banner3.jpg\">","<img src=\"banner4.jpg\">");
$namehidden = "Quick";
$passhidden = "saver";

if (
$banner == "true") { print("$banners[$chosen]"); }
if (
$action == "true") {
if (
$name == $namehidden && $pass == $passhidden) {
print(
"<form method=\"post\" action=\"$PHP_self\">
<input type=
\"hidden\" name=\"action\" value=\"true\">
<input type=
\"hidden\" name=\"banner\" value=\"true\">
<input type=
\"hidden\" name=\"name\" value=\"Quick\">
<input type=
\"hidden\" name=\"pass\" value=\"saver\">
<select name=
\"chosen\">");
for(
$a=0; $a<4; $a++) {
$bannername = $a+1;
print(
"<option value=\"$a\">Banner $bannername</option><P>"); }
print(
"</select>
<input type=\"submit\" value=\"change banner\">
</form>"
);
exit(); } else {
print(
"Login <b>name</b> and/or <b>pass</b> is/are incorrect, please try again.<P>"); } } ?>

<form method="post" action="<? $PHP_self ?>">
<input type="hidden" name="action" value="true">
Name: <input type="text" name="name" size=15><P>
Password: <input type="password" name="pass" size=15"><P>
<input type="submit" value="login">
</form>
</body>
</html>



working url

 

 (#201 2003-09-13 16:53:09) Post Reply
Page 0 1

operations
Need To Set


Enrolled: Sep 2003
Posts: 8
AP: 1

http://members.lycos.co.uk/operations/

Username : operations - Password : 54321



<html>
<body>
<center>

<?php

/**
* Week #5 Advanced TO-DO ASSIGNMENT: 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, then 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.
*/

$username = "operations";
$userpassword = "54321";
$banners = array("<IMG SRC=\"banners/devshed.gif\">",
"<IMG SRC=\"banners/sitepoint.gif\">",
"<IMG SRC=\"banners/php.gif\">",
);
$banner_name = array("Devshed", "Sitepoint", "PHP",);

if (
$action_b == "true") {
print(
"$banners[$banner_choice]");
exit();
}
if (
$action == "true") {
if (
$name == "$username" &$password == "$userpassword") {
print(
"<title>Welcome $username</title><FONT COLOR=\"#0000FF\"><b>Pick a Banner:</b>
<form method=
\"post\" action=\"$PHP_self\" >
<input type=
\"hidden\" name=\"action_b\" value=\"true\">
<select name=
\"banner_choice\">");

for(
$i = 0; $i < 3; $i++) {
print(
"<option value=\"$i\">$banner_name[$i]</option>");
}

print(
"</select>
<input type=\"submit\" value=\"submit\">
</form>"
);
exit();
} else {
print(
"<title>Login Error</title><FONT COLOR=\"#FF0000\"><b>Wrong Username / Password</b></center></FONT</BODY></html>");
}
}

?>
<title>Script School Assignment 5 Advanced</title>
<center>
<form method="POST" action="<?php $PHP_self ?>">
<input type="hidden" name="action" value="true">
<input type="text" name="name" value="Username" size="10"> Username<br>
<input type="password" name="password" value="Password" size="10"> Password<br>
<input type="submit" value="Submit"> <input type="reset" value="Reset"></center>
</form></body></html>


 

 (#202 2003-09-14 03:45:12) Post Reply
Page 0 1

logspirit
Need To Set


Enrolled: Oct 2001
Posts: 63
AP: 1

operations,
There should be two && for AND, not just one & for a comparison operator in the line:
if ($name == "$username" &$password == "$userpassword") {
it should be:
if ($name == "$username" && $password == "$userpassword") {

The syntax &$var is for creating reference variables! If You are interested in finding out about using references in PHP, (they are NOT the same as pointers in the c and c++ languages!) see: http://www.php.net/manual/en/l...erences.whatare

Also, Please note: After PHP version 4.2.0 unless You have register globals (variables) turned on in Your initialization settings (php.ini), Your script above will NOT work... After version 4.2.0 register_globals is OFF by default! After version 4.1.0 You should bring in Your external variables from POST operations as:
$_POST[variableName]
Since PHP version 3.0
$HTTP_POST_VARS['variableName']
has been available, but $_POST[] is 'Super Global' in scope, available within functions, while $http_post_vars[] is not and must be brought into functions through the global directive.

You may want to take a look at: http://www.php.net/variables.external
and: http://www.php.net/manual/en/l...ables.scope.php

logspirit

 

 (#225 2003-09-17 03:37:30) Post Reply
Page 0 1

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

http://members.lycos.co.uk/jef...an/class05a.htm

Here is my Assignment.

Class05a.htm



<FORM NAME="LOGIN_FORM" METHOD="post" ACTION="class05a.php">

<input type="hidden" name="action" value="true">
Login the PHP Week 5 ADVANCED Assignment<p>

Login Name:<br>
<input type="text" name="user" value="guest" size="20"><br>
Password:<br>
<input type="password" name="pass" value="guest" size="20"><br>


<input type="submit" value="Submit">

</FORM>




Class05a.php


<?

$action
=$_REQUEST['action'];
$user=$_REQUEST['user'];
$pass=$_REQUEST['pass'];
$banner=$_REQUEST['select_banner'];

if(
$action=='banner')
{
?>
<img alt=<? print($banner);?> src=<? print($banner);?> />
<?
exit;
}
if(
$action=="true")
{
if(
$user=="jeffkwan" && $pass=="jeffkwan")
{
print(
"Login Successful!!!!");
$bannerarray=array('image1.jpg','image2.jpg','image3.jpg','image4.jpg');
$bannername=array('image 1','image 2','image 3','image 4');
$bannerlink=array('www.1.com','www.2.com','www.3.com','www.4.com');
?>

<FORM NAME="BANNERFORM" METHOD="post" ACTION="class05a.php">
<input type="hidden" name="action" value="banner">
<select name="select_banner">
<?
$va_x
=0; // assign a variable
while($va_x <= (count($bannerarray)-1))
{
print(
"<option value='$bannerarray[$va_x]'>".$bannername[$va_x]."</option>");
$va_x++;
}
?>
</select>
<input type="submit" value="Submit">
</FORM>
<br>
</a>
<?
exit;
}
else{
print(
"<font color='#ff0000' <b>Username or Password Error!!!!</b></font><p>");
print(
"Please go back to <a href='class05a.htm'>PHP Week 5 ADVANCED Assignment</a> to login again");
exit;
}
exit;
}
?>




 

 (#230 2003-09-17 11:23:27) Post Reply
Page 0 1

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

Still working on Week 5 advanced. I am still getting a parse error on line 17. I added the recommended changes. Any other suggestions?



<HTML>
<HEAD>
<TITLE>PHP Advanced Assignment 5</TITLE>
</HEAD>
<BODY>
<?php
if ($action == "true"){
if (
$username=="phpstudent" && $password=="phptest"){
print(
"Username and Password Accepted");
//Script to store banners in a multidimensional array
//Three banners in three categories
$bannercategory1 = array('BANNERCAT1BAN1.jpg','BANNERCAT1BAN2.jpg','BANNERCAT1BAN3.jpg');
$bannercategory2 = array('BANNERCAT2BAN1.jpg','BANNERCAT2BAN2.jpg','BANNERCAT2BAN3.jpg');
$bannercategory1 = array('BANNERCAT3BAN1.jpg','BANNERCAT3BAN2.jpg','BANNERCAT3BAN3.jpg');
$banners = array($bannercategory1, $bannercategory2, $bannercategory3);
//Script to display banners from the above array
print("<form method="post" action="phpadvassignment5.php">")
<
input type="hidden" name ="action1" value="true">
print(
"<select name="bannerselect">")
//Loop to populate the select box.
if ($action1 == "true"){
for (
$i = 0; $i = (count($banners)-1); $i++) {
for (
$j = 0; $j = (count($banners[$i]-1); $j++){
print(
"<option value=\"$banners[$i][$j]\">$banners[$i][$j]</option>}}")
print(
"</select>")
print(
"</form>")
exit}
exit;
}
else{
print(
"Username and Password are incorrect. Please enter correct values.");
}}
?>
<center>Please enter the username and password to continue:<br>
<b>Hint:</b><br> Username: phpstudent<br> Password:phptest
print("<form method = "post" action = "phpbasicassignment5.php">
<input type="hidden" name = "action" value = "true">
<input type="text" name="username"><br>
<input type="password" name="password"><br>
<input type="submit" value="submit">
</center>
</FORM>")
</BODY>
</HTML>


 

 (#231 2003-09-17 13:01:04) Post Reply
Page 0 1

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Donnie these lines are buggy:

quote:

print("<form method="post" action="phpadvassignment5.php">")
<input type="hidden" name ="action1" value="true">
print("<select name="bannerselect">")



Try:



print('<form method="post" action="phpadvassignment5.php">"
<input type="hidden" name ="action1" value="true">
<select name="bannerselect">');


 

 (#233 2003-09-17 14:34:06) Post Reply
Page 0 1

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

Thanks TDavid. I thought I had it . . . But another parse error in the last line. I suspect I have left out something very simple, but I just can't see it. Thanks!



<HTML>
<HEAD>
<TITLE>PHP Advanced Assignment 5</TITLE>
</HEAD>
<BODY>
<?php
if ($action == "true"){
if (
$username=="phpstudent" && $password=="phptest"){
print(
"Username and Password Accepted");
//Script to store banners in a multidimensional array
//Three banners in three categories
$bannercategory1 = array('BANNERCAT1BAN1.jpg','BANNERCAT1BAN2.jpg','BANNERCAT1BAN3.jpg');
$bannercategory2 = array('BANNERCAT2BAN1.jpg','BANNERCAT2BAN2.jpg','BANNERCAT2BAN3.jpg');
$bannercategory1 = array('BANNERCAT3BAN1.jpg','BANNERCAT3BAN2.jpg','BANNERCAT3BAN3.jpg');
$banners = array($bannercategory1, $bannercategory2, $bannercategory3);
//Script to display banners from the above array
print('<form method="post" action="phpadvassignment5.php">
<input type="hidden" name ="action1" value="true">
<select name="bannerselect">'
);
//Loop to populate the select box.
if ($action1 == "true"){
for (
$i = 0; $i = (count($banners)-1); $i++) {
for (
$j = 0; $j = (count($banners[$i])-1); $j++){
print(
'<option value=\"$banners[$i][$j]\">$banners[$i][$j]</option>}}
</select>
</form>'
);
exit;}
exit;
}}
else{
print(
"Username and Password are incorrect. Please enter correct values.");
}
?>
<center>Please enter the username and password to continue:<br>
<b>Hint:</b><br> Username: phpstudent<br> Password: phptest
<form method = "post" action = "phpbasicassignment5.php">
<input type="hidden" name = "action" value = "true">
<input type="text" name="username"><br>
<input type="password" name="password"><br>
<input type="submit" value="submit">
</form>
</center>
</body>
</html>


 

 (#237 2003-09-18 03:24:46) Post Reply
Page 0 1

logspirit
Need To Set


Enrolled: Oct 2001
Posts: 63
AP: 1

Donnie,

It seemed like You were getting very frustrated,
so I have provided the following working script for You and others.
If You examine it closely, You will pick up the differences to Your onwn examples, and perhaps grab a few pointers.
I have used some more advanced concepts that You can look up in the PHP manual.
See: http://www.php.net/manual/en/index.php
When using the header() function it is critical that there is NO output to the browser first,
this even includes blank spaces!!! So Make SURE the first character of the first line begins
with the < of the first <?php See: http://www.php.net/header
Due to the header() output, to be fully correct, I have Output the <HTML><BODY>...
tags 'twice'... once for each script condition,
although some browsers may forgive You if You leave some of these out...
I am also using the $_POST, $_SERVER, and $_GET arrays. Again, the PHP manual has info.
See: http://www.php.net/variables.predefined



<?php
if(isset($_POST['action']) || isset($_POST['banner'])){
if(
$_POST['username']=="phpstudent" && $_POST['password']=="phptest"){
echo
'<HTML>
<HEAD>
<TITLE>PHP Advanced Assignment 5</TITLE>
</HEAD>
<BODY><center>'
;
print(
"Username and Password Accepted");
// Store banners in a multidimensional array
// Three banners in three categories
$bannername = array('jpgname1','jpgname2','jpgname3');
$bannerlink = array('http://www.jpglink1.htm','http://www.jpglink2.htm','http://www.jpglink3.htm');
$bannergraphic = array('Graphic1.jpg','Graphic2.jpg','Graphic3.gif');
$banners = array($bannername, $bannerlink, $bannergraphic);
// Select to choose banners from the above array
echo '<form method="post" name="banner" action="'.$_SERVER['PHP_SELF'].'">
<input type="hidden" name = "username" value="'
.$_POST['username'].'">
<input type="hidden" name= "password" value="'
.$_POST['password'].'">
<select name="bannerchoice">'
;
// Loop to populate the select box
// Watch Your Comparison operator in the for, it must not be just =
for ($i = 0; $i <= count($banners[0])-1; $i++) {
echo
'<option value='.$i.'>'.$banners[0][$i].'</option>';
}
print(
'</select>
<input type="submit" name="banner" value="Submit">
</form>'
);
if(isset(
$_POST['banner'])){
echo
'<a href="'.$banners[1][$_POST['bannerchoice']].'"><img src="'.$banners[2][$_POST['bannerchoice']].'" alt="'.$banners[0][$_POST['bannerchoice']].'"></a>';
}
echo
'</center></BODY></HTML>';
exit;
}else{
// Use header() to redirect back with a GET variable err=1
header("Location: ".$_SERVER['PHP_SELF']."?err=1");
exit;
}
}
?>
<center>
<?php
if($_GET['err'] == 1){
print(
"<font color=\"#FF0000\">Username and Password were incorrect. Please enter correct values.</font><br>");
}
?>
<HTML>
<HEAD>
<TITLE>PHP Advanced Assignment 5</TITLE>
</HEAD>
<BODY><center>
Please enter the username and password to continue:<br>
<b>Hint:</b><br> Username: phpstudent<br> Password: phptest
<form method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="username"><br>
<input type="password" name="password"><br>
<input type="submit" name="action" value="Submit">
</form>
</center>
</BODY>
</HTML>



logspirit

 

 (#238 2003-09-18 03:32:21) Post Reply
Page 0 1

logspirit
Need To Set


Enrolled: Oct 2001
Posts: 63
AP: 1

On my last post, I threw in a spurious


<center>



<?php
if($_GET['err'] == 1){




Oh well, just proves that no one is perfect!

logspirit

 

 (#270 2003-09-23 14:29:28) Post Reply
Page 0 1

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

logspirit:

Thanks for the help, but I am still beating my head against the wall. I have been comparing my script to yours and I am still just not getting it.

Your script works, but I have modified it a little. In its original form it did not completely populate the drop down. I fixed that, but now when you select one of the nine choices, it will only display either jpgname1.jpg, jpgname2.jpg, or jpgname3.jpg (If you click on jpgname1.jpg, http://www.jpglink1.htm, or Graphic1.jpg jpgname1 will be displayed and so on.)

Could you please explain a little bit about what is going on here? Also could you explain the function of the following line of code?



echo'<a href="'.$banners[1][$_POST['bannerchoice']].'"><img src="'.$banners[2][$_POST['bannerchoice']].'" alt="'.$banners[0][$_POST['bannerchoice']].'"></a>';



<?php
if(isset($_POST['action']) || isset($_POST['banner'])){
if(
$_POST['username']=="phpstudent" && $_POST['password']=="phptest"){
echo
'<HTML>
<HEAD>
<TITLE>PHP Advanced Assignment 5</TITLE>
</HEAD>
<BODY><center>'
;
print(
"Username and Password Accepted");
// Store banners in a multidimensional array
// Three banners in three categories
$bannername = array('jpgname1','jpgname2','jpgname3');
$bannerlink = array('http://www.jpglink1.htm','http://www.jpglink2.htm','http://www.jpglink3.htm');
$bannergraphic = array('Graphic1.jpg','Graphic2.jpg','Graphic3.gif');
$banners = array($bannername, $bannerlink, $bannergraphic);
// Select to choose banners from the above array
echo '<form method="post" name="banner" action="'.$_SERVER['PHP_SELF'].'">
<input type="hidden" name = "username" value="'
.$_POST['username'].'">
<input type="hidden" name= "password" value="'
.$_POST['password'].'">
<select name="bannerchoice">'
;
// Loop to populate the select box
// Watch Your Comparison operator in the for, it must not be just =
for ($i = 0; $i <= count($banners)-1; $i++) {
for (
$j = 0; $j <= count($banners[$j])-1; $j++) {
echo
'<option value='.$j.'>'.$banners[$i][$j].'</option>';
}}
print(
'</select>
<input type="submit" name="banner" value="Submit">
</form>'
);
if(isset(
$_POST['banner'])){
echo
'<a href="'.$banners[1][$_POST['bannerchoice']].'"><img src="'.$banners[2][$_POST['bannerchoice']].'" alt="'.$banners[0][$_POST['bannerchoice']].'"></a>';
}
echo
'</center></BODY></HTML>';
exit;
}else{
// Use header() to redirect back with a GET variable err=1
header("Location: ".$_SERVER['PHP_SELF']."?err=1");
exit;
}
}
?>
<center>
<?php
if($_GET['err'] == 1){
print(
"<font color=\"#FF0000\">Username and Password were incorrect. Please enter correct values.</font><br>");
}
?>
<HTML>
<HEAD>
<TITLE>PHP Advanced Assignment 5</TITLE>
</HEAD>
<BODY><center>
Please enter the username and password to continue:<br>
<b>Hint:</b><br> Username: phpstudent<br> Password: phptest
<form method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="username"><br>
<input type="password" name="password"><br>
<input type="submit" name="action" value="Submit">
</form>
</center>
</BODY>
</HTML>


 

 (#271 2003-09-23 14:34:14) Post Reply
Page 0 1

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

logspirit:

Part of my message was left off the last post.

Thanks for all you help. I am determined to get this right. The code I posted is yours as I modified it. Thanks again.

 

 (#288 2003-09-26 22:55:07) Post Reply
Page 0 1

maddy
Need To Set


Enrolled: Sep 2003
Posts: 14
AP: 1

Jeez, I thought I'd never get it to work! I was making errors with the hidden statements, and keep getting in even with the wrong password.

Working one is here: http://sassy.togetherhost.com/...ts/week5adv.php

<html>
<body>
<?
$imgpath
= "http://sassy.togetherhost.com/scripts/images/";
$banners = array("i_think.gif","bumble_bee.gif","bright_green.gif","fast_red.gif");
$bannername = array("i think","bumble bee","bright green","fast red");
$username = "maddy";
$password = "rocks";



if (
$banner == "true") { print("<img src=\"$imgpath$banners[$selected]\" alt=\"$bannername[$selected]\" />"); }

if (
$action == "true") {
if (
$username == $loginname && $password == $loginpassword) {
print(
"<form method=\"post\" action=\"week5adv.php\">
<input type=\"hidden\" name=\"action\" value=\"true\">
<input type=\"hidden\" name=\"banner\" value=\"true\">
<input type=\"hidden\" name=\"loginname\" value=\"maddy\">
<input type=\"hidden\" name=\"loginpassword\" value=\"rocks\">

<select name=\"selected\">"
);

for(
$i=0; $i<4; $i++) {
print(
"<option value=\"$i\">$bannername[$i]</option>"); }

print(
"</select>
<input type=\"submit\" value=\"select\">
</form>"
);
exit(); }
else {
print(
"Sorry, you seem to be confused, please try again."); } } ?>



<h3>Please enter your details:</h3>
<form method="post" action="week5adv.php">
<input type="hidden" name="action" value="true">
Username: <input type="text" name="loginname" /><br />
Password: <input type="password" name="loginpassword" />
<input type="submit" value="enter">
</form>
</body>
</html>


Thanks to Quicksaver - your code helped me figure out the hidden statements. And thanks to logspirit for explaining a bit about the effect register globals being off. :)

 

 (#312 2003-10-11 14:48:35) Post Reply
Page 0 1

jlk242
Need To Set


Enrolled: Oct 2003
Posts: 8
AP: 1

OMG this one really kicked my butt for awhile, and I thought I knew something about forms...
Thanks to Quick and Maddy, you code helped get a better understanding of how it should work.

[link]http://jlk.qfgroup.org/login.php[/link] http://jlk.qfgroup.org/login.php

User Name : lycaon
Password : werewolf



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>_-=+:: The House of Lycaon ::+=-_</title>
</head>
<body bgcolor="141D51" text="#FFFFFF" link="#FFFFFF">
<?php
$set
= 0;
$banners = array('lycanthrope','werewolf','metamorph');
$name = "lycaon";
$pass = "werewolf";
if (
$action == "true") {
if (
$username == $name && $password == $pass)
{
$set = 1;
}
}
?>
<div align="center">
<form name="form1" method="post" action="<? PHP_self ?>">
<input type="hidden" name="action" value="true">
<table width="75%" height="329" border="0">
<tr>
<td>
<div align="center"><img src="images/form_head.gif" width="400" height="160">
</div>
</td>
</tr>
<tr>
<?php
if ($set == 0){
echo (
"
<td>
<div align=\"center\"><img src=\"images/form_name.gif\" width=\"400\" height=\"34\">
</div>
</td>
"
);
}

?>
<div align="center"><img src="images/<?
if ($setbanner == "true") {
echo (
"$banners[$choice]");
}
else {
echo (
"transparent");
}
?>.gif" width="400" height="34">



</tr>
<tr>
<?php
if ($set == 0){

echo (
"
<td>
<div align=\"center\">
<input name=\"username\" type=\"text\" id=\"username\">
</div>
</td>
"
);
}
?>
</tr>
<tr>
<?php
if ($set == 0){

echo (
"
<td>
<div align=\"center\"><img src=\"images/form_pass.gif\" width=\"400\" height=\"34\">
</div>
</td>
</tr>
"
);
}
?>
<?php
if ($action == "true") {
if (
$username == $name && $password == $pass) {

echo(
"
<td>
<div align=\"center\">

<input type=\"hidden\" name=\"action\" value=\"true\">
<input type=\"hidden\" name=\"setbanner\" value=\"true\">
<input type=\"hidden\" name=\"username\" value=\"lycaon\">
<input type=\"hidden\" name=\"password\" value=\"werewolf\">

<select name=\"choice\">"
);
$i = 0;
while(
$i < 3) {
echo(
"<option value=\"$i\">$banners[$i]</option>");
$i++;
}
echo (
"</select>
<input type=\"submit\" value=\"select\">
</div>
</td>
</tr>
"
);
exit(); }
else {
$error = 1;
}
}
?>
<tr>
<?php
if ($set == 0){

echo (
"
<td>
<div align=\"center\">
<input name=\"password\" type=\"password\" id=\"password\">
</div>
</td>
"
);
}
?>
</tr>
<tr>
<td>
<div align="center">
<input type="submit" name="Submit" value="Login">
</div>
</td>
</tr>
<tr>
<?php
if ($error == 1){
echo (
"
<td>
<div align=\"center\"><img src=\"images/form_error.gif\" width=\"400\" height=\"59\">
</div>
</td>
"
);
}
else {
echo (
"");
}
?>
</tr>
</table>
</form>
</div>
</body>
</html>



jlk

 

 (#357 2003-11-03 16:11:21) Post Reply
Page 0 1

pIscIs
Need To Set


Enrolled: Nov 2003
Posts: 5
AP: 1

whats wrong with my code? when i pressing submit(in picture choice) it returns me to login page

<HTML>
<HEAD>
<TITLE>PHP Advance Assignment 5</TITLE>
</HEAD>
<BODY>
<?php

$banners = array("<img src=\"banner1.jpg\">","<img src=\"banner2.jpg\">","<img src=\"banner3.jpg\">","<img src=\"banner4.jpg\">");
$banner_name = array("banner1", "banner2", "banner3", "banner4");

if (isset($_POST['banner_choice']) && !empty($_POST['banner_choice']))
{
print("$banners[$banner_choice]");
exit;
}
if (isset($_POST['action']) && $_POST['action'] == 'true')
{
if ($_POST["username"] == 'phpstudent' && $_POST["password"] == 'phptest')
{
print('You logged on');

?>
<form action=" <?php print $_SERVER['PHP_SELF'];?> " method="POST">
<SELECT NAME="banner_choice" >
<?
for($i = 0; $i < 4; $i++)
{
print("<option value=\"$i\">$banner_name[$i]</option>");
}
?>
</select>
<INPUT TYPE="submit" VALUE="Submit" > <INPUT TYPE=reset VALUE="Reset">
</form>
<?
exit;
}
else
{
print("Username and Password are incorrect. Please enter correct values.");
}
}
?>
<center>Please enter the username and password to continue:<br>
<b>Hint:</b><br> Username: phpstudent<br> Password:phptest
<form action=" <?php echo $_SERVER['PHP_SELF']; ?> " method="POST">
<input type="hidden" name = "action" value = "true">
<input type="text" name="username"><br>
<input type="password" name="password"><br>
<input type="submit" value="submit">
</center>
</FORM>
</BODY>
</HTML>


 

 (#358 2003-11-03 17:22:58) Post Reply
Page 0 1

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

pIscIs, i dunno really why you added the empty() part to the if() funtion:

if (isset($_POST['banner_choice']) && !empty($_POST['banner_choice']))

I guess you wanted it to check if the var wouldnt be empty, but you dont need that kind of protection because the var is being set with a value ALWAYS i beleive, as long you select a banner and click submit, that var will always have a value, even though the above should work, as its like "if there is a banner_choice var and its not empty do..." lemme do some tests...

ok after some tries im defenetly confused. the empty() function seems to be working backwards, instead of returning true, since the var isnt empty, its returning false...

well, if you remove the "!" so it stays just:

empty($_POST['banner_choice'])

it'll return true (just in this script, i made some other simple ones and it works nicely), so do that and my advice is to wait for someone who might have an idea of whats happening here

but what i'd really do is just take off that part and leave it simply like this:

if (isset($_POST['banner_choice']))

less work and works the same :)

 

 (#363 2003-11-04 07:11:52) Post Reply
Page 0 1

pIscIs
Need To Set


Enrolled: Nov 2003
Posts: 5
AP: 1

thanx, i changet it. now it not returning me to login page, the i press submit it show me blank page :(

 

 (#364 2003-11-04 10:22:54) Post Reply
Page 0 1

pIscIs
Need To Set


Enrolled: Nov 2003
Posts: 5
AP: 1

so i have made corrections and it works. thats my mistakes:
1.
if (isset($_POST['banner_choice']) && !empty($_POST['banner_choice']))
must be:
if (isset($_POST['banner']) ) //with submit name="banner" in banner choice form and without "hidden" row
or
if (isset($_POST['action_b']) && $_POST['action_b'] == 'true')
2.
print("$banners[$banner_choice]");
must be:
print($banners[$_POST["banner_choice"]]);
3.
print("<option value=\"$i\">$banner_name[$i]</option>");
must be:
print("<option value=\"".$i."\">".$banner_name[$i]."</option>");

thats all

 

 (#367 2003-11-05 08:27:59) Post Reply
Page 0 1

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

lol i finished week 9 advanced, and then saw that i forgot to post this one :) and i had to modify it. it was without loops ;) now it is with loops. comments please.:

url: http://tts.lt/~sir/scripts/week5adv.php



<html>
<title> Week 5 advanced to-do assignment </title>
<body>
<center>
<?

//Set variables
$loginreal="dest";
$passreal="script";

//banner names:

$bannerblue=array('blue1.gif', 'blue2.gif', 'blue3.gif');
$bannergreen=array('green1.gif', 'green2.gif', 'green3.gif');
$bannerred=array('red1.gif', 'red2.gif', 'red3.gif');
$bannersmain=array($bannerblue, $bannergreen, $bannerred);



if(
$form=="done")
{

//If our form done do this:

if($login==$loginreal&&$pass==$passreal) {
print(
"Choose the banner:<br><br>");
//if login and pass are correct print Choose the banner and another form
?>

<!--form for banners(if psw and login correct-->
<form name=bannerform method=post action=week5adv.php>
<input type=hidden name=formbanner value=made>
<input type=hidden name=form value=done>
<input type=hidden name=login value=dest>
<input type=hidden name=pass value=script>

<select name=bannercount>
<?
$bannernumber
=array('First', 'Second', 'Third');
for(
$b=0; $b<3; $b++)
{
print(
"<option value=$b>$bannernumber[$b]</option>"); } ?>
</select>

<select name=bannerselect>
<?
$bannercolors
=array('Blue banner', 'Green banner', 'Red banner');
for(
$i=0; $i<3; $i++)
{
print(
"<option value=$i>$bannercolors[$i]</option>"); } ?>

</select>
<input type=submit value=submit>
</form>

<?

//if banner form isn't complete exit.

if($formbanner!=made){ exit; }

//and if banner form is complete, print that banner and then exit.

elseif($formbanner="made")
{
$bannerpic=$bannersmain[$bannerselect][$bannercount];
print(
"<br>Here is banner you selected:<br>");
print(
"<img src=\"files/week4/$bannerpic\">");
; exit; }

}

//and if our form is complete but pass or login are not correct, print error.
else
{
print(
"<font color=red>Your password or login is incorrect.</font>");}
}


?>


<!-- main form. used to identify you-->
<form method=POST action=week5adv.php>
<input type=hidden name=form value=done>
Login:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=text name=login size=15>
<br>Password:<input type=password name=pass size=15>
<br><br><input type=submit value=Submit>&nbsp;&nbsp;<input type=reset value=Clear>

</form>
</center>
</body>
</html>



 

 (#368 2003-11-05 08:28:40) Post Reply
Page 0 1

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

forgot to say:

login: dest
pass: script

 

 (#491 2004-02-03 13:06:04) Post Reply
Page 0 1

Cyb
Need To Set


Enrolled: Feb 2004
Posts: 6
AP: 1

For my first post here I want to start saying that your course really kick-ass. Prolly the best one around :D.
I'm late with posting this of course, but I still wanted to because I found out I use another way than the others here.

This assignment was quite hard but very interesting too, especially if you want to do it exactly like the assignment was. With saying self-containing script, I understood a script WITHOUT action in a form. Also because I didnt know of PHP_self I, after some thinking, found a way to do that.
It's quite a long script, but that's also because I used much comments.
I am a newbie btw (this course untill part 5 is the only I know of PHP) so excuse me if there are better ways to do it. http://members.lycos.nl/twanka...bannerlogin.php
is the link, without virtual banners though.





<html>
<head><title>login for banners</title></head>
<body>

<?php

//the true login name and pass
$real_username = David;
$real_password = td;

//defining the banner array
$banner_array = array('1.jpg','2.jpg','3.jpg');

//checking if the form is filled
if ($form==done) {
//the form is filled, proceed verifying password and username
if (($password==$real_password) AND ($username==$real_username)) {



//the login is correct, check if a banner has been chosen
if ($selectform != filled){
//no banner has been chosen, tell to select one
echo Plz select a banner;
}
else {
//the banner has been chosen, show it
echo <img src=$banner>;
}
//escaping to the banner choose form
?>

<form>
<select name=banner>
<?php
//creating the loop file for the select part as stated in the assignment
for ($i=0 ; $i<3 ; $i++) {
echo <
option value=$banner_array[$i]>;
$a=$i+1;
echo
Banner $a </option>;
}
//escaping again for the rest of the form, the hidden values are
//to prevent the form from returning to the login, the form fills in the correct pass and username again itself
?>
</select><br>
<input type=hidden name=selectform value=filled>
<input type=hidden name=username value=<?php echo $real_username; ?>>
<input type=hidden name=password value=<?php echo $real_password; ?>>
<input type=hidden name=form value=done>
<input type=submit value=submit>
</form>

<?php
}
else {
//the login was incorrect, put a message above the login form stating so
$text = Something went wrong, plz enter your username and password again.;
}
}
else {
//text should contain something
$text = Please enter your username and password:<p>;
}

//checking if text contains something, this makes it possible to show the loginform both when
//the login isnt filled yet AND when the login is incorrect
if ($text) {
echo
$text;
//escaping for the loginform
?>

<form>
Username: <input type=text name=username><br>
Password: <input type=password name=password><br>
<input type=hidden name=form value=done>
<input type=submit value=submit>
</form>

<?php
}
?>


</body>
</html>



 

 (#492 2004-02-03 13:17:28) Post Reply
Page 0 1

Cyb
Need To Set


Enrolled: Feb 2004
Posts: 6
AP: 1

:( by posting all the " " were removed somehow... not a too big prob of course.. but is that a forum bug or was is just my fault?

 

 (#668 2004-07-18 15:54:41) Post Reply
Page 0 1

def
Need To Set


Enrolled: Jul 2004
Posts: 10
AP: 1

$set_username = "guest";
$set_password = "guest";
$banner_array = array('banner1','banner2','banner3');

if ($action_submit_banner_choice == "true") {
print ("you have selected: $banner_array[$banner_index]");
exit();
}

if ($action_submit_login == "true")
{
if ($username != "$set_username" || $password != "$set_password")
print ("incorrect username or password<br>");
else
{
print ("select a banner:
<form method=\"post\" action=\"$php_form\">
<input type=\"hidden\" name=\"action_submit_banner_choice\" value=\"true\">
<select name=\"banner_index\">");
for ($i = 0; $i < 3; $i++)
{
print("<option value=\"$i\">$banner_array[$i]</option>");
}
print ("</select><input type=\"submit\" value=\"submit\"></form>");
exit();
}
}
?>

<form method="post" action="<? $php_form ?>">
<input type="hidden" name="action_submit_login" value="true">
Username:
<input name="username" type="text" id="username">
<br>
Password:
<input name="password" type="password">
<br><input type="submit" value="Login">
</form>

 

 (#669 2004-07-18 17:33:02) Post Reply
Page 0 1

def
Need To Set


Enrolled: Jul 2004
Posts: 10
AP: 1



$set_username = "guest";
$set_password = "guest";
$banner_array = array('banner1','banner2','banner3');

if ($action_submit_banner_choice == "true") {
print ("you have selected: $banner_array[$banner_index]");
exit();
}

if ($action_submit_login == "true")
{
if ($username != "$set_username" || $password != "$set_password")
print ("incorrect username or password<br>");
else
{
print ("select a banner:
<form method=\"post\" action=\"$PHP_SELF\">
<input type=\"hidden\" name=\"action_submit_banner_choice\" value=\"true\">
<select name=\"banner_index\">");
for ($i = 0; $i < 3; $i++)
{
print("<option value=\"$i\">$banner_array[$i]</option>");
}
print ("</select><input type=\"submit\" value=\"submit\"></form>");
exit();
}
}
?>


 

 (#670 2004-07-18 17:34:10) Post Reply
Page 0 1

def
Need To Set


Enrolled: Jul 2004
Posts: 10
AP: 1



$set_username = "guest";
$set_password = "guest";
$banner_array = array('banner1','banner2','banner3');

if ($action_submit_banner_choice == "true") {
print ("you have selected: $banner_array[$banner_index]");
exit();
}

if ($action_submit_login == "true")
{
if ($username != "$set_username" || $password != "$set_password")
print ("incorrect username or password<br>");
else
{
print ("select a banner:
<form method=\"post\" action=\"$PHP_SELF\">
<input type=\"hidden\" name=\"action_submit_banner_choice\" value=\"true\">
<select name=\"banner_index\">");
for ($i = 0; $i < 3; $i++)
{
print("<option value=\"$i\">$banner_array[$i]</option>");
}
print ("</select><input type=\"submit\" value=\"submit\"></form>");
exit();
}
}
?>


 

 (#671 2004-07-18 17:35:03) Post Reply
Page 0 1

def
Need To Set


Enrolled: Jul 2004
Posts: 10
AP: 1

ignore the above posts, browser acting weird :(



<?
$set_username
= "guest";
$set_password = "guest";
$banner_array = array('banner1','banner2','banner3');

if (
$action_submit_banner_choice == "true") {
print (
"you have selected: $banner_array[$banner_index]");
exit();
}

if (
$action_submit_login == "true")
{
if (
$username != "$set_username" || $password != "$set_password")
print (
"incorrect username or password<br>");
else
{
print (
"select a banner:
<form method=
\"post\" action=\"$PHP_SELF\">
<input type=
\"hidden\" name=\"action_submit_banner_choice\" value=\"true\">
<select name=
\"banner_index\">");
for (
$i = 0; $i < 3; $i++)
{
print(
"<option value=\"$i\">$banner_array[$i]</option>");
}
print (
"</select><input type=\"submit\" value=\"submit\"></form>");
exit();
}
}
?>


 

  Page 0 1

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission