Quick way to update code that reads ‘session_is_registered(‘foo’) to isset($_SESSION['foo']) for PHP5 usage:
In vi type:
:%s/session_is_registered(\"\([a-zA-Z]*\"\))/\isset($_SESSION\[\'\1\'\])/
May 20, 2011
Updating _SESSION variables from old PHP v4 script
December 22, 2010
Porting PHP4 to PHP5 Gotcha
Came across a little “gotcha” porting a site from PHP 4.4.4 to version 5
if($a == $b)
{
$x = new whateverObject(); // note that this object may or may not get instantiated
}
.....
$x->doSomething(); // this will cause "Fatal error: Call to a member function doSomething() on a non-object
...
How this ever worked in PHP4, I don’t know… might have to check into what happens there.
November 9, 2010
PHP Variable as Array name (variable variablenames)
To use a PHP variable as a name for an array:
$theArray = array("a","b","c");
$variableReference = "theArray"; // Note: no []
echo ${$variableReference}[0]; // outputs just like $theArray[0] - ie: "a"
Note that this is generally a bad idea, as it makes code brutally hard to read and debug, but it is handy sometimes.
August 29, 2010
Fade-in popup window example in Javascript
Source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <script type="text/javascript">// <![CDATA[ // Browser safe opacity handling function function setOpacity( divid, value ) { document.getElementById( divid ).style.opacity = value / 10; document.getElementById( divid ).style.filter = 'alpha(opacity=' + value * 10 + ')'; } function fadeInMyPopup( divid ) { for( var i = 0 ; i <= 100 ; i++ ) setTimeout( 'setOpacity("' + divid + '", ' + (i / 10) + ')' , 8 * i ); } function fadeOutPopup( divid ) { for( var i = 0 ; i <= 100 ; i++ ) { setTimeout( 'setOpacity("' + divid + '", ' + (10 - i / 10) + ')' , 8 * i ); } setTimeout('closeMyPopup( divid )', 800 ); } function closeMyPopup( divid ) { document.getElementById( divid ).style.display = "none"; } function launchMyPopup( divid ) { setOpacity( divid, 0 ); document.getElementById( divid ).style.display = "block"; fadeInMyPopup( divid ); } // ]]></script> <div id="popup1" style="width: 380px; height: 300px; display: none; position: absolute; top: 130px; left: 80px;"> <table border="0" cellspacing="0" cellpadding="0" width="380"> <tbody> <tr> <td><img src="/images/menubar_bg.png" alt="" width="356" height="23" /></td> <td><a href="javascript:fadeOutPopup("popup1");"><img src="/images/window-close.png" border="0" alt="" width="24" height="23" /></a></td> </tr> <tr> <td style="padding: 5px 10px; vertical-align: text-top; background: url(/images/popup_body.png) no-repeat scroll left top transparent; width: 380px; height: 277px;" colspan="2"> This is a test of the emergency pop up system. If this were an actual emergency, you'd have been trampled. :-)</td> </tr> </tbody> </table> </div> <input onclick="launchMyPopup('popup1')" type="submit" value=" Launch Popup1! " /> |
You can have multiple popups on one page simply by changing the DIV id and setting the calls to fadeInPopup() and launchMyPopup() accordingly.
August 9, 2010
Fixing “Warning: file_get_contents()” php error
I recently got the following error on a newly installed webserver:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/localhost/htdocs/wordpress/wp-content/plugins/statsurfer/statsurfer.php on line 3543
This happened to me after activating StatsSurfer for this blog, and that big ugly error would appear at the top of every page.
Thankfully, the fix is quite easy (strangely hard to google for though), in your php.ini file (mine’s at /etc/php/apache2-php5/php.ini – other *nix variants will be similar), just change the following line in the php.ini file from:
allow_url_fopen = Off
To:
allow_url_fopen = On
I recently got the following error on a newly installed webserver:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/localhost/htdocs/wordpress/wp-content/plugins/statsurfer/statsurfer.php on line 3543
This happened to me after activating StatsSurfer for this blog, and that big ugly error would appear at the top of every page.
Thankfully, the fix is quite easy (strangely hard to google for though), in your php.ini file (mine’s at /etc/php/apache2-php5/php.ini – other *nix variants will be similar), just change the following line in the php.ini file from:
allow_url_fopen = Off
To:
allow_url_fopen = On
Restart Apache, and off you go.

Like