I have a daughter and son in law in iraq. I am taking care of the grandbaby till they get back. There are so many family members and them over seas that I fealt a web site where they all can access them would be a very good idea. I have a domain name already, made my front page. On the main page there is a link to nothing, because this is where I want to control access with passwords. I right most of my code in straight html using css. I have no clue how to do the secure part. Can someone point me in the right direction?
If this is your only need from PHP, then its not a big task.
I see your need is just to show your pictures to few of your family members. I'll just give a short script and you can use that.
index.php (add this somewhere in your main page and name your page as index.php)[html]<form action="pictures.php" method="post">
Id:<input name="id" type="text" /><br />
Password:<input name="password" type="password" /><br />
<input name="login" type="submit" value="Submit" />
</form>[/html]
pictures.php[php]<?php
require ("ids.php");
if (isset($_COOKIE["viewer_id"]) && isset($_COOKIE["viewer_password"]))
if ($_COOKIE["viewer_password"] == md5($passwords[array_search($_COOKIE["viewer_id"], $ids)]))
{
show_list_page();
exit();
}
if (isset($_POST["login"]) && isset($_POST["id"]) && isset($_POST["password"]))
if (in_array($_POST["id"], $ids))
if ($_POST["password"]==$passwords[array_search($_POST["id"], $ids)])
{
$hour = time() + 86400; //FOR 24 HOURS
setcookie("viewer_id", $_POST["id"], $hour);
setcookie("viewer_password", md5($_POST["password"]), $hour);
show_list_page();
exit();
}
header ("location:index.php");
function show_list_page()
{
?>
<!-- copy here the HTML that contains the list and links to all the pictures -->
<?php
}[/php]
logout.php (Link this somewhere in pictures.php)[php]<?php
$past = time() - 100;
setcookie("viewer_id", "", $past);
setcookie("viewer_password", "", $past);
header("location:index.php");
?>[/php]
ids.php[php]<?php
$ids = array(
"my_id",
"your_id",
"his_id",
"her_id"
);
$passwords = array(
"my_password",
"your_password",
"his_password",
"her_password"
);
?>[/php]This
ids.php contains the list of all the ids and passwords which you can give your relatives. You can add ids and passwords in it, but you would need to be careful that the serial order remains respective.
The only limitations are, user can't himself change the password and you may not have TOO many ids and passwords.
I have not tested it, so if any problem is there, do let me know.
Regards,
Harpreet