PHP Script Not Working – Solution

by Hiroshi on September 29, 2009

in Post & Get

Ever wondered that most of the PHP scripts you download, do not do anything. I mean you downloaded the PHP script, uploaded at your host or copied at localhost and when you run it, it will not display results. In most cases it happens. One reason might be that the script is not properly written. But the fact is, scripts are written correctly in most cases. The problem is that the developers miss something very important in most cases. Next time you download scripts, those should run if you follow this instruction I am going to tell you.

Some PHP developers write code with Globals On.

Left click wamp icon -> config files -> php.ini

When its open, search for register_globals

These must be Off by default e.g.
register_globals = Off

Many developers were used to program in environment of On Globals. This makes programming easier but this method is vulnerable and security risk. You do not have to get variables which you post at the new page where PHP does something in case of Globals On. Sometimes developers still do the same thing.

This is not recommended.

Globals should be off in PHP.ini and scripts should work while Globals are off.

So the reason is obvious. Many scripts you download, you will see do not get variables when these are posted. Those are programmed in environment of Globals On (Easy way PHP Coding).

Next time you download a script and if that is not working, check that Variables are being requested after when these are posted or not.

What to Do

Suppose someone posts a form with his name and email with variables txtName and txtEmail which are text input names. txtName and txtEmail should be requested at the next PHP page. If these are not being called, then you will get Null result which will be empty.

Request these variables in the following manner at the next page at the top of everything where PHP code starts. In case of above example:

$txtName=$_REQUEST["txtName"];
$txtEmail=$_REQUEST["txtEmail"];

Now $txtName contains the name of user and $txtEmail contains the email and you can use these further. When some PHP script is not working, always see that if these variables are being requested by this manner at the next page? If not you can get every variable like this and the script will be working in most cases. You can also use $_Post instead of $_REQUEST.

Another reason is not using proper PHP starting tag.

Wrong Tag

<?

Correct Usage of PHP Tag

<?php

Some servers will output errors if you do not use proper PHP starting tag.

Also read Post and Get if this is not clear.

Related Posts

Previous post:

Next post: