Nandini Posted September 29, 2008 Share Posted September 29, 2008 Hi i am doing change timezones using php If user select one timezone as Hong_Kong. The system time was automatically change to current Hong_Kong time. for this i am executing the following command by using shell_exec. if ($q=="Asia/Hong_Kong") { putenv("TZ=Asia/Hong_Kong"); $time = date("g:i a"); echo $time; $command=shell_exec('ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime'); echo "<pre>$command</pre>"; } By using above script the system time was not changing. If i am using that linux commnd (ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime) in command line its working fine. But through script its not working. Can anyone help me. Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/ Share on other sites More sharing options...
ranjuvs Posted September 29, 2008 Share Posted September 29, 2008 I don't know what you are trying to do with shell command just adding the command putenv("TZ=Asia/Hong_Kong"); at the top of the page will work fine. May be you could save the part "TZ=Asia/Hong_Kong" in session if you need to assign different time zones for different user. Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652814 Share on other sites More sharing options...
Nandini Posted September 29, 2008 Author Share Posted September 29, 2008 by using this system time will not same. Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652817 Share on other sites More sharing options...
Nandini Posted September 29, 2008 Author Share Posted September 29, 2008 Sorry 'change' in the place of 'same' sorry for the mistype. Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652818 Share on other sites More sharing options...
ranjuvs Posted September 29, 2008 Share Posted September 29, 2008 can you please post your code Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652824 Share on other sites More sharing options...
Nandini Posted September 29, 2008 Author Share Posted September 29, 2008 Hi here is the total code. the following is my html form. <script type="text/javascript" src="clienthint.js"></script> <form> Select timezone: <select name="customers" onchange="showHint(this.value)"> <option value="America/Santiago">America/Santiago</option> <option value="Asia/Hong_Kong">Asia/Hong_Kong</option> <option value="Asia/Calcutta">Asia/Calcutta</option> </select> </form> </td><td> <div id="txtHint"><b> </b></div> clienthint.js // JavaScript Document var xmlHttp function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="get_time.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlHttp.responseText; } }function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } get_time.php <?php header("Cache-Control: no-cache, must-revalidate"); // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //get the q parameter from URL $q=$_GET["q"]; if ($q=="America/Santiago") { putenv("TZ=America/Santiago"); $time = date("g:i a"); echo $time; } if ($q=="Asia/Hong_Kong") { putenv("TZ=Asia/Hong_Kong"); $time = date("g:i a"); echo $time; $command="ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime"; ////this command is for change system time echo shell_exec($command); } if ($q=="Asia/Calcutta") { putenv("TZ=Asia/Calcutta"); $time = date("g:i a"); echo $time; $command="ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime"; echo shell_exec($command); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652827 Share on other sites More sharing options...
ranjuvs Posted September 29, 2008 Share Posted September 29, 2008 This won't work as you are setting the time zone in a different page. For this to work you need to set it on the top of every page or in the configuration file which is included in every file. Try to put the code putenv("TZ=America/Santiago"); on top of your page and try to print the same. the shell command you are using is of no use. It just builds a link to the file specified. Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652830 Share on other sites More sharing options...
Nandini Posted September 29, 2008 Author Share Posted September 29, 2008 Thanx for ur cooperation Mr. ranjuvs As you are saying my script is in my header part of my website. It will apply all pages. Until that working fine. But i want to system time when select timezone. How can i do that? Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652833 Share on other sites More sharing options...
ranjuvs Posted September 29, 2008 Share Posted September 29, 2008 I didn't understand this part - "But i want to system time when select timezone." Can you make it clear Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652835 Share on other sites More sharing options...
trq Posted September 29, 2008 Share Posted September 29, 2008 The apache process (and therefore php) does not have enough permissions to change links within /etc. Doing so would be quite a security issue. Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652843 Share on other sites More sharing options...
Nandini Posted September 29, 2008 Author Share Posted September 29, 2008 I got a command for change system time. that is date 092916002008 Here is 09 ----> MM 29 -----> DD 16 ------>HH (hours) 00 ------>mm(Minuts) 2008 ----> YYYY (year) Thanx for everyone help. Quote Link to comment https://forums.phpfreaks.com/topic/126248-solved-shell_exec-problem/#findComment-652846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.