Saturday, 30 March 2013

Denying access to a particular folder on your web server

Suppose you have a directory in your web server which contains sensitive files like files containing database connection passwords , app-secret id's for using 3rd party services etc . You want to block access to that particular folder . So how are you going to do it ? Well it's pretty simple . Just add a .htaccess file to that folder . Open it up , and add the following lines :-

Order deny,allow
deny from all

This will deny access to any files in that folder . Remember that all those files in the folder can be accessed only if you add a require , include directive in a file on the server-side . However ajax calls or any sort of client request won't work on the files of that directory .

Friday, 29 March 2013

PHP Tutorial . Chapter 5 . PHP Control Statements ( Part 2 - Loops 1 (For Loop) )

While writing your code , you might encounter situations when you might want to execute the same set of statements over and over again . PHP like other programming languages implements this in the form of loops . There are three types of looping constructs commonly used in php - for , while , foreach . The last one is usually used for resources , associative arrays .

1) For Loop

The following piece of code illustrates the use of a for loop .

for($i=1 ; $i<=10 ; $i++)
       echo $i."<b/>";

The above code will print 1 to 10 on different lines . So how does this work ? First we assign $i = 1 . Then when the loop executes each time , the condition $i<=10 . The statements inside the looping construct are executed only if this condition is true . Then the value of the variable i is incremented .

The given code can also be written as the following . It is an example of a loop where no statements are within the control statement itself . We assign the variable out of the loop and also the conditions are checked for and the variable is incremented inside the loop .

echo $i++."<br/>";

The only thing that may sound unfamiliar to guys who are new to programming is the break statement . Whenever a break statement is encountered , the loop is terminated then and there . There is also something called continue , which is the opposite of break , continue ends the loop over there and starts a new loop .

Saturday, 23 March 2013

Off the grid ...

Hello guys :) I am posting after a long time , it may be yet another couple of weeks until i can get back to blogging regularly , owing to exams/competitions etc etc . Please bear with me :) I Promise to be back with nice tutes and awesome hacks !! Till then cya :) Bye !!