There are softwares already that helps to replace a string in a file. Suppose, if you’re making a program that requires saving some data in to a file. By “adding”, the program is actually replacing a word. Let’s see how it’s done in PHP & Python. This is the file where we are going to replace the word : thisWord I got thisWord for making it thatWord replace thisWord already my friend.... [READ MORE]
Posts marked with "PHP" in categories
Folder Recursion in PHP & Python
A folder has files and sometimes sub directories. If we use the normal function for obtaining contents of a folder, we won’t get the details of the files in the sub directories. In this case, we have to look over into the sub folders and into other sub folders within this sub folder. This looking up of files deep down is called Recursive Folder Searching. By doing this, we can search for a file or do various actions with each files thus recursed.... [READ MORE]
Word Palindrome Check in PHP & Python
Palindromes are unique words that are read the same forward and backward. We can identify them using out eyes and brain. How about we identify using a simple program in PHP & Python ? PHP <?php $word = strtolower("Malayalam"); $splitted = str_split($word); $reversedWord = ""; $length = strlen($word); for($i = 0; $i < $length; $i++) $reversedWord .= $splitted[$length - $i - 1]; echo $word == $reversedWord ? "It's a palindrome !... [READ MORE]
Executing Terminal Commands in Python & PHP
Python & PHP are great languages and there are many similarities between them. In this short post, you will learn how to execute terminal commands in PHP & Python. PHP As I said before many times in other posts, there areexec andsystem command to execute commands : exec("firefox ‘http://subinsb.com’"); Or in the other way : system("firefox ‘http://subinsb.com’"); Python In Python, there is no exec or system function. But there is a system function in the os nodule.... [READ MORE]
Infinite loop in PHP & Python
Infinite loops are loops that doesn’t have a defined ending. It will continue to run until the program it’s running in is terminated. Normally an infinite loop is created using while loop and is used for continuity of the same program. In this short tutorial, you will learn how to make an infinite loop in both PHP & Python. PHP There is no need of defining any variables. while(1){ print "... [READ MORE]
Blocking Brute Force in PHP Website
Brute Force is a time consuming cracking process to log in to a user’s account of a web site. It’s not common and requires very high resources including the most important factor : TIME. What’s Brute Force Suppose, your email website have an account of username “abel”. His big enemy who is a nerd, wants to send rubbish stuff to Abel’s friends to make his friends angry. Your site is heavily protected except for Brute Force and the enemy is willing to give as much time to log in to Abel’s account.... [READ MORE]
Accessing /var/log Files in PHP
If you have tried to access a log file in /var/log using PHP in Linux, you will see the “Permission denied” error. This is because, Apache doesn’t have read permission on the log file. Let’s look at the user groups that have permission to access the log files : it’s root and the program which created the file. Suppose, let’s say the log file is “/var/log/squid/access.log”. That file’s group and owner will be “proxy” and others won’t even have the read permission on it except **root **ofcourse.... [READ MORE]
Finding Exact Document Root in PHP
You might know the DOCUMENT_ROOT value of the $_SERVER array. This value indicates the absolute location of the site directory where pages are served. In short, it’s the public folder of site as defined in the server’s configuration. Here’s a quick example : If you have a site in /home/me/site and can access it by http://site.dev, then the $_SERVER[‘DOCUMENT_ROOT’] is “/home/me/site”. If any page in the server, even if it is in many sub folders, the DOCUMENT_ROOT value will be the same.... [READ MORE]
Create Live Group Chat With PHP, jQuery & WebSocket
With the introduction of HTML5, a new technology was evolved in 2011 called WebSockets. This technology enables live connection with the server even after the page finished loading. It’s a better, replaceable version of AJAX for client to server communication in the background. With WebSocket technology, its possible to have a direct communication between server and client without any interruption and faster data transmission. So, to demonstrate this to me and for you, We’re going to create a live group chat with PHP, jQuery with the help of WebSockets.... [READ MORE]
Animated AJAX Login Form With jQuery
The Web is growing rapidly. Each day, new features are arriving. With the coming of AJAX, many websites became more easy to handle. With jQuery, websites became more attractive with animations and styles. In this tutorial, we are going to create a stylish animated Login Form with jQuery, CSS & AJAX. With this, the login time for the user is greatly reduced as the page shouldn’t be loader all over again.... [READ MORE]