Solved

Undefined variable: PHP_SELF in PHP4.0 on Win2000 server

Posted on 2002-06-05
9
432 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
ID: 7055774
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
ID: 7055813
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
ID: 7056066
All those $_SERVER, $_POST etc. are SUPER GLOBAL.  You can access from the functions without declaring them global.

JD
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Assisted Solution

by:onestar
onestar earned 50 total points
ID: 7056498
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
ID: 7056680
I like that form submitter idea! Very clever.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 7056717
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
ID: 9643358
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 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

21 Experts available now in Live!

Get 1:1 Help Now