PHP: Going around register_globals=off

PHP logoSince PHP 6, there will be no register_globals option, so you will not see output of form input directly as corresponding variables in PHP.
Also a lot of webhosting servers have register_globals turned off. How to get your form output without having to declare form variables at the beginning of every script? It is very simple.
All you have to do is put one line in the beginning of every script you want to see the variables automatically:

foreach($_POST as $variablename => $value) ${variablename} =$value;

This will transform variables from $_POST supervariable containing all form output in array into PHP variables. So if you had textfield named NAME in your form, so the script processing this form will see it as $name. Clean and easy.
I believe that this can help a lot.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Simple Ajax DIV change function

I wrote simple Ajax function which you can use to put result of ajax request to any named div on page.
You just include script ajax.js into head and than you can use function javascript getdata() wherever you want in document, all you need is to have named <div> areas, for example like this:
<a href=”#” onclick=”getdata(‘page_to_load‘,’where_to_put_it‘);”>Click here</a>

Here is the simple exmaple of usage (you’ll need file text.php for this, it should output just anything, which will be put into target DIVs):

<head>

<title>Ajax Demo</title>

<script type=”text/javascript” src=”ajax.js”></script>
</head>

<body>
<a href=”javscript:void(0);” onclick=”getdata(‘
text.php‘,’content1‘);”>Click here – put it in content box 1</a>
  
<a href=”javscript:void(0);” onclick=”getdata(‘text.php‘,’content2‘);”>Click here – put it in content box 2</a>

<div id=”content1” style=”border: 1px solid #cccccc;width:640px;height:240px;”>CONT1 </div>
<div id=”content2” style=”border: 1px solid #cccccc;width:640px;height:240px;”>CONT2 </div>
</body>

</html>

Ajax

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)