School Map:
Home / Enroll
$ Student Records; Class
$ News @ LIVE
Tech Radio * Support/FAQ
| Store | FORUMS
Class / Forums / php101 ![]() |
Week #5 ADVANCED To-Do Assignment |
(#9 2003-08-07 16:10:55) Post Reply |
|
TDavid
|
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 |
|
Sk8rRIMuk
|
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'
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 |
|
Sk8rRIMuk
|
Sorry forgot to say the Username is Sk8rRIMuk and the Password is havoctheman :) |
(#160 2003-09-05 08:08:11) Post Reply |
|
Donnie
|
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. |
(#176 2003-09-09 16:30:13) Post Reply |
|
Quicksaver
|
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 |
|
Quicksaver
|
oh yeah i forgot my own code :P
working url |
(#201 2003-09-13 16:53:09) Post Reply |
|
operations
|
http://members.lycos.co.uk/operations/
Username : operations - Password : 54321 |
(#202 2003-09-14 03:45:12) Post Reply |
|
logspirit
|
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 |
|
Shrek
|
http://members.lycos.co.uk/jef...an/class05a.htm
Here is my Assignment. Class05a.htm |
(#230 2003-09-17 11:23:27) Post Reply |
|
Donnie
|
Still working on Week 5 advanced. I am still getting a parse error on line 17. I added the recommended changes. Any other suggestions?
|
(#231 2003-09-17 13:01:04) Post Reply |
|
TDavid
|
Donnie these lines are buggy:
quote: Try: |
(#233 2003-09-17 14:34:06) Post Reply |
|
Donnie
|
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!
|
(#237 2003-09-18 03:24:46) Post Reply |
|
logspirit
|
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
logspirit |
(#238 2003-09-18 03:32:21) Post Reply |
|
logspirit
|
On my last post, I threw in a spurious
Oh well, just proves that no one is perfect! logspirit |
(#270 2003-09-23 14:29:28) Post Reply |
|
Donnie
|
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? |
(#271 2003-09-23 14:34:14) Post Reply |
|
Donnie
|
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 |
|
maddy
|
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
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 |
|
jlk242
|
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
jlk |
(#357 2003-11-03 16:11:21) Post Reply |
|
pIscIs
|
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 |
|
Quicksaver
|
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 |
|
pIscIs
|
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 |
|
pIscIs
|
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 |
|
Dest
|
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 |
(#368 2003-11-05 08:28:40) Post Reply |
|
Dest
|
forgot to say:
login: dest pass: script |
(#491 2004-02-03 13:06:04) Post Reply |
|
Cyb
|
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. |
(#492 2004-02-03 13:17:28) Post Reply |
|
Cyb
|
:( 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 |
|
def
|
$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 |
|
def
|
|
(#670 2004-07-18 17:34:10) Post Reply |
|
def
|
|
(#671 2004-07-18 17:35:03) Post Reply |
|
def
|
ignore the above posts, browser acting weird :(
|
Page 0 1 |
View Previous Thread Print This Page |
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