Solved

Undefined variable: PHP_SELF in PHP4.0 on Win2000 server

Posted on 2002-06-05
9
431 Views
Last Modified: 2008-03-17
I have a code:
<?php
$hostname="sonpham.24mbnet.com";
$username="root";
$database="SE";
$ma = isset ($ma)? $ma:'';
$tien = isset($tien)?$tien:0;
$cmd= isset ($cmd)? $cmd:'';
$myConnect=mysql_connect($hostname,$username);
if (!$myConnect) {$msgErr = "Can not Connect to MySQL Server<Br>\t\t".mysql_error() ."<Br><Br>\n";     print $msgErr;}
mysql_select_db($database,$myConnect);
switch ($cmd) {
     case 'OK':
          $laygio = getdate();
          $thoigian= $laygio["hours"].":".$laygio["minutes"].":".$laygio["seconds"];
          mysql_query("insert into thanhvien(MAuser)values('$ma')") or die( 'Khong nhap duoc'.  mysql_error());
          $ttx=($tien-$tien)/$tien;
          mysql_query("insert into tk_tienvao(MAuser,Thoigian,Tienvao,tiensudung,tx)values('$ma','$thoigian','$tien','$tien','$ttx')") or die( 'Khong nhap duoc'.  mysql_error());
          break;
    default:
}
     $result=mysql_query("select * from tk_tienvao");
     $recc=mysql_num_rows($result)+1;
     print "<HTML>";
     print "<BODY leftmargin=30 bgColor='#CCCCFF' onLoad='moveTo(80,250)'><br><br>";
     print "<CENTER><FORM method='POST' name='me' action=".$PHP_SELF.">";
     print "<TABLE border=1 bordercolor='#0000FF' bgColor='#330066' width='100%' style='color:#FFFF00' align=center>";  
     print "<TR width='100%' align=center><TD style='font-family:Times New Roman;font-size:14;color:#FFCCFF' colspan=2>S&#7889; l&#432;&#7907;ng ng&#432;&#7901;i m&#7903; tài kho&#7843;n là:<b style='color:#FFFF00'>".($recc-1)."</B></TD></TR>";
     print "<TR width='100%' align=center>";
     print"          <TD colspan=2 width='100%' style='color:#00FF00;font-weight:bold;font-size:20px'>CREATE NEW ACCOUNT</TD></TR><TR align=center><TD style='font-size:15px;color:#FFFF00;font-weight:bold'>USERNAME</TD>";
     print "     <TD><INPUT type='text' name='ma' value='QSE'></TD></TR><TR align=center><TD style='font-size:15px;color:#FFFF00;font-weight:bold'>CASH</TD>          <TD><INPUT TYPE='text' NAME='tien' value='100000'></TD></TR><TR align=center><TD style='font-size:15px;color:#FFFF00;font-weight:bold' Colspan=2><INPUT TYPE='submit' value='OK' name='cmd' style='cursor:hand'>&nbsp;&nbsp;&nbsp;<INPUT type='Reset' value='Reset' style='cursor:hand'>&nbsp;&nbsp;&nbsp;<INPUT type='button' value='Exit' onClick='window.close()' style='cursor:hand'></TD></TR></TABLE></FORM></CENTER></BODY></HTML>";
mysql_close();
?>
 But when run then the browse show: Notice: Undefined variable: PHP_SELF in D:\php&mysql\QSE_SON\Qse\data\nao.php on line 25
 I still run well on Win98se or WinNT but not run on Win2000. Can you help me? I'am very need! Thank You very much!

0
Comment
Question by:rosepaint
9 Comments
 
LVL 40

Accepted Solution

by:
RQuadling earned 50 total points
Comment Utility
If you are using V4.2 (I think), then $PHP_SELF is now $_SERVER["PHP_SELF"]

Regards,

Richard.
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Also, if this code is in a function, you MAY have to use the globals array.

But as of V4.2 (I think), all that has more or less gone. You use $_SERVER, $_POST, $_GET, $_COOKIE instead. They are always global too.

Regards,

Richard.
0
 
LVL 5

Expert Comment

by:dkjariwala
Comment Utility
All those $_SERVER, $_POST etc. are SUPER GLOBAL.  You can access from the functions without declaring them global.

JD
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Assisted Solution

by:onestar
onestar earned 50 total points
Comment Utility
If you are using us 4.21 there are some changes that I have made to scripts that seem to be making them work better.


First of all when posting to self this is the best way

if($_POST['form_submitted'] == 1)
{
     //do something ....
}
else
{
     //display form
     <form method="post" action="<?=$PHP_SELF?>">
     <input type="hidden" name="form_submitted" value="1">
}

You should send a hidden field and check that.
This will make sure if the user hits enter or clicks the submit button or hits enter on the submit buttom it will always work. You should never just do if($submit) I have found cases where it doesn't work.

Another thing you should always use
if (isset($category_id))
not just
if ($category_id)


Another HUGE issue is now they are trying to faze-out register_globals.

If you have writen your scripts the old way without using SUPER GLOBALS you need changed your php.ini to register_globals = On
or change all your scripts to use SUPER GLOBALS

This was the default setting in older versions of php.

//This is the part of the php.ini file 4.21
; You should do your best to write your scripts so that they do not require
; register_globals to be on;  Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = Off
// **** Change to "On" *****


Hope this helps
Onestar



0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
I like that form submitter idea! Very clever.
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Also, something that may help with those repeated print statements.

Instead of ...

print "a whole load of text";
print "and";
print "some";
print "more";
...

try

print <<< _END_
a whole load of text
and
some more
_END_;



This is from the PHP manual ...

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

/* More complex example, with variables. */
class foo
{
    var $foo;
    var $bar;

    function foo()
    {
        $this->foo = 'Foo';
        $this->bar = array('Bar1', 'Bar2', 'Bar3');
    }
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>


Regards,
Richard.
0
 
LVL 11

Expert Comment

by:shmert
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
SPLIT: rquadling, onestar
Please leave any comments here within the next seven days.
               
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
               
Sam Barnum
EE Cleanup Volunteer              
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now