Archive for the 'Scripting' Category

IE7 max tabindex problem #microsoft #fail

It took me an hour to debug some jquery in IE7. I was making a tab-navigation. When you click a tab it hides the content of the other tabs and shows the content of the clicked tab. Quite easy with jquery right? In all browsers except IE7 (I banned IE6 a long time ago..)

One of the tabs had a tabindex of 99999.
I added an alerts to display the value of tabindex attribute...
IE7 seems to have a max tabindex value of 16959!

Why? Only Bill Gates knows why....

No Comments »

IIS7 Impersonate PHP Fast-CGI as local user

The problem i had that i had to talk to a dll through COM on a windows server in PHP.
I needed to run the site as another user than the standard IURS.
I tried setting the identity of the application pool, no success.

Finaly i found the solution;

The (default) website advanced settings page has the option to specify the Physical Path Credentials.
I set this to a regular system account, and checked within PHP with:

echo get_current_user();

Everything worked!

No Comments »

SVN and Mac OSX hidden .DS_Store ._ .AppleDouble files

If you work on a mac (as i do) your directories get poluted with .DS_Store, ._ and .AppleDoubel files. Apple (this is THE missing Finder feature!) has no option to turn this crap off.
Now when you use svn, you will also import all these useless files.

Thank god there is a option in svn to globally ignore specific files.
Just edit the file:

~/subversion/config

Find the line global-ignores, uncomment it and make it something like this:

global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store .AppleDouble ._*

Whoot!

No Comments »

sprint_r PHP function

 
<?php
function sprint_r($v) {
	ob_start();
	print_r($v);
	return ob_get_clean();
}
?>
 

1 Comment »

Alternate PHP exec() function bypassing cmd.exe

I had a problem running executables (like identify.exe and convert.exe from ImageMagick) from php under windows using the exec() funciton. The solution provided by others was kind off stupid... Give full permisions on cmd.exe to IURS... Like you wanna do that.....
I wrote a exec() replacement function using the bypass_shell option proc_open has. It works great for me. Do your favour with it.

 
<?php
 
	function executeCommand($cmd) {
 
		if(DEBUG === true) {
			echo "Command: ".$cmd;
			echo "<br>";
			echo "Tempdir: ".TEMP_DIR;
			echo "<br>";
		}
 
		$descriptorspec = array(
		   0 => array("pipe", "r"),
		   1 => array("pipe", "w"),
		   2 => array("pipe", "w")
		);
 
		$process = proc_open(
				$cmd,
				$descriptorspec,
				$pipes,
				TEMP_DIR,
				NULL,
				array('bypass_shell' => TRUE)
		);
 
		if(!is_resource($process)) {
			return false;
		}
 
		if(!$pipes[1]) {
			if(DEBUG === true) {
				echo "No STDOUT<br>";
			}
			return false;
		}
		$output = stream_get_contents($pipes[1]);
		fclose($pipes[1]);
		$err = stream_get_contents($pipes[2]);
		fclose($pipes[2]);
 
		$x = proc_get_status($process);
 
		$return_value = proc_close($process);
 
		if($return_value == 0) {
			if(DEBUG === true) {
				echo "Return value {$return_value}<br>";
				print_r($x);
				echo "<br><br><br>";
			}
			return explode("\n", str_replace("\r", '', $output));
		} else {
			if(DEBUG === true) {
				echo "Return value {$return_value}<br>";
				print_r($x);
				echo "Output: ".$output;
				echo "Error: ".$err;
				echo "<br><br><br>";
			}
			return false;
		}
 
	}
?>
 

2 Comments »

ClamAV 0.94 not working anymore in MailScanner

I had this issue, clamav worked perfectly on command line, but within MailScanner it seemed to stop working. I could not find out why. I checked every configuration file, everything seemed normal.

Today i was upgrading ClamAV from 0.94 to 0.94.1, and suddenly i saw these lines in my maillog:


Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unzip
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --jar
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --tar
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --tgz
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --deb
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unrar
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --arj
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --lha
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unzoo
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --max-ratio
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unrar

Hmmmm.. weird. I started googling and found this bug:
https://wwws.clamav.net/bugzilla/show_bug.cgi?id=1213

They did this: Instead of hardfailing, clamd will print warnings.

Glad it is resolved now..

2 Comments »

Use your own HTML element attributes and make W3C validate correctly and make your browser display it like it should

Thanks to my College Joris (a.k.a. whizzrd) i wanted to make my website really Standards complient and not be satisfied with quirks mode but with standards mode.

Well, i did it, and this is how....

Make sure your page is served with Content-Type application/xml.
In PHP you can send this header:

header("Content-Type: application/xml");

Next on the top of your HTML you place this:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="copy.xsl"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[
<!ATTLIST td hoverimage CDATA #IMPLIED>
<!ATTLIST td normalimage CDATA #IMPLIED>
]>
<html xmlns="http://www.w3.org/1999/xhtml">

As you can see i defined two custom attributes for the td tag.
Now make sure you create a file named copy.xsl in your document root:
The file contains:

<stylesheet version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform">
<template match="/">
<copy-of select="."/>
</template>
</stylesheet>

IE should display your page like it should, but firefox has mysterious gaps when you use tables to make your layout (which you offcourse should not do to begin with ;)
Read this doc from mozilla dev to know all about why these gaps are there.

You can fix the gaps in FireFox by adding this style:

td img {
display: block;
}

Congratulations! You now have a w3c validating website in Standards mode.

You may have noticed your jQuery stuff is nog working anymore. In the Standards mode Mozilla does not generate implicit top-level JavaScript variable bindings for elements with the id or name attribute.
You can use your jquery stuff by not using the $ shortcut but calling jquery directly. See this example:

window.jQuery(document).ready(function() {
window.jQuery(".someelement a").hover(
function() {
//hover stuff },
function() {
//do other stuff
}
);
});

Well, thats it for now, hope you can enrich your life with this information and work on a unpoluted HTML world with me from today on.

Cheers..

No Comments »

Automatic frame redirect (cloaking) with apache and PHP

Sometimes a customer wants redirection using a frame. What you as an ISP don't want to do is make webspace and a index.html file for each customer handling this. You want this automated somehow.
This is how i did it.

First set up redirection with apache.

 
<VirtualHost *:80>
    ServerName www.whatever.com
    ServerAdmin admin@whatever.com
    DocumentRoot /usr/local/www/apache22/data
    SetEnv FRAMEREDIRECTURL "http://www.to-where-ever.com/blah/blah"
    ServerAlias *.whatever.com whatever.com
</VirtualHost>
 

As you can see we set a environment variable containing the URL you want to redirect to.
Next you will need some PHP to generate the frameset. Create this in the documentroot you specified in the virtual host.

 
<html>
<frameset rows="100%">
<frame src="<?php echo $_SERVER['FRAMEREDIRECTURL'] ?>">
</frameset>
<noframes>
<body>Please follow <a href="<?php echo $_SERVER['FRAMEREDIRECTURL'] ?>">link</a>.</body>
</noframes>
</html>
 

This is it. Use this info if you can.
Cheers

No Comments »

Check out my new StringSpeller PHP class

Ever wanted to spell for example a password?
Check out this project: http://www.bokko.nl/projects/php-stringspeller-class

No Comments »

Securely display email adresses on a website

To prevent your email address being spidered by some spammer you should never put your e-mail addresses on a website. I developed a PHP script that replaces found e-mail addresses by a secure version using jQuery.

See it in action here

Download the example script here: contentprotect.php

No Comments »

Next »