PHP - Turn register globals on off using htaccess

Posted by Vijay on June 5th, 2009

Problem:

My application is hosted on a server where php has register_globals set to on in php.ini. But using register_globals = on makes code error prone and is dangerous to use.
I want to turn it of for my application regardless of what is its setting for other applications.
Since the value of register_globals cannot be set at run time bu using ini_set, how can I do it?

Solution:

Use htaccess file to control this behaviour. Create a file named .htaccess in root directory of your application and write the following line in it:

php_flag register_globals off

Thats all you need to do.

You can verify this by creating a phpinfo() file. Suppose your server has register_globals set to on and you have turned it off using above syntax.

phpinfo() will show the local value as off and master value as on.

Note: Of course, this will work only if your apache configuration allows to override htaccess settings.

Share this post on :
  • StumbleUpon
  • LinkedIn
  • Digg
  • del.icio.us
  • Technorati
  • Facebook
  • Google
  • Reddit
  • MySpace
  • Sphinn
  • Mixx
  • Furl
  • Live
  • Pownce
  • Spurl
  • TwitThis

Technorati Tags:

FAQ: How to fix error 403: access forbidden for phpmyadmin in wampserver?

Posted by Vijay on May 26th, 2009

The Problem:

PhpMyadmin works fine on localhost but accessing it over a network gives error 403: Access Forbidden.

Reason:

Reason is pretty clear - phpmyadmin is not configured to be accessed over a network. Permission to access it over network is not given.

Solution:

Locate the file phpmyadmin.conf in your wamp installation. If you have wampserver version 2 or higher, this file can be found at C:\wamp\alias\phpmyadmin.conf (Of course assuming that you installed wamp in C:\wamp). For earlier wamp versions this file is at C:\wamp\Apache2\conf\alias\phpmyadmin.conf.
Once found,open this file. Contents of the file will be like the following:

Alias /phpmyadmin "c:/wamp/apps/phpmyadmin3.1.3.1/"
# to give access to phpmyadmin from outside
# replace the lines
#
#        Order Deny,Allow
#	Deny from all
#	Allow from 127.0.0.1
#
# by
#
#        Order Allow,Deny
#   Allow from all
#
 
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Deny,Allow
	Deny from all
	Allow from 127.0.0.1

As it is clearly written in the file itself, replace the line Deny from all (second line from the bottom )with Allow from all. Save the file, restart apache and you are done.

PhpMyadmin can be accessed from outside now.

Share this post on :
  • StumbleUpon
  • LinkedIn
  • Digg
  • del.icio.us
  • Technorati
  • Facebook
  • Google
  • Reddit
  • MySpace
  • Sphinn
  • Mixx
  • Furl
  • Live
  • Pownce
  • Spurl
  • TwitThis

Changing font size on a page with javascript for better user experience

Posted by Vijay on April 2nd, 2009

Today we will learn to add a simple functionality to web pages. Visitors on a web page will be able to increase or reduce the font size of text as per their choice. This is an example of how javascript can be used for enhancing user experience. If anyone is having a problem with small font size, he should have an option to make it readable. I have seen this feature on many sites and if you ask me, I think all sites should provide this feature.

It happens that sometimes the font size on a page is so small that its unreadable and sometimes annoyingly large. Agree that browsers provide the feature to increase or reduce font size of a page, how many actually know it?

Lets create an example in which user will be able to increase/reduce font-size at his will.

See the example in action HERE. If you want to have a look at source code, you can always do so by doing view source on your browser.

Create a html page with the following markup:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html>
	<head>
		<script></script>
	</head>
<body>
<p>
	<a href="javascript:void(0);" onclick="changeFontSize('content','2');">Increase font</a>
	&nbsp;&nbsp;
	<a href="javascript:void(0);" onclick="changeFontSize('content',-2);">Decrease font</a>
</p>
<p id="content" style="font-size:12px;">
	My name is Sherlock Holmes. It is my business to know what other people don't know.
</p>
</body>
</html>

This page contains a p tag with id set to content with some text inside it. Note that the font-size property has been set for content as 12px inline.

Above are 2 hyperlinks, one for increase font and other for reducing it. Both of them call a javascript function changeFontSize() when it is clicked. changeFontSize() accepts 2 parameters. First is the id of the container for which you wish to increase/decrease font. Second one is by how much you wish to increase or decrease it.
For increasing font I have passed 2 to it, and for the decrease font button the value is -2. Each time any of the links is clicked, it will increase or reduce the font size by 2px. Change this value to what suits you.

Now we will add the definitions for changeFontSize(). Insert the following code between script tags in the head of your html page.

1
2
3
4
5
6
7
function changeFontSize(element,step)
{
	step = parseInt(step,10);
	var el = document.getElementById(element);
	var curFont = parseInt(el.style.fontSize,10);
	el.style.fontSize = (curFont+step) + 'px';
}

In fact, you can squeeze above 4 lines into a single line:

1
2
3
4
function changeFont(element,step)
{
	document.getElementById(element).style.fontSize = (parseInt(document.getElementById(element).style.fontSize,10)+parseInt(step,10)) + 'px';
}

Use whichever you prefer.

Now you are done. Refresh the page and click on Increase Font/Decrease Font links.Font size will change accordingly.

How does this happen actually?

Line 3: First convert step as an integer
Line 4: Then use javascript function getElementById to get the html element.
Line 5: Then use the style property to get the font size that has been set for the element. element.style.fontSize will give us 10px. Pass it to function parseInt to get an integer value - 12 in this case.
Line 6: Finally reset the fontSize property for the element by adding the value of step.

Simple :)

There may be other methods/variations also by which you can control the font size. For example, create a combo box with values for font size as smaller,small,medium,large and largest.Each value of combo box will have a specific font size associated with it say 8px,10px,12px,14px and 16px respectively. Onchange event will set the font size according to selected value.

Thats all. Hope you enjoyed the post.

For more information on changing the styles/css of html elements by javascript you can read my previous post.

Share this post on :
  • StumbleUpon
  • LinkedIn
  • Digg
  • del.icio.us
  • Technorati
  • Facebook
  • Google
  • Reddit
  • MySpace
  • Sphinn
  • Mixx
  • Furl
  • Live
  • Pownce
  • Spurl
  • TwitThis

Technorati Tags:

Bookmarklet For TinyURL and Flickr Search

Posted by Vijay on April 1st, 2009

Bookmarklets have become common over the internet nowadays. They are helpful too. Bookmarklets are like small tools for specific purposes.

They are relatively new things for me. But I found them pretty useful.

Wiktionary defines bookmarklets as “A small piece of JavaScript code stored as a URL within a bookmark.”
Users can drag this piece of code onto their browser toolbars. After that bookmarklet is ready to use. Just click on it from the toolbar when you are on a webpage.

Bookmarklets are supposed to do one click functions. I thought why not create some. Though I created several to experiment, only 2 of those are worth sharing(At least I think so). Others perform weird functions like disabling css of a page, making all images on the page invisible etc etc. If you want code for these also, just drop a message below.

Here is the first one that searches flickr for any term you select on any web page. If you do not select any text, it will prompt you for keyword.(Nonsense??? I know that). Slight modification can make it google search or dictionary search or whatever search you wish.

Search Flickr

The second one is slightly more useful.
Just click it and it will create tinyURL of that page you are visiting. You can then post it to twitter or share with friends(Cool, isn’t it).

Create TinyURL


Why wait now, Drag these to your browsers toolbar and have fun.

Give this  article a Thumbs-up on Stumbleupon if you liked it.

Share this post on :
  • StumbleUpon
  • LinkedIn
  • Digg
  • del.icio.us
  • Technorati
  • Facebook
  • Google
  • Reddit
  • MySpace
  • Sphinn
  • Mixx
  • Furl
  • Live
  • Pownce
  • Spurl
  • TwitThis

Technorati Tags: ,

My funny mail collection

Posted by Vijay on March 31st, 2009

Some time ago, just for fun I started to collect all funny and crazy mails that friends sent to me. Later I thought of putting them into a single place. I sat down to code and in a couple of hours created  http://www.vijayjoshi.org/humour/.

This page displays all the content that I have collected till now with the name of friend who sent it to me. (Some of them are insisting me to remove their names (read Bhuwanesh) which I will not do ;) . I keep on updating it as I get new mails from friends.
Click on the story title to see the contents.
Yesterday I added one more feature to it. Now you can comment on individual stories as well. So please add your funny/crazy comments. Planning to add a recaptcha to comments soon as there will be lots of spam too.

Also, I request all of you reading this to send lots of crazy stuff to be included in the collection.

Share this post on :
  • StumbleUpon
  • LinkedIn
  • Digg
  • del.icio.us
  • Technorati
  • Facebook
  • Google
  • Reddit
  • MySpace
  • Sphinn
  • Mixx
  • Furl
  • Live
  • Pownce
  • Spurl
  • TwitThis

Technorati Tags: , ,


Copyright © 2007 vijayjoshi.org. All rights reserved.
3,621 spam comments
blocked by
Akismet