Poll
Has Hilco abandoned this site?
Yes?
50%
No?
17%
I can't tell!
33%
Total votes: 6
- Login to post comments
- Older polls
User login
Recent comments
- php to update prices
1 year 4 weeks ago - I suggest you create a php
1 year 4 weeks ago - If you don't know much about
1 year 10 weeks ago - Hi Hilco
1 year 11 weeks ago - Hi Kha,
1 year 11 weeks ago - this should
1 year 16 weeks ago - Hi!
Well, there's not much
1 year 18 weeks ago - Have a look at the $_POST
1 year 19 weeks ago - Thanks Tony
1 year 19 weeks ago - 1) No, never use the same ID
1 year 20 weeks ago
New forum topics
Active forum topics
Who's new
Cusomer login area
- Login to post comments
Sat, 12/06/2008 - 12:06
Hi,
My client needs a login page for his customers to login and download various health and safety records.
This will not be linked to a data base, the password and username will be the same for each customer.
I'm not sure how this is done, any ideas?
Thanks in advance
Kevin

Hi Kevin,
This video will show you exactly that
http://www.strawberrycampus.com/node/70
It begins by talking about a database, but that's a piece from the earlier videos, the video shows you exactly what you need. Good luck with it!
Hi Hilco, I tried the lesson at http://www.strawberrycampus.com/node/70 but it does not do what I want it to do.
I did not like that you had to have the actual password and username in the php in plain view on the page.
If you look at the link below you will see the page I am working on. One field is the username 'CHRIS' and the other the password 'BALL'. When the correct username are submitted and posted to a php script called login.php I want the script to open up a page called downloads.htm or php where they can download some files from.
But if the wrong password is submitted I want an error message to appear, something like you have submitted the wrong username or password.
I basically want to protect the files on the download page from being downloaded by just anybody.
http://www.planbdesign.co.uk/tsg/index.php
Thanks
Kevin
if you don't like the plain view, use md5.
you can do everything on one page.
Hi Hilco,
I've copied your php code into my login.php page. what I get when I put the correct password in is a blank page with this line of digits and letters on 5f4dcc3b5aa765d61d8327deb882cf99.
I think there needs to be some code on line 6 and 10 but I dont know what as I dont know php at all.
Kevin
Hi Kevin,
Did you watch the PHP core training? Please watch that if you didn't and implement the exact script as shown in the video.
Make that work at first, and then continue with small changes. I suggest you try to understand what you are doing. The php code provided in the video is pretty basic.
Thanks,
I have not had the chance to watch any of the php videos yet, but I will watch them today.
Thanks,
Kevin
I have watched the php core training and understand a lot of it but I did not see anything that would open a webpage page.
I tried the code below, but obviously it did not work.
I understand how it should work, I just dont know what the code could be between the braces.
<?php
$username = "chris";
$password = "ball";
if($_POST['username'] == $username && $_POST['password'] == $password)
{
fopen("http://www.planbdesign.co.uk/tsg/downloads.php/", "r");
}
else
{
fopen("http://www.planbdesign.co.uk/error_page.php", "r");
}
?>
kevin
Hi Kevin,
fopen is only needed when you try to read the file contents in php. If you just want to include the page, use
<?phpinclude('path/to/file.php');
?>
Hi Hilco,
Thanks for that, however instead of just showing the links I need the code to jump to a separate page called downloads.php as there will be around 50 links to download from and this page will have a secific design to it.
If I remove these two lines
Link to file 1
Link to file 2
What do I replace them with that will automatically open http://www.mydomain.co.uk/downloads.php without having to click on a link?
Is there a line of code that says something like
open http://www.mydomain.co.uk/downloads.php
Kevin
<?phpheader("Location:http://www.mydomain.co.uk/downloads.php");
?>
please do note that downloads.php should be protected as well so people won't be able to access that page directly without loging in.
Hi, Thanks for that.
I am trying to understand how php works so I have created a couple of test files from memory.
After submitting the correct username and password, instead of opening the page I have asked in the php, it displays the page that the form is posted to. why is this?
The else statement works for the incorrect password.
<?php
$username = "pass";
$password = "word";
if ($_POST['username'] == $username && $_POST['password'] == $password)
{
header("Location: <a href="http://www.google.com"" title="http://www.google.com"">http://www.google.com"</a>);
}
else {
print "try again, wrong password";
}
?>
Regards
Kevin
Hi,
Please don't use html in a header statement, just the direct address as I did in my post above yours.
And a HTML form always posts to the "action" of the form element, that's how browsers work, it has nothing to do with php
Hi,
I honestly dont know where the html came from as it is not there in my header code in Dreamweaver!
When I save this comment for some reason the html is added to the header code? automatically ?? And I cant delete it!
my code looks like this, so it should work but it does'nt!
see it here!
http://www.planbdesign.co.uk/php/statements.htm
kevin
Mmm, this site does that by itself, when I edit your post I can see what you did
use echo or print statements to check what if statement is called.
put:
in the above if statement and see if it shows, that's the way you debug your script
The header statement should also be with a capital L. not all browsers accept the lowercase l.
Hi,
I have added the echo "yes" statement to my if statement, see below. It works, I can see it on the page, but the header ("Location: http:// .... etc still does nothing! WHY IS THIS?
<?php
$username = "pass";
$password = "word";
if ($_POST['username'] == $username && $_POST['password'] == $password)
{
header ("Location: <a href="http://www.planbdesign.co.uk/php/downloads.php"" title="http://www.planbdesign.co.uk/php/downloads.php"">http://www.planbdesign.co.uk/php/downloads.php"</a>);
echo "yes it works";
}
else {
print "try again, wrong password";
}
?>
Regards
Kevin
Add those 2 lines of code all the way at the top, maybe your errors aren't displaying.
Hi,
I added those two lines of code and I got an error message, that meant nothing to me. See below.
Warning: Cannot modify header information - headers already sent by (output started at /homepages/44/d83103282/htdocs/planb/php/if_statements.php:10) in /homepages/44/d83103282/htdocs/planb/php/if_statements.php on line 20
I moved the php to the top of the page, out from between the tags. I made sure there was no white space at the top of the page and no white space above the doc type. I tested the form and it redirected me to the correct page!
What stopped it working before I did this, was it because I had the php between the body tags?
Regards
Kevin
yes, that's exactly it.
Headers are sent to the browser BEFORE any of the page content is sent. So when you display just a blank line and then you want to send a header, it won't work, because headers were already sent and then the blank line came
Nice going!
Hi Hilco
Ok, I now understand that now.
So how do I get the else statment to show an error message above the form when the form html is between the body tags of the html page and the php is on its own page?
I just want the error message "you have entered the wrong username and password" to appear on the same page as the form is.
Also, how do I protect the downloads.php page?
Kevin
Hi Kevin,
You protect the downloads.php page by including the downloads.php links inside the if statement instead of redirecting them. That's why I suggested to put in the links instead of a redirect, it's easier to put the login on the same page as the content for you just now. Else, you need to work with sessions like how it's done in the Strawberry CMS videos.
I suggest you look at the following training video to see how error handling is done:
http://www.strawberrycampus.com/node/76
have a look at around 28 minutes, that's the way I prefer doing it.
Hope that clarifies.