School Map:
Home / Enroll
$ Student Records; Class
$ News @ LIVE
Tech Radio * Support/FAQ
| Store | FORUMS
Class / Forums / php101 ![]() |
Week #5 Basic To-Do Assignment, post here |
(#8 2003-08-07 16:09:15) Post Reply |
|
TDavid
|
Week #5 Basic 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 ****. 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 here the complete source code of the script in you post. scriptname.php <-- script name Good luck to you!
|
(#65 2003-08-19 11:07:38) Post Reply |
|
Sk8rRIMuk
|
Here is the URL of my working script (use username Sk8rRIMuk and password havoctheman):
http://www.katikai.com/ee/assi...nt/username.php Here is my script:
That was amazingly simple yet it took me a while to figure utt hat I had spelt method & pasword wrong and that if you put spaces in the action's filename you get errors :S. I will have a go ta the other one sometime this wekk, looks a little difficult though. |
(#154 2003-09-03 13:59:50) Post Reply |
|
Donnie
|
Somebody please help me out here. When I execute this script it allows me to enter the username and password, but it just returns to the same page asking for the username and password again. Any ideas?
|
(#155 2003-09-03 14:12:33) Post Reply |
|
Sk8rRIMuk
|
This script works fine when it's uploaded to my site, my only quarrels are that you didn't print the </BODY></HTML> before you exited and yopu could use $PHP_SELF to identify the page you wan't to submit the form to.....
Are you sure you are typing them right, remember PHP is caps senstive... |
(#156 2003-09-03 15:09:55) Post Reply |
|
Donnie
|
Could you give me a little more information Sk8? I don't exactly understand what you mean about $PHP_SELF. Should I have put the html tags you mentioned before the exit? |
(#157 2003-09-03 18:07:33) Post Reply |
|
Sk8rRIMuk
|
It works fine as it is but I was offering pointers, try:
<HTML> <HEAD> <TITLE>PHP Basic Assignment 5</TITLE> </HEAD> <BODY> <?php if ($action == "true"){ if ($username=='phpstudent' & $password=='phptest'){ print("Username and Password Accepted\n</BODY>\n</HTML>"); 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 = "<?php $PHP_SELF ?>"> <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> The PHP_SELF makes sure it submits it to itself and the </BODY></HTML> are there so the will be displayed before the exit and the \n make sure theres a newline in the source code... It does work on my server thought I can only think of type errors in the login are the reason for it not working for you... |
(#174 2003-09-09 15:11:28) Post Reply |
|
Quicksaver
|
no comments...
working url |
(#200 2003-09-13 16:51:39) Post Reply |
|
operations
|
http://members.lycos.co.uk/operations/
Username : operations Password : 54321 |
(#209 2003-09-15 10:53:12) Post Reply |
|
Shrek
|
I have some problems. I can't forward the username and password to the php file. I don't know what's wrong.
class05.php
Could anyone help me to find it out? |
(#210 2003-09-15 10:54:18) Post Reply |
|
Shrek
|
When I run my php, it just shows
"You can't access this page!!!!" Thx a lot |
(#211 2003-09-15 11:06:20) Post Reply |
|
Quicksaver
|
you gotta put two && instead of just one i think, and you dont need two exits after the name and pass error, just one does the trick
other than that i see nothin wrong, although dont blame me if it still doesnt work, i gotta do some stuff on my pc before i do php again, probably in a couple of days or so |
(#212 2003-09-15 11:10:20) Post Reply |
|
Quicksaver
|
oh, and dont put the "you cant access this page error", remove that else condition because, if you think well that else condition is always stated when the $action string is empty, and its logical that when you first run the script without filling in the form that string is empty so you made that error appear when the user didnt even do anything. |
(#213 2003-09-15 15:52:08) Post Reply |
|
Shrek
|
I have tried your suggestion.
1. Remove the else, and 2. Use && rather than & Unfortunately, the string in all variables seem empty and the result returns to me is a blank page. The question in my heart is what can I bring the variables from form to php? Thx a lot. |
(#214 2003-09-15 16:00:27) Post Reply |
|
Quicksaver
|
huh??? i dont get it, have you tried taking the "you cant access..." error out? could you link me to somewhere where you may have uploaded your script? |
(#215 2003-09-15 16:17:37) Post Reply |
|
Quicksaver
|
oh i think i got it, the name you give to each field of the form (for example "name") will become a string called $name when the form is submitted, with the value inserted at the form. but i dont get what you said bout the always getting the blank page error. you need to submit a link to the url with a "workin" (or not working so we can fix it) with the code you subbmit, that is also valid to the previous tasks youve done.
heh, im being technical here and i only have the eighth course with an error on the advanced task that i cant fix :P oh by the way, i have nothing to do with it, you do as you like, but i noticed that you didnt make any advanced tasks till the moment, my advice: they really help a lot increasing your aknowledge on php as well as being logical with it. again i dont meen to offend or to command or anything, just a lil advice im givin out :) |
(#216 2003-09-16 05:40:25) Post Reply |
|
Shrek
|
Thank you for your help. I have found a web hosting to hosting my class file.
http://members.lycos.co.uk/jef...wan/class05.htm The file works well there. May be my php server got something wrong. BTW, I will try my best to do the advanced assignment. Thank you very much. |
(#217 2003-09-16 05:56:35) Post Reply |
|
Shrek
|
I finally find out the result. I need to amend the class05.php.
I found that the php4 cannot directly get the variables from the html. http://hk.php.net/variables.external |
(#284 2003-09-26 18:35:08) Post Reply |
|
maddy
|
I did two variatons for this assignment - the first just prints out a message if the username/password combo is correct (example here: http://sassy.togetherhost.com/...pts/week5.php). The second redirects to another page if it is correct (example here: http://sassy.togetherhost.com/.../password.php).
I guess the second is jumping ahead to week 8,but I figure I'm most likely to redirect if a password is correct, as compared to printing out a message. I found this helpful: http://nz2.php.net/manual/en/f...tion.header.php :) |
(#285 2003-09-26 18:39:55) Post Reply |
|
maddy
|
Grr. The forum attached my closing brackets to my URLS. I'll post them again in a second. Anyway, I forgot to note, although it's obvious from the code, that the username is 'maddy' and the password 'rocks'. :)
First example: http://sassy.togetherhost.com/...ripts/week5.php Second example (with redirect): http://sassy.togetherhost.com/...ts/password.php It'd be neat if we could edit out posts here. |
(#286 2003-09-26 18:43:02) Post Reply |
|
maddy
|
Hey, what's happened to my code? The php bit of the second bit I posted is way different to what I posted. I'll try again (just the php bit)
else { print("You are not allowed to enter. Try again.");} } ?> |
(#287 2003-09-26 18:45:09) Post Reply |
|
maddy
|
Still not working!!! I'll just link to the file instead: http://sassy.togetherhost.com/...ts/password.txt
I know this is free, but maybe a beter forum software is needed - Invision Power Board is great (and free). :) |
(#353 2003-11-02 12:44:26) Post Reply |
|
Dest
|
I was going to make advanced assignment but i decided to do this first. i used include command, but not for main script. just made variation, and after successful login you are taken in to my pic of the day script :)
Name: dest Password: script Working example: http://tts.lt/~sir/scripts/week5basic.php |
(#375 2003-11-14 11:02:36) Post Reply |
|
zxrod
|
Here's my basic assignment. It seemed fairly easy to me..
|
(#417 2003-12-12 06:28:54) Post Reply |
|
fudded
|
I have a problem here, no matter what I do I get this error
Undefined variable: action in c:\inetpub\wwwroot\learn php\TMPh21ypuns2.php on line 14 I have even borrowed Quicksaver code to check i get the same "variable: action .....". I guess its this line of code
Any help would be helpful Thanx Sean |
(#419 2003-12-18 06:09:19) Post Reply |
|
Quicksaver
|
post the previous lines before that chunk of code, sometimes its something behind and not exactly that one |
(#441 2003-12-30 01:24:02) Post Reply |
|
PureGrain
|
OK, this is getting me frustrated. I cannot seem to get it to work on my server. I am hosting my own of coarse and seem to get most every other weeks assignments to work, with the exception of week 3's advanced assignment, which I posted for help on in the advanced forum. But here is the code i revamped to fit others once I could not get it to work the way I tried it. Which now makes me think it might have worked if my server allowed it too. I am not sure if that is my problem or am I missing something?
|
(#442 2003-12-31 01:17:09) Post Reply |
|
n2o2k
|
Here is the basic assignement and a link to an example:
http://membres.lycos.fr/justry...school/course_5
|
(#447 2003-12-31 18:24:47) Post Reply |
|
PureGrain
|
I fixed it. :D
I had left an = off in the form..
working url: http://members.lycos.co.uk/xko...sson5_basic.php |
(#544 2004-03-09 23:14:54) Post Reply |
|
Havoc
|
This one was pretty easy, But how do you get multiple usernames and passwords with different pages for each one?
|
(#547 2004-03-10 14:48:45) Post Reply |
|
Cyb
|
Well there are more ways to do that... one would be starting with another if (password == other pass and username == otherusername).
You can primarely only send everyone entering the form to the same place (I think), so I would then redirect them with a variable header location to another page which you will learn in course 10 :). |
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