GetDotted Domains

Viewing Thread:
"Password protecting a .php page?"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Mon 03/05/04 at 12:43
Regular
Posts: 14,117
I want to password protect a .php page on my site, so that only admin may view the page.

Is the a way of doing this easily without having to have people log in? I'm using SmartFTP and wondered if I could do it through there somehow, but I haven't managed to figure it out.

Many thanks.
Mon 03/05/04 at 12:43
Regular
Posts: 14,117
I want to password protect a .php page on my site, so that only admin may view the page.

Is the a way of doing this easily without having to have people log in? I'm using SmartFTP and wondered if I could do it through there somehow, but I haven't managed to figure it out.

Many thanks.
Mon 03/05/04 at 12:53
Regular
"Pouch Ape"
Posts: 14,499
There's quite a simple way involving cookies and "file_exists" statements, which I use for adding content on my site.

$pretext = "extrakeyword_";
$format = ".data";
$filename = "$pretext$password$format";
if(file_exists($filename) == TRUE)
{ include("$filename"); }
else
{ print("Go away"); }
; ?>

The variable $password is posted by a form that points to this login page. For this example, you password is "donkeyballs". Then the script searches for a file called "extrakeyword_donkeyballs.data". If it exists, it includes the file, which will contain all your admin features. Else it tels you to "Go away!". You need to create the file called "extrakeyword_donkeyballs.data" for it to be found and included. Simple really, and you can use a PHP cookie to set and retrieve the password.
Mon 03/05/04 at 15:41
Regular
Posts: 14,117
Ummm, ok... I think.

I don't really know anything about coding in PHP. What do I include in the file?
Mon 03/05/04 at 22:03
Regular
"previously phuzzy."
Posts: 3,487
You could start a session on your homepage, declaring variable $userentry1 and $userentry2.

Set up a log-in form (username / password) and pass on this form data to another page, with a script something vaguely like :



then,

Switch ($username)

---case ($)
---$userentry1 = yes
---$userentry2 = no

---case ($)
---$userentry1 = yes
---$userentry2 = yes

(A Switch statment is like an easy way to do nested IF's)

Then, on every page you want to protect, use the session thingy along with a condition like :

IF ($userentry1 = yes) AND ($usernetry2=no) [i.e not staff]
THEN

Works a treat for me.
Mon 03/05/04 at 22:10
Regular
"previously phuzzy."
Posts: 3,487
Quick lesson on sessions :

session_start();
session_register('status1','status2' (SPACE),'username2','password2');
?>

That's on my index before any other code. It basically opens a session, and lists the variables this session will use. You'll probably only need 'status1'.

Then, on every page you want to use sessions :

session_start();
if ( @$status2 != "Yes" )
{
header("Location: register.php");
exit();
}
?>

That basically checks $status2 and acts based on it's contents, in this case, going to /register.php.

Quick lesson on switch statements

switch ($memberPass)
{
case "fruitypie" :
$status1="No";
$status2="No";
echo ;
break;

case "monkey" :
$status1="No";
$status2="No";
echo ;
break;

default :
$status1="No";
$status2="No";
echo ;
break;
}

It's the first few lines of my uber-complex (;D) set of statements to determined users, wrong inputs and the like. You can have as many of the cases as you like.
Tue 04/05/04 at 23:05
Regular
"NULL"
Posts: 1,384
With something like that code, for security it's worth checking to see if Safe Mode is enabled. Either ask your ISP or upload a PHP file containing:



If it isn't then it makes your site vulnerable to fairly simple attacks on that kind of code snippet. The code can be fairly easily modified to prevent the attacks though.
Wed 05/05/04 at 11:37
Regular
Posts: 14,117
Thanks for you help everyone, I'm working on something now.

PHP seems similar to 'C' in some ways. I wonder if there's a program that can convert C to php....
Thu 06/05/04 at 20:48
Regular
"previously phuzzy."
Posts: 3,487
Nimco wrote:
> With something like that code, for security it's worth checking to see
> if Safe Mode is enabled. Either ask your ISP or upload a PHP file
> containing:
>
>

I've just checked, Safe Mode is on.

Thanks for informing :)

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Top-notch internet service
Excellent internet service and customer service. Top-notch in replying to my comments.
Duncan
LOVE it....
You have made it so easy to build & host a website!!!
Gemma

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.