Login Integration

Hi guys,

I wonder if you can help..

I am trying to allow seamless login from my main CMS (App 1) to zen photo.

Ideally once the user has logged into the main CMS they should not have to re-login to Zen Photo.

I can set it so both passwords are the same *however* how whenever I try to link to /zen/admin.php using the below script i get an error saying problem with login.

I am passing variables 'user', 'pass', 'redirect' and 'login' as you can see from my test script but still no joy..

Is there any special thing about zen photo admin page / login i need to know about?

Thanks for your help..

*************************************************************************************
TEST CODE
*************************************************************************************
<?
$request = "";
$param["user"] = "mickoc";
$param["pass"] = "mmcs";
$param["login"] = "1";
$param["redirect"] = "/zen/admin.php";

foreach($param as $key=>$val)
{
$request.= $key. "=" . urlencode($val);
$request.= "&";
}
$request = substr($request, 0, strlen($request)-1); //remove last &

echo $request;

$url = "http://www.mysite.com/mmcs/photos/company1/zen/admin.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //set the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //return as a variable
curl_setopt($ch, CURLOPT_POST, 1); //set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //set the POST variables
$response = curl_exec($ch); //run the whole process and return the response
curl_close($ch); //close the curl handle

echo $response;

/*
//you can do some testing here with the response, to see whether the login was successful, etc.
if ($response == 'success') {
header("location: http://www.mysite.com/yey.html");
} else {
header("location: http://www.mysite.com/nichnich.html");
}*/

?>
**************************************************************************************
END TEST CODE
***************************************************************************************

Comments

  • trisweb Administrator
    Okay, that won't work because you're loading it within PHP.... the cookie needs to be set on the user's system to work, so the user has to load the url, not the server.

    Take a look at `/zen/auth-zp.php`, it's short, sweet, well-documented and easy to read. Do what it does in reverse to set the "zenphoto_auth" cookie manually, that'd be my suggestion. You have to set the same $cookiepath, but that's all you have to get right essentially. The hash in the cookie is just `md5($adminuser . $adminpass);` (the dot is a concatenation). So all you have to do is this:

    `$user = "username";

    $pass = "password";

    $cookiepath = "http://www.yoursite.com/zenphotodir"; // Same as WEBPATH

    setcookie("zenphoto_auth", md5($user . $pass), time()+5184000, $cookiepath);`

    Also note this only works if you're on the same domain as your ZP installation. Otherwise you'll need the user to load `auth-zp.php` somehow, maybe with a JavaScript call.
  • Ok,

    Have spent a good few hours at this and still can't get it to work.

    What's happening is as follows:

    1. When i process the login for my main CMS i have the following code.

    <?php
    session_start();

    $username = $_POST['username'];
    $user_password = $_POST['password'];

    include '../includes/functions.php';
    require_once("../photos/$username/zen/functions-db.php");
    require_once("../photos/$username/zen/auth_zp.php");

    // Login to my CMS
    $user = new User();
    $username = $user->login( $username, $user_password );

    // If USER MATCHES
    if ($username != "")
    {

    $user_id = $user->getid($username);
    $user_first_name = $user->get_first_name($username);
    $mini_co_id = $user->get_mini_co_id($username);
    $mini_co_name = $user->get_mini_co_name($username);

    // Log into Zen Photo

    $cookiepath = "http://www.mysite.org/mmcs/photos/$username";
    //echo "Cookiepath is : " . $cookiepath;
    //setcookie("zenphoto_auth", md5($username.$user_password), time()+5184000,
    $cookiepath);
    setcookie("zenphoto_auth", md5($username.$user_password), time()+5184000);
    $_zp_loggedin = true;

    2. For some reason i cant set the cookie if i include the Cookiepath

    3. I run a check on the same script to see if the cookie is set and it is

    4. I then link to ../photos/$username/zen/admin.php

    I still get a login box no matter what i try.. really strange because the cookie is being set now..

    If there is anything you can suggest that might help it would be MUCH appreciated as i'm pulling my hair out here!

    Thanks :)
  • Hi there,

    Ok finally got it sorted was to do with the url path of the cookie..

    Thanks a million!
  • trisweb Administrator
    Thought so. Glad you fixed it!
Sign In or Register to comment.