Password Protection example

Started by zubrag, December 14, 2006, 05:03:22 PM

recoding

Hi ostatni,
Could you please copy and paste into a reply lines 115, 116 and 117?

Should be able to start to help then.

pan2

Hello,
I've been working on this for countless hours now, to the point that I think I'm about to cry.

As with so many other people, I've encountered the incredibly bothersome "cannot modify headers" problem:
Warning: Cannot modify header information - headers already sent by (output started at /home/doki/public_html/hetalia/admin2.php:1) in /home/doki/public_html/hetalia/password_protect.php on line 184

I've already checked for white spaces and there aren't any. I wonder if it's because I'm trying to combine so many different scripts and I have no idea what I'm doing. admin2.php is supposed to have a password form and then upon entering the correct password, it opens and displays another text file (which I have working).

These are the first two lines of admin2.php
<?php include("/home/doki/public_html/hetalia/password_protect.php");
include (
'pagestop.txt'); //regular text file with header info like <html>..<body>
//below this is code for opening & displaying another .txt


This was originally line 184 of password_protect.php, and after I // out the line as I read under the comments on the main page, the line of error changed to 158.
setcookie("verify", md5($lp), $timeout, '/');

These are lines 157-158 of password_protect.php
// set cookie if password was validated
    setcookie("verify", md5($login.'%'.$pass), $timeout, '/');

After I commented out line 158, the headers problem disappeared. But then, naturally, it wouldn't remember any cookies and I would have to re-enter the password each time which is tiresome!

Please help, somebody! I can also email my entire PHP codes and also give the URL to show the problem.

recoding

Hi pan2,
It sometimes can be hard to read the errors, the error is basically saying that the command on line 158 cannot be ran because of: output started at /home/doki/public_html/hetalia/admin2.php:1 or basically, admin2.php seems to have something on line one..what do you use to edit your files? try opening in wordpad(windows) or textedit(for mac) and making sure there is absolutely nothing there, if it still doesn't work send me a private message with the two php scripts attached, and I'll try and have a look for you.

pan2

I use notepad, and I've checked time and time again! I am certain there are no white spaces!
I will send you the PM now though, thank you for helping!

nairda

Hello,

This script seems fantastic and is just the thing I'm looking for, however I've the same problems as many others and have been trying to fix for many hours now! Have searched all the postings but no luck I'm afraid. I've added the line <?php include("/mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/protector/password_protect.php"); ?> to my header.php file so gets added to all pages on the site. The problems I have are:

1) Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/wp-content/themes/cheap-online-train-tickets-theme/three_column_template_cheap_tickets.php:7) in /mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/protector/password_protect.php on line 137

If I comment out the line 137 this message is gone :-) But I would like it to have the option for cookies, how can I do this? I've checked my documents and can't see any white space.

2) I have to login on every page! I only want to enter the login details once so I can then browse all of the website.

This is a test site (need to implement this on a live site once I have ready). Any help would be much appreciated. I'd gladly email you the password_protect.php and header.php files I am using if it helps.

Kind regards,

Adrian

recoding

Hi Adrian,
The problems 2 and 3 are because of 1, cookies make it possible to save that you have logged in, and delete them when you logout.

So to do anything, we need to fix problem 1, now just commenting it out does fix the problem, but removes complete functionality.

Basically you may have added the password_protect to the right place, however the file ../wp-content/themes/cheap-online-train-tickets-theme/three_column_template_cheap_tickets.php loads BEFORE header.php so that is the problem, to be exact on the file three_column_template_cheap_tickets.php on line 7, something is said, what I recommend is moving the line: <?php include("/mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/protector/password_protect.php"); ?> and adding it to three_column_template_cheap_tickets.php on line one. It should work then.

nairda

Hello again,

It's always the way isn't it, you search for hours to find a solution before making a posting... then a few minutes later find the solution :-) http://www.zubrag.com/forum/index.php/topic,360.0.html made it very clear what was needed to fix my problems.

Tried to delete my previous post but couldn't see how so just wanted to say a big thank you for the script :-)

Many thanks,

Adrian

recoding

Ah I thought you may have read that, okay :D

lambofgod

Hi, i'm so newb at this its not even funny.

Where would i set my username/password?

I see a line where it say's

  'zubrag' => 'root',
  'admin' => 'adminpass'

and i tired to replace
'root' with my username &
'adminpass' with my password.

it still wouldn't let me log in :( please help!!!

recoding

Hey lambofgod,

Could you private message me your complete script (the whole file) I'll take a look (:

designer

Hello-
I have been trying for hours now to get the password to take in my file and I can't get it to take, and let me in to what I am protecting.

Would someone have some advice?


recoding

Take in your file? how are you including it? If you do not want to paste your code here please feel free to PM me and I'll try my best to help out ;)

akishimo

lambofgod:
you're supposed to replace 'zubrag' with username and 'root' with password. Same for the next line.

For all those who couldn't get the log-in page to come up, I had the same problem until I discovered this:

Let's say you were trying to password protect "Home.html".

You change the name to "Home.php"

However this "homepage" comes with a folder that contains your images and other stuff.

The password log-in may not be showing because you probably have to change everything in your folder that used to refer to "Home.html" to "Home.php"

I created an entirely new test page with no other folders/files attached, and the password script worked perfectly.

Hope this helps.

maco

Is there a way to add a logout button at the page that has been protected and when the user presses it it sends them back to the login page... I know when the session times out this happens but I want the user to be able to do it aswell...

how would this be done?