Boolean Island !

Entries from May 2008

Bangla Web App

May 20, 2008 · 5 Comments

Last day one of my friend came to me.He was facing a problem (he solved later).Here is his problem –
The Bangla/Unicode data become ?????? in his page.

I’m gonna tell u today step-by-step what u need to do if u wanna develop Bangla/Unicode based Web App.

#1 . First make the database with CHARACTER utf8 and collation_connection =’utf8_general_ci’
#2 . Make the Tables with same configuration.
#3 . When u connect the database use following 2 lines just below the mysql_select_db()

mysql_query(’SET CHARACTER SET utf8′);
mysql_query(”SET SESSION collation_connection =’utf8_general_ci’”);

#4 . Set the META-TAG as “Content-Type: text/html; charset=UTF-8″

Thats it :D u r done.Here is a sample page what will show data from database

<?
header(’Content-Type: text/html; charset=UTF-8′); //As its php page i dont need the meta-tag so i need to send a header .

mysql_connect(’localhost’,'xxxxx’,'xxxxxx’) or die(’Error In connection’);
mysql_select_db(’test’) or die(’Error In connection(DB)’);

mysql_query(’SET CHARACTER SET utf8′);
mysql_query(”SET SESSION collation_connection =’utf8_general_ci’”);

$re = mysql_query(”SELECT * FROM test”) or die(’Query Problem’);
while($row = @mysql_fetch_assoc($re))
echo $row['name'].PHP_EOL;
?>

Categories: Bangla computing · PHP · Tutorial · Web Developing · localization · mysql · programming
Tagged: , ,

phpMyAdmin বাংলায়

May 16, 2008 · 9 Comments

phpMyAdmin এর বাংলা ভার্সন রিলিজ হল । আমি ও জয় কাজটি করলাম । আমি অন্য কাজে ব্যাস্ত থাকায় বেশী সময় দিতে পারিনি । জয় বেশী সময় দিয়েছে । আজ phpMyAdmin থেকে মেইল পেলাম , ওরা ৩য় ভার্সন থেকে phpMyAdmin এর অন্যান্য ভাষার পাশাপাশি বাংলাকে ও রাখবে । কিন্তু যদি কেউ এখনি ব্যাবহার করতে চান তবে এখান থেকে ডউনলোড করতে পারেন । তবে সেটিং একটু ঝামেলার । প্রথমে ফাইলটি আনজিপ করুন bangla-utf-8.inc.php ফাইলটি কপি করে phpMyAdmin এর lang ফোল্ডারে পেষ্ট করুন । তারপর phpMyAdmin\libraries ফোল্ডারের select_lang.lib.php ফাইলটি এডিট করতে হবে । Azerbaijani ভাষার নীচে , নীচের লাইনটি যোগ করুন

‘bngla-utf-8′ => array(’bn|bangla’, ‘bangla-utf-8′, ‘bn’, ‘বাংলা’),

ব্যাস কাজ শেষ । এবার phpMyAdmin খুলে ভাষা হিসেবে বাংলাকে বাছাই করুন । :D

Categories: Bangla computing · localization
Tagged: ,

Automatically Update

May 14, 2008 · 1 Comment

Today one of my friend ask me how can he load the data automatically after a few secs . Let me make it clear.He want to do something which will help the user.The user dont have to refresh his/her page.It’ll refresh and update it self.

For this you need AJAX.Here is a little example of this.I used 3 files here.
#1 index.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Ajax Auto Update Example</title>
<script src=”AJAX.JS”></script>
<style type=”text/css”>
<!–
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
–>
</style>
</head>

<body onload=”show()”>
<table width=”561″ height=”174″ border=”0″ align=”center” cellpadding=”3″ cellspacing=”2″>
<tr>
<td height=”34″><div align=”center”><span class=”style1″>The Space Below will be update auto. </span></div></td>
</tr>
<tr>
<td><div id=”auto”></div></td>
</tr>
</table>
</body>
</html>

#2 ajax.js

var xmlHttp

function show()
{

//Show Loading Massage
document.getElementById(”auto”).innerHTML=”<h3 style=\”color:#FF0000\”>Loading……</h3>”;

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert (”Your browser does not support AJAX!”);
return;
}
var url=”show.php”;
xmlHttp.onreadystatechange=stateChanged;

//Get the value from show.php page.I use GET method here.You can use what u want GET/POST

xmlHttp.open(”GET”,url,true);
xmlHttp.send(null);

//This page will refresh it self after 2 sec.If u chage the value ‘2000′ the time will be changed .
setTimeout(’show()’,2000);

}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
//Below line show the server responce on the index.php page.
document.getElementById(”auto”).innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(”Msxml2.XMLHTTP”);
}
catch (e)
{
xmlHttp=new ActiveXObject(”Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}

#3 show.php

<?php

//If u use data from the database use necessery code here.I just show the current BD time in the page.

$am=’AM’;

$time = localtime();

$hour = $time[2]+6;

if($hour>=12)

$am=’PM’;

$hour%=12;

echo “<h3 style=\”color:#009900\”>Now Time is–$hour:$time[1]:$time[0]-$am</h3>”;

?>

Note : You can make ur site like www.gopsop.com and www.crickinfo.com.

Categories: AJAX · JavaScript · Web Developing · programming
Tagged: ,

Word Counter By PHP

May 6, 2008 · 1 Comment

I was reading Hasin Bhai’s New book Object Oriented Programming with PHP5.In chapter 2 i got a nice example of OOP.Its a word counter.Its a nice tool actually and pretty little too.Here is that example. :)

<?
class WordCounter
{
const ASC=1;  //you need not use $ sign before Constants
const DESC=2;
private $words;
function __construct($filename)
{
$file_content = file_get_contents($filename);
$this->words =
(array_count_values(str_word_count(strtolower
($file_content),1)));
}
public function count($order)
{
if ($order==self::ASC)
asort($this->words);
else if($order==self::DESC)
arsort($this->words);
foreach ($this->words as $key=>$val)
echo $key .” = “. $val.”<br/>”;
}
}
?>

Categories: PHP · programming
Tagged: ,

popup menu by CSS & JS

May 6, 2008 · 3 Comments

popup menus are very popular now a days.There are many software which helps us to create popup menus.Those software use a JavaScript file.But the main problem is its really tough to edit that JS file without that software.And one software doesn’t support another software’s files.So i was looking for some simple script which will helps me understand and what can i change when ever i want.Then i found a nice solution its based on CSS and javaScript.It is using visibility property.Here is an example.

<div id="MENU"
  style="position:relative; width:80px; text-align:center;
  background-color:#DC6000; color:#FFFFFF; cursor:hand"
    onmouseover="document.getElementById('ITEMS').style.visibility='visible'"
    onmouseout="document.getElementById('ITEMS').style.visibility='hidden'">
      Menu
</div>

<div id="ITEMS"
style="position:relative; visibility:hidden; width:80px; text-align:center;
background-color:#DEB887; color:#FFFFFF"
  onmouseover="this.style.visibility='visible'"
  onmouseout="this.style.visibility='hidden'">

  <div style="background-color:#DEB887"
    onmouseover="this.style.backgroundColor='#9D4602'"
    onmouseout="this.style.backgroundColor='#DEB887'"
    onclick="location='url'">
      Menu Item 1
  </div>
  <div style="background-color:#DEB887"
    onmouseover="this.style.backgroundColor='#9D4602'"
    onmouseout="this.style.backgroundColor='#DEB887'"
    onclick="location='url'">
      Menu Item 2
  </div>
  <div style="background-color:#DEB887"
    onmouseover="this.style.backgroundColor='#9D4602'"
    onmouseout="this.style.backgroundColor='#DEB887'"
    onclick="location='url'">
      Menu Item 3
  </div>

</div>

<p>Other page content...</p>

Just copy and paste the code inside a HTML file and watch :).

Categories: CSS · JavaScript · Web Developing
Tagged: , , ,

SubVersion on Windows XP

May 4, 2008 · 3 Comments

Version controlling is very important now.Almost all the developers (web app/desktop) have to know it.Subversion is software which helps us in version controlling.Who dont know what is Subversion please read this.

BTW i was looking a short and nice tutorial on subversion .But i didnt got any :( . Then Aman Bhai helps me to start with svn . Here is the mail he sent me as a tutorial ..

Lets start from the beginning.

First you need a repository. What is it… practically its a folder on a pc that subversion (svn now on) uses as the database. This
database manages version information. (skipping user/security, svn uses file system or dbms backend, default is fs).
Now if you want to enable versioning with svn you must have to import that project folder into a repository.

After importing a project folder into a repository, you MUST checkout (download ) it from that repository. It may sound weird. But think of a remote
user, at least s/he has to checkout the project first right ? and you are nothing but a user to svn :)

so, lets come back to using tortoise. If you want to checkout a project from a remote site, say a google code hosted project. you just right click on the folder where you want to checkout. select tortoisesvn->import. Copy the svn url from the browser and paste to URL of repository: field. click ok, you will find the project is downloading… and done. :) now, modify any source and right click and select svn commit. Dont forget to svn update first before any commit.

now,. say you are not going to use any remote project. rather you like to use svn as your local versioning. in that case you frirst create a folder that you want to use the repository. say, you created a folder named REPO. right click on the folder and select TortoiseSVN->Create repository here… an option will appear. select Native filesystem (FSFS). done… you have created a repository successfully.

Now, right click on the project folder that you want to maintain versioning and select TortoiseSVN->import. click on the … button and select your repository folder i.e. REPO folder you have just created. say, it is like file://D:/REPO, now enter as file://D:/REPO/myproject.
Thus you can use same repo for multiple projects.
দেখবে যে তোমার প্রোজক্ট ইম্পোর্ট হয়ে গেছে under myproject folder in the REPO repository.

now, comes the funny part, YOU HAVE TO CHECKOUT THIS PROJECT AGAIN :).
Create a folder name it …say… Workspace. Now enter into the folder.
right click.
TortoiseSVN->Repo browser
select your REPO folder.
You will find myproject folder in the tree.
select it.

now, checkout. :)

Note : This is using TortoiseSVN .

Categories: Subversion · Tutorial
Tagged: , , ,

mod re_write Example

May 1, 2008 · No Comments

Few days ago i was thinking how can i rewrite the url ? Then i ask phpxperts and they replay me that mod re_write can do that work.Then i was looking for some mod re_write example.And got a nice one.Here it is I’m shearing with u all.

so, what is mod_rewrite for?

Simply, mod_rewrite is used for rewriting a URL at the server level, giving the user output for that final page. So, for example, a user may ask for http://www.somesite.com/widgets/blue/, but will really be given http://www.somesite.com/widgets.php?colour=blue by the server. Of course, the user will be none the wiser to this little bit of chicanery. .

What do I need to get mod_rewrite working?

There’s pretty much only one thing you’ll need to get mod_rewrite working for you, and that’s to have the mod_rewrite module installed on your Apache server!

For the purpose of this article, I’m going to assume that you don’t have access to view or edit the Apache server httpd.conf file, so the easiest way to check whether the mod_rewrite module is installed will be to look on your phpinfo page. If you’ve not already created one of these for yourself, just copy and paste the following code into an new text file using your favourite text editor, save it as phpinfo.php, and upload it to your server:

<?php phpinfo(); ?>

Load that page up in your web browser, and perform a search for “mod_rewrite”. All being well, you’ll find it in the “Apache loaded modules” section of the page. If it isn’t there, you’ll have to contact your hosting company and politely ask them to add it to the Apache configuration.

Assuming the mod_rewrite module is loaded, then you’re good to go!

A simple mod_rewrite example

So, let’s write a simple mod_rewrite example. This isn’t going to be anything fancy; we’re just going to redirect people who ask for alice.html to the page bob.html instead. First, let’s create the Alice and Bob pages. Below is Alice’s webpage - create a similar one for Bob.

<html>
   <head>
      <title>Alice's webpage</title>
   </head>
   <body>
      <p>
         This is Alice's webpage
      </p>
   </body>
</html>

Upload both of these to your web server, and check that you can view both of them. Now comes the fun - we’re going to add a couple of lines to your .htaccess file. The .htaccess file is a text file which contains Apache directives. Any directives which you place in it will apply to the directory which the .htaccess file sits in, and any below it. To ours, we’re going to add the following:

RewriteEngine on
RewriteRule ^alice.html$ bob.html

Upload this .htaccess file to the same directory as alice.html and bob.html, and reload Alice’s page. You should see Bob’s page being displayed, but Alice’s URL. If you still see Alice’s page being displayed, then check you’ve followed the instructions correctly (you may have to clear your cache). If things still aren’t working for you, then contact your technical support people and ask them to enable mod_rewrite and the FileInfo override in their httpd.conf file for you

The structure of a RewriteRule

RewriteRule Pattern Substitution [OptionalFlags]

The general structure of a RewriteRule is fairly simple if you already understand regular expressions. This article isn’t intended to be a tutorial about regular expressions though - there are already plenty of those available. RewriteRules are broken up as follows:

RewriteRule

This is just the name of the command.

Pattern

A regular expression which will be applied to the “current” URL. If any RewriteRules have already been performed on the requested URL, then that changed URL will be the current URL.

Substitution

Substitution occurs in the same way as it does in Perl, PHP, etc.

You can include backreferences and server variable names (%{VARNAME}) in the substitution. Backreferences to this RewriteRule should be written as $N, whereas backreferences to the previous RewriteCond should be written as %N.

A special substitution is -. This substitution tells Apache to not perform any substitution. I personally find that this is useful when using the F or G flags (see below), but there are other uses as well.

OptionalFlags

This is the only part of the RewriteRule which isn’t mandatory. Any flags which you use should be surrounded in square brackets, and comma separated. The flags which I find to be most useful are:

· F - Forbidden. The user will receive a 403 error.

· L - Last Rule. No more rules will be proccessed if this one was successful.

· R[=code] - Redirect. The user’s web browser will be visibly redirected to the substituted URL. If you use this flag, you must prefix the substitution with http://www.somesite.com/, thus making it into a true URL. If no code is given, then a HTTP reponse of 302 (temporarily moved) is sent.

A full list of flags is given in the Apache mod_rewrite manual.

A slightly more complicated mod_rewrite example

Let’s try a slightly more meaty example now. Suppose you have a web page which takes a parameter. This parameter tells the page how to be displayed, and what content to pull into it. Humans don’t tend to like remembering the additional syntax of query strings for URLs, and neither do search engines. Both sets of people seem to much prefer a straight URL, with no extra bits tacked onto the end.

In our example, you’ve created a main index page with takes a page parameter. So, a link like index.php?page=software would take you to a software page, while a link to index.php?page=interests would take you to an interests page. What we’ll do with mod_rewrite is to silently redirect users from page/software/ to index.php?page=software etc.

The following is what needs to go into your .htaccess file to accomplish that:

RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

Let’s walk through that RewriteRule, and work out exactly what’s going on:

^page/

Sees whether the requested page starts with page/. If it doesn’t, this rule will be ignored.

([^/.]+)

Here, the enclosing brackets signify that anything that is matched will be remembered by the RewriteRule. Inside the brackets, it says “I’d like one or more characters that aren’t a forward slash or a period, please”. Whatever is found here will be captured and remembered.

/?$

Makes sure that the only thing that is found after what was just matched is a possible forward slash, and nothing else. If anything else is found, then this RewriteRule will be ignored.

index.php?page=$1

The actual page which will be loaded by Apache. $1 is magically replaced with the text which was captured previously.

[L]

Tells Apache to not process any more RewriteRules if this one was successful.

Let’s write a quick page to test that this is working. The following test script will simply echo the name of the page you asked for to the screen, so that you can check that the RewriteRule is working.

<html>
   <head>
      <title>Second mod_rewrite example</title>
   </head>
   <body>
      <p>
         The requested page was:
         <?php echo $_GET['page']; ?>
      </p>
   </body>

RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(www\.)?somesite.com/.*$ [NC]RewriteRule \.(gif|jpg|png)$ http://www.somesite.com/nasty.gif [R,L]

</html>

Again, upload both the index.php page, and the .htaccess file to the same directory. Then, test it! If you put the page in http://www.somesite.com/mime_test/, then try requesting http://www.somesite.com/mime_test/page/software. The URL in your browser window will show the name of the page which you requested, but the content of the page will be created by the index.php script! This technique can obviously be extended to pass multiple query strings to a page - all you’re limited by is your imagination.

Conditional Statements and mod_rewrite

But what happens when you start getting people hotlinking to your images (or other files)? Hot linking is the act of including an image, media file, etc from someone else’s server in one of your own pages as if it were your own. Obviously, as a webmaster, there are plenty of times when you don’t want people doing that. You’ll almost certainly have seen examples where someone has linked to one image on a website, only for a completely different, “nasty” one to be shown instead. So, how is this done?

It’s pretty simple really. All it takes are a couple of RewriteCond statements in your .htaccess file.

RewriteCond statements are as they sound - conditional statements for RewriteRules. The basic format for a RewriteCond is RewriteCond test_string cond_pattern. For our purpose, we will set the test_string to be the HTTP_REFERER. If the test string is neither empty nor our own server, then we will serve an alternative (low bandwidth) image, which tells the person who is hotlinking off for stealing our bandwidth.

Here’s how we do that:

Here, the RewriteRule will only be performed if all the preceeding RewriteConds are fulfilled. In the second RewriteCond, [NC] simply means “No Case”, so it doesn’t matter whether the domain name was written in upper case, lower case or a mixture of the two. So, any requests for gif, jpg or png files from referers other than somesite.com will result in your “nasty” image being shown instead.

The [R,L] in the RewriteRule simply means “Redirect, Last”. So, the RewriteRule will visibly redirect output to “nasty.gif” and no more RewriteRules will be performed on this URL.

If you simply don’t want the hot linkers to see any image at all when they hot link to your images, then simply change the final line to RewriteRule \.(gif|jpg|png)$ - [F]. The - means “don’t rewrite the requested URL”, and the [F] means “Forbidden”. So, the hot linker will get a “403 Forbidden message”, and you don’t end up wasting your bandwidth.

Note : This is the original link .

Categories: Apache
Tagged: , , ,