Navigate/Search

Archive for the 'PHP' Category

PHP Namespaces – Use not Import, huh?

Wednesday, February 11th, 2009

Not sure how pertinent this is (update) as I’ve never ran across any of these “gotchas.” All it really talks about is a bit of syntax and the fact ‘import’ was changed to ‘use.’  *shrugs*

I ran across it while trying to remember what the name of namespaces were in PHP — yeah, I know, crazy.  Did I mention my memory is kaput?

See my massive about page to see what I mean.  And believe every word of it.

Useful PHP class for debug output

Wednesday, February 11th, 2009

JASLabs has a useful little class for iterating object properties, as well as all GET and POST variables.  The comments yield another useful tidbit.

If you are using Firefox, LiveHTTPHeaders is a useful tool. It’ll show you your GET and POST, as well as all HTTP request/response headers, for every request your browser makes.

Using this, you can also sneak debugging output into your headers (thereby preventing it from affecting your HTML rendering) by doing something like this:

$key = "MyObject";
$message = serialize(get_object_vars($myobj));
header("X-Debug-$key: $message");

ImageFlow script causes a 503 error – here’s the fix?

Tuesday, February 10th, 2009

And now I’m battling a 503 error due to mod_security.

mod_security: Access denied with code 503. Error normalising REQUEST_URI: Invalid character detected

This link from the Menalto Gallery forums was dead-on my exact problem (experience-wise) and then it derailed into something totally unrelated.  This link from the LiteSpeed Support Forums I thought would be of help in regards to making sure PHP had enough memory and it had enough time to execute.

I’m still struggling trying to figure out what part of the “reflectionN.php” causes problems.

Here’s one straight from the boards of my host, DreamHost.

It’s actually the one that got me thinking.  I re-examined the support documentation and the examples and finally found the problem.

Well, sort of…

If I use:

reflectionGET: '&height=20%'

…nothing appears at all on my Linux host —– Windows host is fine.

If I use:

reflectionGET: '&height=20'

…it starts working, but not in a way I can figure out.  Plus it seems to greatly affect the height and position of the image.

I looked in the code and saw that the part that handles the “height” value is setup to strip a percent symbol (%) if it comes with one, but the other ‘reflectionGET’ values do not strip the percent symbol.

So for whatever reason that particular aspect is wonky.

  • fade_start
  • fade_end
  • height

Those are the values that behave differently and erratically between my Windows and Linux hosts.

Escaping PHP to Markup and a thought

Sunday, February 8th, 2009

An example of escaping in and out of PHP in an HTML document.

<?php if (1 === 2) : ?>
<!-- if/Markup -->
<p>One</p>
<?php elseif (2 === 1) : ?>
<!-- elseif/Markup -->
<p>Two</p>
<?php else : ?>
<!-- else/Markup -->
<p>I have no clue!</p>
<?php endif; ?>

On that same note I believe you should parse all HTML documents that contain PHP as PHP — with some caution of course. Target specific directories for this behavior. Even better would be to handle it via mod_rewrite — that is, for example, interpret:

/index.htm

…as:

/index.php?category=news&default=true&frontPage=true

This opens up many possibilities without having to apply additional overhead to the PHP engine.

Random code-by’s, code blitherings and whatnot

Sunday, February 8th, 2009

I wasn’t sure what to call this one but this site has a random array of varied goodies in CSS, PHP, HTTP and IE-specific problems.

phpMyChat to the rescue?

Saturday, February 7th, 2009

I hope to offer a little gratis live help from time to time and this seems to be my best solution for now as apparently the AVChat guys are full of it.

Here’s the tutorial page for phpMyChat.  Oh, and a FAQ.

Enumerations in PHP, um, OK

Tuesday, January 27th, 2009

I always find it interesting to see what geeks with too much time on their hands get into.

http://www.jeremyjohnstone.com/blog/archives/2008/10/05/enums-in-php/#more-383

http://it.toolbox.com/blogs/macsploitation/enums-in-php-a-native-implementation-25228

Be wary of isset() when testing server/header variables/responses

Thursday, January 22nd, 2009

For example:

if (isset($_GET)) print 'This is always fired because a browser uses GET.';

if (isset($_SERVER['QUERY_STRING']) print 'This also always fires because a Query String always exists with a length of 0 unless an actual query is made.';

It is much better to use:

if (isset($_GET['key'])) print $_GET['key']; // value

if (strlen($_SERVER['QUERY_STRING']) > 0) print $_SERVER['QUERY_STRING'];

Fatal error: Class ‘ZipArchive’ not found in

Friday, January 16th, 2009

It just so happens that the majority of PHP problems dealing with new technology are related to not enabling their extension and then turning them on in your php.ini file.

For example:

; turns on ZIP streams
zlib.output_compression = On

; notice it simply lacks “;” in front denoting a non-comment
extension=php_zip.dll

So basically it reads:

a) enable ZIP
b) make sure ZIP is available

Yeah, whatever, it works as intended so…