matik
Posts: 57
|
| Posted: 01/15/2007, 6:30 AM |
|
Hi,
I am trying to use this ASP code:
' On successful login, persist cookies by giving them an Expires value
If Login.RememberMe.Value Then
Response.Cookies("login").Expires = "01/01/2030"
Response.Cookies("pass").Expires = "01/01/2030"
' Save login info in cookies
Response.Cookies("login") = Login.login.Value
Response.Cookies("pass") = Login.password.Value
Else
Response.Cookies("login") = ""
Response.Cookies("pass") = ""
End If
And convert to PHP:
if ($Login_Button_DoLogin_OnClick) {
$Response->Cookies("login")->Expires = "01/01/2030";
$Response->Cookies("pass")->Expires = "01/01/2030";
$Response->Cookies("login") = $Container->login->Value;
$Response->Cookies("pass") = $Container->password->Value;
Else
$Response->Cookies("login") = "";
$Response->Cookies("pass") = "";
}
But I always get errors.
Can someone help and fix this code.
Thank you
|
 |
 |
peterr
Posts: 5971
|
| Posted: 01/15/2007, 12:51 PM |
|
There is no such syntax in PHP but you can find various examples here: http://www.google.com/search?q=php+cookies
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
klwillis
Posts: 428
|
| Posted: 01/15/2007, 1:34 PM |
|
This should be of some help: http://www.php.net/manual/en/function.setcookie.php
Quote matik:
Hi,
I am trying to use this ASP code:
' On successful login, persist cookies by giving them an Expires value
If Login.RememberMe.Value Then
Response.Cookies("login").Expires = "01/01/2030"
Response.Cookies("pass").Expires = "01/01/2030"
' Save login info in cookies
Response.Cookies("login") = Login.login.Value
Response.Cookies("pass") = Login.password.Value
Else
Response.Cookies("login") = ""
Response.Cookies("pass") = ""
End If
And convert to PHP:
if ($Login_Button_DoLogin_OnClick) {
$Response->Cookies("login")->Expires = "01/01/2030";
$Response->Cookies("pass")->Expires = "01/01/2030";
$Response->Cookies("login") = $Container->login->Value;
$Response->Cookies("pass") = $Container->password->Value;
Else
$Response->Cookies("login") = "";
$Response->Cookies("pass") = "";
}
But I always get errors.
Can someone help and fix this code.
Thank you
_________________
Kevin Willis, VP/CIO
HealthCare Information Technology Specialist
http://www.nexushealthcare.com
"Fast - Convenient - Quality-Care"
Medical Software Consulting Services
Email : klwillis@nexushealthcare.com
Skype : klwillis2006 |
 |
 |
matik
Posts: 57
|
| Posted: 01/15/2007, 1:38 PM |
|
I am trying to make remember user login cookie for users.
I know how to setup cookies but when I visit restricted page what kind of data I need in cookie to avoid login page and typing user/pass??
Thank you
|
 |
 |
peterr
Posts: 5971
|
| Posted: 01/15/2007, 1:50 PM |
|
You can add into Common.php some code that checks if CCGetUserID() is empty and then use the cookie values to login the user. Here is sample code that automatically logs in a sample user with such sample values: user id = 1, username = ABC, group id = 100:
CCSetSession("UserID", 1);
CCSetSession("UserLogin", "ABC");
CCSetSession("GroupID", 100);
In your code you can replace the above 3 values with those retrieved from your cookies (or anywhere else).
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
matik
Posts: 57
|
| Posted: 01/15/2007, 2:42 PM |
|
Thank you for help. I have add this code on login page:
if ($Login_Button_DoLogin_OnClick) {
CCSetCookie("UserID", CCGetUserID());
CCSetCookie("UserLogin", CCGetUserLogin());
CCSetCookie("GroupID", CCGetGroupID());
}
And please tell me where exactly in common.php I have to add this code:
if ( CCGetUserID() != "") {
CCSetSession("UserID", CCGetCookie("UserID"));
CCSetSession("UserLogin", CCGetCookie("UserLogin"));
CCSetSession("GroupID", CCGetCookie("GroupID"));
}
I have added to the end of script but I don’t get any results.
|
 |
 |
peterr
Posts: 5971
|
| Posted: 01/15/2007, 11:54 PM |
|
End of the script is fine.
Whenever something doesn't work you may need to debug it by printing various values and checking if they match what you expect. For example:
echo CCGetCookie("UserID");
exit;
You can also use my code above with some specific values (not cookies) to test if this works for you.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
matik
Posts: 57
|
| Posted: 01/19/2007, 9:12 AM |
|
Thank you Peterr, with your help I have found working solution.
I have add this code at the end of common.php:
Quote :
if ( CCGetUserID() == "") {
CCSetSession("UserID", CCGetCookie("UserID2"));
CCSetSession("UserLogin", CCGetCookie("UserLogin2"));
CCSetSession("GroupID", CCGetCookie("GroupID2"));
}
And this code to login.php -> login bottom->custom code:
Quote :
if ($Login_Button_DoLogin_OnClick) {
CCSetCookie("UserID2", CCGetUserID());
CCSetCookie("UserLogin2", CCGetUserLogin());
CCSetCookie("GroupID2", CCGetGroupID());
}
And on the same login_events.php I have add this code when user click logout ( I have add parameter “out” = 1 for logout button):
Quote :
if(strlen(CCGetParam("Logout", "")))
{
CCLogoutUser();
//Start my inserted code
if (CCGetParam("out", "0") == 1) {
CCSetCookie("UserID2", "");
CCSetCookie("UserLogin2", "logout");
CCSetCookie("GroupID2", "");
}
//end my inserted code
global $Redirect;
$Redirect = "login.php";
}
//End Logout
Its work perfect on Linux web server but on my win IIS for testing sometimes I have troubles with cookies:
1. open IE and type restricted area URL
2. enter user – pass and login correctly
3. open new IE and type restricted area URL – no need to login
4. now I click logout
5. open new IE and type restricted area URL - enter user – pass and login but cookie is not setup properly (if I print(echo) UserLogin2 cookie I get logout value)
6. if I open new IE and type restricted area URL again I have to enter user – pass
this problem is only on my localhost.
I am not sure if this code:
Quote :
//Start my inserted code
if (CCGetParam("out", "0") == 1) {
CCSetCookie("UserID2", "");
CCSetCookie("UserLogin2", "logout");
CCSetCookie("GroupID2", "");
}
//end my inserted code
Is on correct place when user click logout button??
If someone have better solution please lett me know.
Regards,
Matik
|
 |
 |
|