<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ask Your Question &#187; PHP</title>
	<atom:link href="http://askbahar.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://askbahar.com</link>
	<description>Lets Talk</description>
	<lastBuildDate>Thu, 29 Sep 2011 05:48:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to add scheduled task to run php scripts in Windows</title>
		<link>http://askbahar.com/2011/04/22/add-scheduled-task-to-run-php-scripts-in-windows/</link>
		<comments>http://askbahar.com/2011/04/22/add-scheduled-task-to-run-php-scripts-in-windows/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 07:20:24 +0000</pubDate>
		<dc:creator>Habib Ullah Bahar</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[scheduled task]]></category>
		<category><![CDATA[schtasks]]></category>

		<guid isPermaLink="false">http://askbahar.com/?p=124</guid>
		<description><![CDATA[<p>Few days ago, for one of our PHP / MySQL project, we were needed to run two php scripts at every minute. We usually develop/deploy our projects in LAMP environment, where we use <a href="http://adminschoice.com/crontab-quick-reference">crontab</a> for our scheduled tasks. But our client have wanted us to run the system in Windows. So we have chosen  [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago, for one of our PHP / MySQL project, we were needed to run two php scripts at every minute. We usually develop/deploy our projects in LAMP environment, where we use <strong><a href="http://adminschoice.com/crontab-quick-reference">crontab</a></strong> for our scheduled tasks. But our client have wanted us to run the system in Windows. So we have chosen  <strong><a href="http://www.apachefriends.org/en/xampp-windows.html">XAMPP</a></strong>. To run our two php scripts every 1 &amp; 2 minute, we thought of developing a simple tool for windows which would run at background and execute those two php scripts. Fortunately we have found about <strong><a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true">schtasks</a></strong>, a native scheduler in Windows to run scheduled task smoothly in command prompt.<br />
<span id="more-124"></span><br />
I will not describe our actual situation, rather I will demonstrate with 2 simple php scripts.</p>
<p>1. Create a directory in your <strong>htdocs</strong> folder inside XAMPP installation directory. In my case, it was <em>C:\xampplite\htdocs\test</em></p>
<p>2. Create two php scripts, <em>test1.php</em> and <em>test2.php</em> inside test directory using the following respective code.<br />
[php]&lt;?php<br />
//test1.php<br />
//creates, appends current time in a file called dump1.txt<br />
date_default_timezone_set(&#8216;Asia/Dacca&#8217;);<br />
$time = date(&#8216;Y-m-d H:i:s&#8217;);<br />
$file = &quot;C:/xampplite/htdocs/test/dump1.txt&quot;;<br />
file_put_contents($file,&quot;job1 run on: $time\r\n&quot;, FILE_APPEND);<br />
?&gt;[/php]<br />
[php]&lt;?php<br />
//test2.php<br />
//creates, appends current time in a file called dump2.txt<br />
date_default_timezone_set(&#8216;Asia/Dacca&#8217;);<br />
$time = date(&#8216;Y-m-d H:i:s&#8217;);<br />
$file = &quot;C:/xampplite/htdocs/test/dump2.txt&quot;;<br />
file_put_contents($file,&quot;job2 run on: $time\r\n&quot;, FILE_APPEND);<br />
?&gt;[/php]</p>
<p>3. create a batch file <em>php_service_creator.bat</em> with the following code.<br />
[vb]<br />
SCHTASKS /Create /RU SYSTEM /SC MINUTE /MO 1 /TN &quot;test_sch_task1&quot; /TR &quot;C:\xampplite\php\php-win.exe -f C:\xampplite\htdocs\test\test1.php&quot;<br />
SCHTASKS /Create /RU SYSTEM /SC MINUTE /MO 5 /TN &quot;test_sch_task2&quot; /TR &quot;C:\xampplite\php\php-win.exe -f C:\xampplite\htdocs\test\test2.php&quot;<br />
[/vb]</p>
<blockquote><p>
1. <em>test_sch_task1</em> task will run on every minute.<br />
2. <em>test_sch_task2</em> task will run on every fifth minute.
</p></blockquote>
<p>to understand the used (and other possible) parameters, please visit <a href="http://www.robvanderwoude.com/schtasks.php">this link</a></p>
<p>4. Run just created <em>php_service_creator.bat</em>. Please note that you have to run this from an account with administrative privileges. </p>
<p>5. After about 20 minutes, check <em>C:/xampplite/htdocs/test/dump1.txt</em> &#038; <em>C:/xampplite/htdocs/test/dump2.txt</em> files for output.</p>
<p>6. To check/view all the added scheduled tasks, type <em>schtasks</em> in command prompt.</p>
<p>7. To delete any scheduled task, type <em>schtasks /Delete /TN TASK_NAME_FOR_DELETE</em> in command prompt.</p>
<p>I hope it helps some people like me.</p>
<p>Comments, suggestions are appreciated <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://askbahar.com/2011/04/22/add-scheduled-task-to-run-php-scripts-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to generate getter/setter in PHP easily</title>
		<link>http://askbahar.com/2010/07/14/generate-getter-setter-in-php-easily/</link>
		<comments>http://askbahar.com/2010/07/14/generate-getter-setter-in-php-easily/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 04:21:16 +0000</pubDate>
		<dc:creator>Habib Ullah Bahar</dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[get-set]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://askbahar.com/?p=70</guid>
		<description><![CDATA[<p>For one of my current project I need to write getter/setter functions for 20+ variables. You know, how annoying it is! Well, I can use magic quotes, but I don&#8217;t like it. More over getter setter will help you later to use the class when your IDE (in my case <a title="Netbeans IDE" href="http://netbeans.org" target="_self">Netbeans</a>) [...]]]></description>
			<content:encoded><![CDATA[<p>For one of my current project I need to write getter/setter functions for 20+ variables. You know, how annoying it is! Well, I can use magic quotes, but I don&#8217;t like it. More over getter setter will help you later to use the class when your IDE (in my case <a title="Netbeans IDE" href="http://netbeans.org" target="_self">Netbeans</a>) supports <em>auto complete suggestion</em>. Though all Java development environments allow to generate getter and  setter code automatically.<br />
Then I started coding a php script for generating getter/setter for supplied variables, but I was lucky as suddenly I thought &#8220;why don&#8217;t I look for something like this online&#8221; <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And here is the link I got, its quite good. <a title="PHP Getter Setter Generator" href="http://www.icurtain.co.uk/getset.php" target="_blank">http://www.icurtain.co.uk/getset.php</a>, It saved my time.</p>
]]></content:encoded>
			<wfw:commentRss>http://askbahar.com/2010/07/14/generate-getter-setter-in-php-easily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to enable Apache HTTP Authentication using PHP</title>
		<link>http://askbahar.com/2009/11/11/enable-apache-http-authentication-using-php/</link>
		<comments>http://askbahar.com/2009/11/11/enable-apache-http-authentication-using-php/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 09:24:39 +0000</pubDate>
		<dc:creator>Habib Ullah Bahar</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://askbahar.com/?p=48</guid>
		<description><![CDATA[<p>The easiest way to password-protect a site is to use HTTP Authentication, where if a browser’s request for a protected page is not accompanied by the correct username and password, the Web server replies with an HTTP 401 error – which means “Unauthorized Access” – and an invitation for the browser to re-submit the request [...]]]></description>
			<content:encoded><![CDATA[<p>The easiest way to password-protect a site is to use HTTP Authentication, where if a browser’s request for a protected page is not accompanied by the correct username and password, the Web server replies with an HTTP 401 error – which means “Unauthorized Access” – and an invitation for the browser to re-submit the request with a proper username and password. From the user’s point of view, most of this dialogue is hidden. Following that first failed request, the browser prompts the user (in a dialog box) for a username and password, and then re-submits the request, this time with the authentication information attached. Assuming the username/password combo is on the list of allowed users, the Web server then sends the page requested. The Web browser will likewise continue to send that username/password with all subsequent requests.</p>
<p>Look at the following code:<br />
<span id="more-48"></span></p>
<pre>
<code>
<?php
/*
    Document   : auth
    Created on : Nov 11, 2009, 9:08:32 AM
    @author    : Bahar
    Email      : bahar@progmaatic.com
    Copyright  : http://progmaatic.com

    Description: Authenticate user
*/

require_once 'settings.php';

$failure_msg = " <HTML>
 <HEAD><TITLE>Authorization Failed</TITLE></HEAD>
 <BODY>
 <H1>Authorization Failed</H1>
 <P>Without a valid username and password,
    access to this page cannot be granted.
    Please click 'reload' and enter a
    username and password when prompted.
 </P>
 </BODY>
 </HTML>";

if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER']!==$site_user || $_SERVER['PHP_AUTH_PW']!==$site_pass)
   {
       header("WWW-Authenticate: Basic realm=\"Protected Page: Enter your username and password for access.\"");
       header("HTTP/1.0 401 Unauthorized");
       exit($failure_msg);
   }

?>
</code>
</pre>
<p>For each page, you want to authenticate user, each page must have the above code. You can save this code to a script (for example <em>auth.php</em>) and include <em>auth.php</em> to any page, hence save yourself from rewriting the code for each page.</p>
]]></content:encoded>
			<wfw:commentRss>http://askbahar.com/2009/11/11/enable-apache-http-authentication-using-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

