CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [SOLVED] User logon restriction

Print topic Send  topic

Author Message
erdcck


Posts: 17
Posted: 08/04/2014, 5:06 AM

Dear friends
How to restrict user logon 09:00 and 18:30.

my code but not working

  	$db = new clsDBmyprintDB();  
  		global $CCSLocales;  
  		$current_time = date('H:i:s');  
  		$worktime_error = ($CCSLocales->GetText("worktime_error"));  
  		$worktimebegin = CCDLookUp("work_begin_time", "companies", "company_id=".CCGetSession("company_id") ,$db);  
  		$worktimeend = CCDLookUp("work_end_time", "companies", "company_id=".CCGetSession("company_id") ,$db);  
  		if ($current_time > $worktimebegin   && $worktimeend < $current_time  ) {  
  		$Component->SetValue("$worktime_error");  
  		}  
{
View profile  Send private message
saseow

Posts: 744
Posted: 08/05/2014, 12:19 AM

With dates I always work with timestamps. e.g.:
$cur_date= time();

Then use the strtotime PHP function to change the values you have stored in the database to change those to timestamps. You can then simply check for larger or smaller as you are doing.

So, to get the timestamp for 9am use something like:
$starttime = strtotime("2005-10-16 09:00:00");

Then get the end time and current time as per above.
Have a look at http://php.net/datetime which has all the info you need.
View profile  Send private message
erdcck


Posts: 17
Posted: 08/05/2014, 7:02 AM

Dear saseow thank you so much everything is fine but adderror not showing :)

working code :

 $db = new clsDBmyprintDB();  
  		global $CCSLocales;  
  		global $Redirect;  
  		$current_time = strtotime(date('H:i:s'));  
  		$worktimebegin = strtotime(CCDLookUp("work_begin_time", "companies", "company_id=".CCGetSession("company_id") ,$db));  
  		$worktimeend = strtotime(CCDLookUp("work_end_time", "companies", "company_id=".CCGetSession("company_id") ,$db));  
  			  
		 if ((($current_time > $worktimebegin) && ($current_time < $worktimeend)) or  CCGetSession("GroupID") > 3) {  
		 }  
		else {  
			$Redirect = "index.php?Logout=yes";  
 			$Login->Errors->addError($CCSLocales->GetText("worktime_error"));  
			}   
		$db->close();
View profile  Send private message
saseow

Posts: 744
Posted: 08/05/2014, 9:42 PM

I am presuming that your login page is called index.php. Because you are redirecting to it you will not be able to add errors.
The simplest way to do this would be to redirect to a page that has a message stating why they cannot login at the current time and to clear the login session vars before showing the page.
View profile  Send private message
erdcck


Posts: 17
Posted: 08/06/2014, 2:21 AM

Quote saseow:
I am presuming that your login page is called index.php. Because you are redirecting to it you will not be able to add errors.
The simplest way to do this would be to redirect to a page that has a message stating why they cannot login at the current time and to clear the login session vars before showing the page.


Dear saseow, you are right, thank you again.
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.