Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old 07-15-2009, 04:38 PM
Senior Member
 
Posts: 59
Question Cookie error

Fairly new at at php but here is what I've done by using your example in a custom login page which I've called index.php
----

?php
function zimbraLogin($username, $password, $client)
{
// Bring the zimbra server value into this function:
global $zimbra_server; // In the format: https://yourdomain.com/

if($client == "")
$client = "preferred";

// Attempt login to zimbra server:
$ch = curl_init();

$crap = fopen ("/dev/null", "w"); // We don't want to log curl's stderr output - contains passwords...

curl_setopt($ch, CURLOPT_URL, $zimbra_server);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Stop Curl from validating SSL cert - needed for self-signed...
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); // Allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 0); // Time out setting
curl_setopt($ch, CURLOPT_HEADER, 1); // Return the headers along with the output...
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_STDERR, $crap);
curl_setopt($ch, CURLOPT_COOKIE, 'ZM_TEST=true');
curl_setopt($ch, CURLOPT_REFERER, "$zimbra_server");
curl_setopt($ch, CURLOPT_POSTFIELDS, "loginOp=login&username=$username&password=$passwo rd&client=$client");

$result = curl_exec($ch);

curl_close($ch);
fclose($crap);

$values = explode("\n",$result);

// Search through the headers to find the Location value to pass to the browser:
foreach($values as $key => $value)
{
list($start, $good) = split(':', $value);

// Found an anamoly where people with cleared cookies have to log in twice...
// Fix it by taking the auth token out of the cookie and passing it through as a URL
if($start == "Set-Cookie")
{
$newurl = $zimbra_server . "?client=$client&zauthtoken=" . $values[$key];
header("Location: $newurl");
die;
}

if($start == "Location")
{
header($values[$key]);
die;
}
}
// If we get here that means that no location header was found - most likely incorrect password, zimbra is down, etc.
return false;
}

?>


I also have copied the login form into my page which looks like --
<form action="https://mydomain.com/zimbra/" method="post" name="form1" id="form1">
<div align="center"> Email Address
<input name="username" type="text" size="55"/>
<br />
Password
<input name="password" type="password" size="45" />
<input type="hidden" name="loginOp" value="login"/>
<input type="hidden" name="client" value="preferred"/>
<input type="submit" name="Submit" value="Submit"/>
</div>
</form>

If my users clear there cache or have there browser set to remove cookies at when they close there browser they get a cookie error when trying to login. All they need to do is click login again and it works. What have I done wrong in the code?
__________________
Chris Priamos
Olympic Global Technologies
http://www.olympicglobal.com
Reply With Quote
  #12 (permalink)  
Old 01-05-2011, 10:37 AM
Starter Member
 
Posts: 2
Default

Quote:
Originally Posted by chrisp8756 View Post
Fairly new at at php but here is what I've done by using your example in a custom login page which I've called index.php
----

?php
function zimbraLogin($username, $password, $client)
{
// Bring the zimbra server value into this function:
global $zimbra_server; // In the format: https://yourdomain.com/

if($client == "")
$client = "preferred";

// Attempt login to zimbra server:
$ch = curl_init();

$crap = fopen ("/dev/null", "w"); // We don't want to log curl's stderr output - contains passwords...

curl_setopt($ch, CURLOPT_URL, $zimbra_server);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Stop Curl from validating SSL cert - needed for self-signed...
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); // Allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 0); // Time out setting
curl_setopt($ch, CURLOPT_HEADER, 1); // Return the headers along with the output...
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_STDERR, $crap);
curl_setopt($ch, CURLOPT_COOKIE, 'ZM_TEST=true');
curl_setopt($ch, CURLOPT_REFERER, "$zimbra_server");
curl_setopt($ch, CURLOPT_POSTFIELDS, "loginOp=login&username=$username&password=$passwo rd&client=$client");

$result = curl_exec($ch);

curl_close($ch);
fclose($crap);

$values = explode("\n",$result);

// Search through the headers to find the Location value to pass to the browser:
foreach($values as $key => $value)
{
list($start, $good) = split(':', $value);

// Found an anamoly where people with cleared cookies have to log in twice...
// Fix it by taking the auth token out of the cookie and passing it through as a URL
if($start == "Set-Cookie")
{
$newurl = $zimbra_server . "?client=$client&zauthtoken=" . $values[$key];
header("Location: $newurl");
die;
}

if($start == "Location")
{
header($values[$key]);
die;
}
}
// If we get here that means that no location header was found - most likely incorrect password, zimbra is down, etc.
return false;
}

?>


I also have copied the login form into my page which looks like --
<form action="https://mydomain.com/zimbra/" method="post" name="form1" id="form1">
<div align="center"> Email Address
<input name="username" type="text" size="55"/>
<br />
Password
<input name="password" type="password" size="45" />
<input type="hidden" name="loginOp" value="login"/>
<input type="hidden" name="client" value="preferred"/>
<input type="submit" name="Submit" value="Submit"/>
</div>
</form>

If my users clear there cache or have there browser set to remove cookies at when they close there browser they get a cookie error when trying to login. All they need to do is click login again and it works. What have I done wrong in the code?
set cookie in the html page with following name and value
"ZM_TEST", "true" and it will works. I just figure it out today ))
Reply With Quote
  #13 (permalink)  
Old 01-05-2011, 10:57 AM
Senior Member
 
Posts: 59
Default how to set cookie

Sorry I'm not sure how to set a cookie in html or even in php. Can you tell me how I can do this?
__________________
Chris Priamos
Olympic Global Technologies
http://www.olympicglobal.com
Reply With Quote
  #14 (permalink)  
Old 01-05-2011, 05:45 PM
Senior Member
 
Posts: 59
Default Oops! It appears your browser does not allow cookies. You need to enable cookies in

I've managed to setup the cookie in my site. But when they close there browser or log out. Then return to login again I get the following error from the zimbra login screen "Oops! It appears your browser does not allow cookies. You need to enable cookies in".


Any ideas on how I resolve this?

I'm currently using using this code to set my cookie-

<?php
setcookie("ZM_TEST","true",time()+3600 , "/", ".mail.mydomain.com");
?>
__________________
Chris Priamos
Olympic Global Technologies
http://www.olympicglobal.com
Reply With Quote
  #15 (permalink)  
Old 01-05-2011, 07:47 PM
Starter Member
 
Posts: 2
Default

this is a javascript is use to set the cookie

function setCookie(name, value, expires, path, domain, secure) {
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

setCookie("ZM_TEST","true");
Reply With Quote
  #16 (permalink)  
Old 07-14-2011, 12:33 PM
New Member
 
Posts: 3
Default

This function dont work anymore.

Show me a message "Auth necessary".

More ideias?
Reply With Quote
  #17 (permalink)  
Old 07-14-2011, 12:57 PM
Senior Member
 
Posts: 53
Default

you can use preauth to authenticate from external php script.
Reply With Quote
  #18 (permalink)  
Old 07-14-2011, 01:15 PM
New Member
 
Posts: 3
Default

Quote:
Originally Posted by andy204 View Post
you can use preauth to authenticate from external php script.
But preauth not verify the password.
Reply With Quote
  #19 (permalink)  
Old 07-14-2011, 02:18 PM
Senior Member
 
Posts: 53
Default

thats true, but you can verify the password before preauth.
Reply With Quote
  #20 (permalink)  
Old 07-14-2011, 03:21 PM
New Member
 
Posts: 3
Default

Quote:
Originally Posted by andy204 View Post
thats true, but you can verify the password before preauth.
How do it?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.