Archive for the ‘PHP’ Category

Here is a code to detect weather the visitor if your webpage is using ie or not:

1
2
3
4
5
6
7
8
if (isset($_SERVER['HTTP_USER_AGENT']) && 
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) 
	{
	echo "You are using ie";
	}  
	else { 
	echo "You are not using ie"; 
	}

I am using this simple PHP code while developing HybridPass, a new authentication tool for web applications. My Javascript is only compatible with ie at the moment, so until I develop it more to support other browsers it is important to give my visitors the right feedback.

array_rand can be used to select a list of values randomly. This helped me to code a server side script to display a random grid of pictures as part of a project. These pictures changes every time the page is requested or refreshed.

Read the rest of this entry »

Charset Problem

The image above is showing part of a small hack I coded for a phpBB board to show topics from selected sections. Those question marks were suppose to be Arabic letters, but after a recent update to phpBB the hack failed to use the board config file to connect so I had to set up my own direct connection to the DB.

The connection was fine, but I got “?????” instead of something I can read in Arabic. After some tests I figured out, though the MySQL DB is using UTF-8 as a character set, which means it can handle the language efficiently, I had to set the character set to UTF-8 via PHP for every query using the following code:

1
mysql_query("SET CHARACTER SET utf8");

What is even better is setting the character set at once with a single line of code for the whole connection by using the following code:

Read the rest of this entry »

Haider’s WebSpace
Welcome to my technical blog. This is where I write, archive and share computer related articles. Subjects vary from posting technical solutions to researching particular topics. Feel free to comment and talk IT!
Sponsored Links
My Tweets
Posts Calendar
February 2012
M T W T F S S
« Nov    
 12345
6789101112
13141516171819
20212223242526
272829