Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, June 29, 2009

Back and working with PHP/MySQL and some Javascript

Using one of those free hosting sites that allow PHP/MySQL - http://www.atbhost.com in particular - I've started working on php scripts. I've also found Javascript to be helpful.

Friday, April 27, 2007

test.php: There's long tags and then there's short tags.

This problem didn't take more than a few minutes to rectify and I'm thankful for that.

My test.php file consisted of the following code:
<? echo phpinfo() ?>
This is supposed to give you a volley of information about the PHP you just installed. Unfortunately when I tried to look at the file on localhost (http://localhost/test.php) it produced a blank window. I'm scratching my head thinking what did I do wrong?

After using Google (I can't say the term "googling" for fear that I'll mess with the giant's trademark. It's not good to say you "googled" something or "Xeroxed" a paper. They might lose money *rolls eyes* But seriously I like Google so I'll use the term "using Google" or "searching on Google") to search for
"GET /test.php HTTP/1.1" 200 20" "<? echo phpinfo() ?> "
I came up with only 6 hits that didn't answer the question as to why nothing was showing up. Then it hit me. Short tags.

The php.ini file has a variable that turns "short tags" on and off. Short tags are when you use . The ini file says it best:
; Allow the tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = Off
"short_open_tag" is the variable that is set to Off my default.
So all I had to do was replace <? with <?php and...
Voila!

PHP, The Eternal Struggle

I've always wanted to set up a dynamic site but whenever I tried to create a local server for testing I would fall flat on my face. For the last few weeks after browsing through the thousands of pages of the manuals for Apache 2.2, PHP, and MySQL 5.0 I tried to installing PHP to run on Apache.

The first snag I ran into (and I should have seen it at the beginning) was my attempt to install PHP 5.1 with Apache 2.2.

It turns out that PHP 5.1 does not have "php5apache2_2.dll" which is needed to run Apache as a module for enhanced security. After downloading PHP 5.2 and adding the lines
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"
I was finally able to start the Apache server without an error message. (c:/php was my choice of where I installed php. It might be different depending on where you unzipped your php file)

So I entered localhost and immediately became of forgetting a step. The Apache configuration file (httpd.conf) was still pointing at "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs" even though I had my root folder set up on the desktop. So I went into the file and found "DocumentRoot" where I promptly entered my desktop directory.

So I go to type in localhost and get the error message: 403 Forbidden You don't have permission to access / on this server. *frowns impatiently*

I go back into the httpd.conf file and scour through it line by line. Soon after DocumentRoot I encounter the problem:
# This should be changed to whatever you set DocumentRoot to.
#

About 26 lines after DocumentRoot it told me to change another line. So I pointed the directory to my desktop directory where all my files were located taking great care to use forward slashes (/) instead of backward slashes (\) and...

Htm files load perfectly but my test.php file comes up blank!