Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
DIRNAME (php 4.3.0)

Posted by Garrie (Garrie), 6 February 2003
I have just installed PHP 4.3.0 and a script that was working under 4.2.3 no longer works.

The original code was this
Code:
       $location ="http://"
                 .$_SERVER['HTTP_HOST']
                 .dirname($_SERVER['PHP_SELF'])
                 .'/cms.php';
       header('Location: '.$location);

which resulted in $location containing
http://127.0.0.1.cms.php
and the message
No input file specified. being displayed.
($location should contain http://127.0.0.1/cms/cms.php).

I changed the code to
Code:
       $location ="http://"
                 .$_SERVER['HTTP_HOST']
                 .'/'.dirname($_SERVER['PHP_SELF'])
                 .'/cms.php';
       header('Location: '.$location);

so $location now contains http://127.0.0.1/./cms.php, but the HEADER command still returns the same message.

Can anyone explain what's going wrong?

I am running PHP on Windows 2000 with BadBlue 2.1 (http://www.badblue.com) as a local webserver.

Posted by admin (Graham Ellis), 6 February 2003
Educated guess - you should use SCRIPT_NAME rather than
PHP_SELF for the name of the script.  Would need to check through all the docs, but PHP_SELF has always stuck me as a strange variable ....

Posted by Garrie (Garrie), 6 February 2003
I tried SCRIPT_NAME - same result
I have reverted to 4.2.3 for the moment.
- Garrie

Posted by admin (Graham Ellis), 8 February 2003
Always looking to be at the (b)leeding edge, I have just installed Apache 2, and PHP 4.3.0 onto one of our systems running XP Pro with the recommended service pack also installed ....

dirname and PHP_SELF look fine:

Code:
<body>
<h1>Test for Garrie</h1>
The PHP_SELF is
<?php print ($_SERVER{'PHP_SELF'}); ?>
<br> and its dirname is
<?php print (dirname($_SERVER{'PHP_SELF'})); ?>
</body>


gave me

Quote:
Test for Garrie
The PHP_SELF is /trainee/garrie.php4
and its dirname is /trainee


Hmmm ... afraid your problem looks like it's the server or O/S or some sort of combination.

The following is a test program I use to look at all environment variables, for variables, etc, on a system; looked OK on my new combination, but you might like to try it and look for any funnies if you still have 4.3.0 around

Code:
<head><title>My Environment Reported</title></head>
<body bgcolor=white>

<?php
reporton($_ENV,"Your Environment");
reporton($_POST,"Your POST data");
reporton($_GET,"Your GET data");
reporton($_COOKIE,"Your Cookie information");
reporton($_SERVER,"Your Server information");
?>

<br><table width=90%><tr><td width=50%><center>

First form - using POST<br><table border=1><form method=post>
<tr><td>name</td><td><input name=who></td></tr>
<tr><td>code</td><td><input name=pass type=password></td></tr>
<tr><td>radio</td><td><input type=radio name=gender value=M> Male<br>
<input type=radio name=gender value=F> Female</td></tr>
<input type=hidden name=hide value=hugesecret>
<tr><td> </td><td><input type=submit></td></tr></form></table>

</center></td><td><center>

Second form - using GET<br><table border=1><form>
<tr><td>name</td><td><input name=person></td></tr>
<tr><td>radio</td><td><input type=radio name=gender value=M> Male<br>
<input type=radio name=gender value=F> Female</td></tr>
<input type=hidden name=hide value=canbeseen>
<tr><td> </td><td><input type=submit></td></tr></form></table>

</center></td></tr></table><br>

<?php
reportall($_ENV,"Your Environment");
reportall($_POST,"Your POST data");
reportall($_GET,"Your GET data");
reportall($_COOKIE,"Your Cookie information");
reportall($_SERVER,"Your Server information");
?>
</body>

<?php
function reporton($array,$describe) {
     print ("$describe contains ".count($array)." values <br>");
     }
function reportall($array,$describe) {
     if (count($array) > 0) {
           print ("$describe contains ".count($array)." values <br>");
           print ("<table border=1>");
           array_walk($array,"tabline");
           print ("</table><br>");
           }
     }
function tabline($value, $key) {
     print ("<tr><td>");
     print (htmlspecialchars($key));
     print ("</td><td>");
     print (htmlspecialchars($value));
     print ("</td></tr>");
     }
?>




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho