Wednesday, October 6, 2010

>> Run Registry Editor From Guest Account Even If It Is Blocked >> Learn To Create Your Own PHP Page Hit Counter

Run Registry Editor From Guest Account Even If It Is Blocked

Posted: 29 Jun 2010 12:38 PM PDT

Registry editor is well known registration directory where windows keep all the records of their setting files. Keeping it inaccessible from other users is extremely necessary in the point of view of security of data and information. Wherever you are, public cyber cafes, Library, College labs, etc you’ll see that you cannot access the heart utilities like Registry Editor.

The Regedit.exe is only the executable file to list up registries in systematically. You can arrange the registry’s easily by your own if you are a good programmer. But who is talking about programming here? I am talking about the program which is alternative for registry editor, RegAlyzer. This works exactly similar to Windows’ registry editor, only the difference is it’s name and it’s third-party.

This tool might be great help if you want to have instant hack to public computers and networks.


You can easily Download RegAlyzer from here.

Hope you liked this info.

Learn To Create Your Own PHP Page Hit Counter

Posted: 29 Jun 2010 06:32 AM PDT

Today, I will show you how you can use php’s file handling functions to create a web site page visit counter.
The script that we are going to create will open a file when called and read the value of the file then increment the value by one and then write that value to the file. We’re going to put the actual code inside a function so that way you can call the script on your page with only one line of code.

Now let’s begin. In order to open a text file in php, we need to call the function fopen(). This will open the file, if it exists, and return a file pointer. Instead of using the file name, you pass a file pointer to functions. Here is the beginning of our code:

In the above script, we declared a function by using the keyword function followed by the name of our function. Next, we used fopen() passing the name of a file in the same directory as the script where the page visits data will be stored as the first parameter; we then passed the second parameter r+, this tells the server that we want to open the hit.txt file for reading and writing. For more details about text file handling parameters, please review my previous tutorial about PHP and txt file interaction.
We must create a blank text file named as hit.txt in the directory where the current script is situated.
fopen() can take one more parameter: 1. If you pass the third parameter as 1, the file you passed the name of in the first parameter will be searched for in the include path. We store the result of fopen() in a variable named $file_pointer. If the file does not exist, fopen() will return false. Therefore we’ll need hit.txt initially.

if ($file_pointer == false)
{
return "Error:File not found or could not be opened!";
exit;
}

Now since file is opened, we’ll need to read the file, to do so, we’ll use function fread().

$hit= fread($file_pointer, filesize("hit.txt"));

The syntax for fread is (file open, filesize). To get the file open we’ll be using $file_pointer string and to get the size of the file we use the filesize(“filename.txt”) function. Now the contents of the file are stored in a variable with the name $hit. We will use the trim() function to strip any whitespace from the beginning and ending of the string.

$hit= trim($hit);

Trim will remove all the blank white spaces if exists, this will be helpful to maintain the file size and unexpected results. Now we have read the contents of the file into a variable and trimed up the variable, we will increase it’s value by 1 per hit, and write it back into the file. Before we write to the file, we need to go back to the begining of the file so we can write over the current count. We do this by using fseek().

$his++;
fseek($file_pointer, 0);
$result= fwrite($file_pointer, $hit);
if ($result == false)
{
return "Error: could unable to write file!";
exit;
}
else {
return $hit;
}

We use the increment operator (++) to add 1 to the hit count, then we use fwrite() function to write to the file. We then pass the file pointer and the hit count to fwrite(). If it returns false, the it will show error message. Lastly, we return the value of $hit, which holds the hit count.
Now we’ll need to close the file after reading and writing it. To do that we use fclose() and pass it the file pointer, and also we’ll add some error checking.

$close= fclose($file_pointer);
if ($close == false)
{
return "Error: could not close the file!";
exit;
}

And that’s all, we’re done! Here is the complete script for a hit counter:

function count_hit()

{

$file_pointer= fopen("hits.txt", "r+");

if ($file_pointer == false)

{

return "Error: could not open the file! It may not exist!";

exit;

}

$hits= fread($file_pointer, filesize("hits.txt"));

$hits= trim($hits);

$hits++;

fseek($file_pointer, 0);

$result= fwrite($file_pointer, $hits);

if ($result == false)

{

return "Error: could not write to the file!";

exit;

}

else {

return $hits;

}

$close= fclose($file_pointer);

if ($close == false)

{

echo "Error: could not close the file!";

exit;

}

}

?>

Now to display the hit on a webpage by adding following code snippet:

< ? php count_hit(); ?>

Hope you like the post :)


No comments:

Post a Comment