| | #1 |
| Warrior Member Join Date: 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
In my quest to learn Php I have another task but I've hit a block. What I am trying to do is have a resume put online BUT when someone clicks on this html button to go to my resume page they are given a password prompt. What I want is that if they enter the correct password the resume page displays and if not then an error message appears. I am trying to do this with Php. The thing I can't get around or at the moment can't think of is how can I prevent the user from just typing in the url of the resume page and thus going around my password check? I thought about having the resume as an "include" to another file but if the user does a "view source" they can still see the resume file name. Any suggestions? Maybe I'm approaching this wrong or missing the obvious? |
| | |
| |
| | #2 | |
| HyperActive Warrior Join Date: 2010
Posts: 192
Thanks: 34
Thanked 27 Times in 23 Posts
|
| |
| |
| | #3 |
| Warrior Member Join Date: 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
For something like this, you'd probably want to keep it as simple as possible. You can do it with the code I've just thrown together and attached. Provided the resume has a hard to guess file name then include(""); is perfectly fine. The file name will not be shown in the HTML source. |
| |
| | #4 | |
| Automation Specialist War Room Member Join Date: 2009 Location: Cary, NC
Posts: 153
Thanks: 31
Thanked 13 Times in 13 Posts
Blog Entries: 2 |
Great code snippet! I'd probably change the password check part to make it easier to read, but from the way the code looks, I imagine that the code should work fine.
| |
| | ||
| |
| | #5 | |
| HyperActive Warrior Join Date: 2010
Posts: 192
Thanks: 34
Thanked 27 Times in 23 Posts
|
| |
| |
| | #6 | |
| Warrior Member Join Date: 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
1) Create new folder called resume 2) Upload index.php (the code sample I attached previously) 3) Upload df3_354-5435_t453.html (your resume) 4) Link people to /resume/ The only way people will be able to link directly to your resume file is by knowing the file name. They're not going to guess that file name. They could email someone the link to the php file AND the password. But if you're worried about that then you should also worry about people just downloading the document after viewing it and emailing it on. Have you tested the script? Perhaps you're getting confused about how it actually works. | |
| |
| | #7 | |
| HyperActive Warrior Join Date: 2010
Posts: 192
Thanks: 34
Thanked 27 Times in 23 Posts
|
Warning: include(supersecretresumefilename.html) [function.include]: failed to open stream: and then they would know right? unless you turned off warnings with ini_set('display_errors', 0); but then you'd have to remember to turn it on and off when you're debugging, which would be kind of annoying actually. Also how would this work if the resume was more than one page? | |
| |
| | #8 | |
| Warrior Member Join Date: 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
That error only shows because 'supersecretresumefilename.html' doesn't actually exist. If you create the file then it wont ever display that error. Alternatively just put an @ symbol before the include(), this will suppress any error. E.g: @include('supersecretresumefilename.html'); If you're really worried that your file might become corrupt or unreadable then use something like this: if(@$resume = file_get_contents("supersecretresumefilename.html" )){ echo $resume; } else { echo 'My resume isn\'t available right now, sorry dude!'; } If it's more than 1 page then you might want to consider the cookie approach. Or just protect the directory with htaccess. | |
| |
| | #9 | |
| HyperActive Warrior Join Date: 2010
Posts: 192
Thanks: 34
Thanked 27 Times in 23 Posts
|
| |
| |
| | #10 |
| homdurgedu Join Date: 2010 Location: USA
Posts: 251
Thanks: 1
Thanked 9 Times in 9 Posts
|
Hi, You just use one database for storing passwords then retrieve the password from database and then check this will do |
| | |
| |
|
| Bookmarks |
| Tags |
| php, question |
| Thread Tools | Search this Thread |
| |