Hello,
I recently downloaded a freebie php ticketing system to see how it worked and what I could do make it suit my needs... I installed php 4.1.1 for windows/apache/mysql. Everything went great until I tried to get this freebie working. Well - I realized that the primary reason it wasn't working (amongst other reasons) was because of register_globals not being on. Then I read the following announcement:
http://www.php.net/release_4_1_0.php
Holy smokes. After reading this I felt like all the php I have written in the last couple years has been written incorrectly - at least, that is, I have been taking for granted global variables. I've always been able to pass a form to a processing php page and access the form variables without having to initialize them or anything. Tisk tisk to me, I guess. However, every tutorial or book I have ever read has encouraged me to expect that I can use a form input on one page named "username" as $username on the reult page, INCLUDING on the OFFICIAL php site...
http://www.php.net/tut.php
Anyway, in hopes of doing things the right way, can someone give me a basic example of a form that submits to itself without assuming register_globals is on? Or - tell me what's wrong with the following example...
<?php
if (isset($_POST["username"])) {
$username = $_POST["username"];
echo "Hello, ".$username;
} else {
?>
<form action="thisfile.php" method="POST">
<input type="text" name="username">
<input type="submit" value="Go!">
<?
}
?>
Should I define my variables at the top of every page like the above so I will still have access to the value of the post @ "$username"?
Someone provide some sanity here.
Thanks,
Steve