Friday, December 19, 2008

openSUSE 11.1 Released

openSUSE 11.1 is released yesterday. I am just downloading now.

Download details link is here:
Link

So download which best suites your system and you.

Have a lot of fun.

ANL

Saturday, December 13, 2008

404 Error customize it for your own site

As, i discussed mod_rewrite in the previous post,that how to enable and use it.
As we know, that some time users input wrong URL, or miss some thing from URL. So that time Apache redirect them to 404 error stating that page not found on this server.
Now the good and very easy way to remove such error and show your users a valid and fine tuned page, Apache give us a opportunity to rewrite that page.

So now you can show a page to users, with some good contents to not lose that user.
Create a .htaccess file and write the following there:

ErrorDocument 404 http://site.com/404error.html

You can change your paths. Now you have a page 404error.html(you can create it in any language PHP etc). Now write whatever you want in 404error.html and show that to user. Save it and place it in the root directory of your site. You can dress up 404error.html to make sure that user will come back or click any link there to your site. OR you can provide search area there. OR any nice page with nice graphics and contents and telling them, that the thing they are looking for can be found in HOME page and give a link to home page. Its all up to you that how you make this page.
I was just giving some tips.

ANL

Thursday, December 11, 2008

Hide .php from users to make your url more friendly

I have written an article named "How to rewrite URL in apache".
Today i am sharing with my readers and PHP programmers.
First of all we will check that either mod_rewrite in apache load modules is enabled or NOT.
In Linux openSUSE:
By default, openSUSE doesn't enable the mod_rewrite rewrite module. It's installed, but not enabled.
So lets enable it,
1. Edit the file /etc/sysconfig/apache2 as root:
i. search for APACHE_MODULES, you should find a line like this
APACHE_MODULES="suexec access actions alias auth auth_dbm autoindex cgi dir env expire include log_config mime negotiation setenvif userdir ssl php5"
ii. Add 'rewrite'(without quotes) to the content in the list between the "".
iii. Save the changes and quit
2. run SuSEconfig to update the apache configuration files.(From terminal)
3. run /etc/init.d/apache2 restart to restart the Apache server.(From terminal)
To check either mod_rewrite is enabled or not. phpinfo();, write in editor, save it in the root directory and open it in browser.
Search for word "mode_rewrite"(without quotes). If you find it, it mean rewrite is enabled. if not, then check the steps again and try.

Now you have to do some tweaking of default-server.conf file.
1. Edit the file /etc/apache2/default-server.conf with your prefered editor.
i. Search for AllowOverride - it should be below the line Directory "/srv/www/htdocs"
ii. Change AllowOverride None to AllowOverride All - this will allow custom .htaccess rewrite rules.
iii. Save your changes and exit
2. run SuSEconfig to update the apache configuration files.
3. run /etc/init.d/apache2 restart to restart the Apache server.

Now every thing is fine and running, lets test it. that it is working or not.
Create a directory with any name, i create mod_rewrite, open editor and write the following code there.

if($_GET['link']==1){echo"You are not using mod_rewrite";}
elseif($_GET['link']==2){echo"Congratulations!! Your Apache mod_rewrite test is successful";}
else{echo"Linux Apache mod_rewrite Test";}

//make it url as by href method.
"rewrite.php?link=1"LINK1 = rewrite.php?link=1
"link2.html"LINK2 = link2.html

save it as rewrite.php

Now write:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]

and save it as .htaccess in the same directory.
Open rewrite.php in browser and click on link1, and then on link2. If you see the message "Congratulations!! Your Apache mod_rewrite test is successful", means that, its working.

In WINDOWS:
How to enable mod_rewrite module in apache in xampp, wamp?

1) Find the “httpd.conf” file under the “conf” folder inside the Apache’s installation folder.
2) Find the following line “#LoadModule rewrite_module modules/mod_rewrite.so” in the “httpd.conf” file.You can do this easily by searching the keyword “mod_rewrite” from find menu.
3) Remove the “#” at the starting of the line, “#” represents that line is commented.
4) Now restart the apache server.
5) You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”.



The rest of the testing is same as above.

ANL

Thursday, December 4, 2008

Round function

A simple post to show how to use round function in PHP.

Lets take a variable holding a number with decimals:
$number = 21.25116;

Now want to round this number to 3 decimal.
So:
$number = round($number,3);
echo $number;
The result will be something like: 21.251

If $number = 21.2569
then result will be: 21.257

If $number = 21.259652;
Then result will be: 21.26

ANL