Hello,
I have integrated ZenPhoto for a client and am having a problem with a feature I'm trying to implement. The client is a photographer, as well as the normal galleries, he has password protected galleries for his clients.
He has a link on his homepage "Client Login", I'd like to link that to a form, take the username and password from the form:-
-Using the username, direct the user to his client gallery
-Use the username and password to log the user in so that he doesn't need to fill in the form that appears when you're not logged in (seeing as that would mean asking for the details twice!)
Is there anyway of doing this?
Comments
Actually I've just realised that my solution isn't working yet. My code is as follows:
<?php
require_once("http://www.mysite.com/zenphoto/zp-core/lib-utf8.php");
require_once("http://www.mysite.com/zenphoto/zp-core/functions-db.php");
$post_user = $_POST["user"];
$post_pass = $_POST["pass"];
setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, "/");
header('Location: http://www.mysite.com/zenphoto/' . $post_user);
?>
SBillard - do you have idea what I could do to make this work?
so `setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, "zenphoto/");`
Could you please let me know how I can verify the username and password entered by the client is correct before I create the cookie!
I know the answer is in auth_zp.php file - but I'm having difficulty locating it!
Thanks in advance!
zp_setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, $cookiepath);
} else {
zp_setcookie("zenphoto_auth", "", time()-368000, $cookiepath);
}`
Can I ask what is the difference between: checkAuthorization & checkLogon?
The checkAuthorization does work, but the cookie is not being set (I get the enter username + password form). My code:
<?php
require_once("lib-utf8.php");
require_once("functions-db.php");
$post_user = $_POST["user"];
$post_pass = $_POST["pass"];
if (checkAuthorization(md5($post_user . $post_pass)))
{
zp_setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, "/");
header('Location: http://www.mysite.com/script/' . $post_user);
}
else
{
zp_setcookie("zenphoto_auth", "", time()-368000, "/");
echo "wrong username / password";
}
?>
Just to add,
If I login using my login form, the authentication part works fine, it redirects me to the gallery but the cookie is not set as I get the username and password form.
If I try to login again through my form, it works! It's just the first time that it doesnt work - do you know why this could be?
In answer to your original question, checkLogon() checks a user/password for authentication. checkAuthorization() matches a stored authorization such as a cookie.
If I visit the plain HTML site, click on my login form, submit the correct user details --> I get the user + password form from Zen, the cookie appears not to be set.
If I then click on the same login link and try again, I get logged in and the cookie is set.
My code is as follows - I feel I'm really close to the solution so I hope you can help me wrap things up!
<?php
require_once("lib-utf8.php");
require_once("functions-db.php");
$post_user = $_POST["user"];
$post_pass = $_POST["pass"];
if(checkLogon($post_user, $post_pass))
{
setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, "/");
header('Location: http://www.mysite.com/zenphoto/' . $post_user);
}
else
{
setcookie("zenphoto_auth", "", time()-368000, "/");
header('Location: http://www.mysite.com/login-failed.html');
}
?>
I modified the code slightly:
`
if(checkLogon($post_user, $post_pass))
{
setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, "/");
$_zp_loggedin = checkAuthorization(zp_getCookie('zenphoto_auth'));
if ($_zp_loggedin) {
header('Location: http://www.mysite.com/script/' . $post_user);
}
}
`
This results in a blank screen which means the cookie is not being set on the first attempt but does get set on subsequent attempts - I don't understand why this happens!
p.s. http://www.zenphoto.org/2008/07/zenphoto-single-login/ < I had some problems copying and pasting the code, there's some formatting errors on the page