Page 1 of 1

newbie: testing locally on mac 10.2: syntax?

Posted: Sat Mar 15, 2003 5:21 pm
by davek
I am just starting to learn php.
On a Mac with 10.2.4 using dreamweaver mx.

I am doing a tutorial from webmonkey:
http://hotwired.lycos.com/webmonkey/01/ ... rogramming

What i dont understand is why this code works on my live site, but not on my localhost?

Code: Select all

<html> 
<head> 
<title>My Form</title> 
</head> 
<body> 
<form action="bad_words.php" method="post"> 
My name is:
<br> <input type="text" name="YourName"> 
<p> My favorite dirty word is: 
<br> <input type="text" name="FavoriteWord"> 
<p>
<input type="submit" name="submit" value="Enter My Data!">
</form>
</body>
</html>

Code: Select all

<html>
<head>
<title>Perv!</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>
Hi <?php print $YourName; ?>
<p>
You like the word <b> <?php print $FavoriteWord; ?> !?! </b>
<p>You oughta be ashamed of yourself!
</body>
</html>
The above works on my live site, but not locally the variables are empty.

And the following works on both, local and live.
Is this the preferred syntax?
Am I getting ahead of myself, will the answer be more clear as I learn more of the basics?

Code: Select all

<html>
<head>
<title>Perv!</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>
Hi <?php print "$_POST&#1111;YourName]";?>
<p>
You like the word <b> <?php print "$_POST&#1111;FavoriteWord]";?> !?! </b>
<p>You oughta be ashamed of yourself!
</body>
</html>
Thanks.

Posted: Sat Mar 15, 2003 5:40 pm
by m3mn0n
Maybe try to trim the data as it comes in.

Code: Select all

<?
$Name = trim($YourName);
$Word = trim($FavoriteWord);
?>
<html> 
<head> 
<title>Perv!</title> 
</head> 
<body bgcolor="#FFFFFF" text="#000000"> 
<p> 
Hi <? echo "$Name"; ?> 
<p> 
You like the word <b> <? echo "$Word"; ?> !?! </b> 
<p>You oughta be ashamed of yourself! 
</body> 
</html>
For more info visit http://www.php.net/trim

Posted: Sat Mar 15, 2003 7:57 pm
by McGruff
I think you've got register globals off on your local server, and register globals on at the web server.

Register globals off is more secure (you still need to do some user input checking though). Many shared hosting servers will have register globals on however, in order to be more compatible with older code.

It's probably best to assume register globals is off when you are writing code: your scripts will still work on a server with register globals on, but if you code assuming register globals is on, scripts might not work on a server with register globals off.

phpinfo() will show current php settings.

Posted: Sun Mar 16, 2003 5:36 am
by twigletmac
Check out:
viewtopic.php?t=511

Mac

Posted: Mon Mar 17, 2003 7:49 am
by davek
Thanks very much.