PHP Tips: Difference between revisions

From EggeWiki
No edit summary
Line 1: Line 1:
== Problems with mod_security ==
== Problems with mod_security ==


Recently, I've been plauged with problem trying to add code examples to my wiki.  It seems that if I include anything that remotely looks like a command, the Apache mod_security returns the error:
Recently, I've been plagued with problem trying to add code examples to my wiki.  It seems that if I include anything that remotely looks like a command, the Apache mod_security returns the error:
  406 Not Acceptable: An appropriate representation of the requested resource wikimedia/index.php could not be found on this server
  406 Not Acceptable: An appropriate representation of the requested resource wikimedia/index.php could not be found on this server


I found the solution on [http://community.mybboard.net/showthread.php?tid=7592 this message board], which basically is to add <code>SecFilterEngine Off</code> to the .htaccess file in my wikimedia folder.
I found the solution on [http://community.mybboard.net/showthread.php?tid=7592 this message board], which basically is to add <code>SecFilterEngine Off</code> to the .htaccess file in my wikimedia folder.


== Regex testers ==
== Regex testers ==

Revision as of 11:02, 1 June 2006

Problems with mod_security

Recently, I've been plagued with problem trying to add code examples to my wiki. It seems that if I include anything that remotely looks like a command, the Apache mod_security returns the error:

406 Not Acceptable: An appropriate representation of the requested resource wikimedia/index.php could not be found on this server

I found the solution on this message board, which basically is to add SecFilterEngine Off to the .htaccess file in my wikimedia folder.

Regex testers

Developing your regex online seems to be the easiest way. Here are a couple of online testers

Increase upload max from 2M default

First, you'll want to see what your default settings are. I created a small file 'phpinfo.php' to show me the settings:

<?php
phpinfo();
?>

Next, I edited the .htaccess in the directory with the upload script to look like this: <verbatim> php_value post_max_size 33554432 php_value upload_max_filesize 33554432 </verbatim>

Finally, I verified the change with the 'phpinfo.php' page.

Show php source code

This works on many linux setups. Any file with a .phps will be shown as it's PHP source, will HTML coloring. The easy way to add this is to create a symlink like this:

ln -s rss.php rss.phps

Displaying XML

Today I set out to create an XML RSS feed in PHP. I quickly found some examples, and without too much trouble I was getting my feed to validate on http://feedvalidator.org. The difficult part for me was getting the xml file to render as XML in Internet Explorer 6.0.

Here's what my page was looking like:

Here's what I want it to look like:

I knew I needed to include the Content-Type in the header:

<?php
header('Content-Type: text/xml');
echo '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'."\n";
?>

This didn't help any. My xml looked the same. My site is hosted on Apache/Linux, so I started trying to figure out how .htaccess works and MIME types. I tried creating my own .htaccess file and putting ~AddType into it. This didn't work either. So I decided to copy the .htaccess file from my tikiwiki app. Following this my xml fixed itself. Unfortunately, this was not caused by the .htacess file. The reason is I tried my query in a new window. When there were errors in my XML, it would get sent as plain text. Internet Explorer was caching this content type, and not changing when I would refresh the page.