Password protect your directory without .htaccess

.htaccess is generally used for basic authentication of a folder/website. The data of users logging in using .htaccess is not stored or kept. It works untill the user’s browser remembers the credentials.  And it would really be very difficult to keep track of users logging in using this method.

So, here is a very simple way of doing the same using HTTP authentication:

<?php
$myusername
= “amanjain.com”;
$mypassword = “amanjain”;

/*The authentication technique can be different like using database or a key value pair file*/
if (
$_SERVER["PHP_AUTH_USER"] == “” || $_SERVER["PHP_AUTH_PW"] == “” ||$_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword)
{

header(“HTTP/1.0 401 Unauthorized”);
header(“WWW-Authenticate: Basic realm=\”This is my protected area\”"); /*Replace  ”This is my protected area” with your personal message*/
echo
“<h1>Authorization Required For Accessing Content.</h1>”;/*If user cancels the authentication*/
die();

}

?>

That’s it. Simple right?

Check out PHPCamp.net a article sharing website relevant to our own PHP community

Taking screenshot of a website using PHP on windows os

I have been trying to figure out a way using I could take a screenshot of any provided URL using PHP.
Finally I could find out a way of doing it and that is by using the COM object on windows os.

I have written a class for taking the screenshot.
For using it, all you need to do is:

Download the class file from here.
Rename it and remove the .txt entention
Include the class file in the required script.
And then,
Create a new object:

$s = new akjScreenshot(”http://amanjain.com”);

Resize if required:

$s->toWidth(100);
$s->toHeight(100);

Save:

$s->save(”screen.jpg”);

You can also save it in different formats like:

$s->save(”screen.png”, “png”);
$s->save(”screen.gif”, “gif”);

I hope it helps :) Please leave a comment if you find it useful.

Check out PHPCamp.net a article sharing website relevant to our own PHP community