newbie: testing locally on mac 10.2: syntax?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davek
Forum Newbie
Posts: 12
Joined: Sat Mar 15, 2003 5:21 pm
Location: chicago

newbie: testing locally on mac 10.2: syntax?

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Check out:
viewtopic.php?t=511

Mac
davek
Forum Newbie
Posts: 12
Joined: Sat Mar 15, 2003 5:21 pm
Location: chicago

Post by davek »

Thanks very much.
Post Reply