Why dont i get the desired output from this peice of code?

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
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Why dont i get the desired output from this peice of code?

Post by crazytopu »

<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>




<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>



when i input two value and hit my button i get the folloing output:

Hi

You like the word !?!

You oughta be ashamed of yourself!


Why doesnot it print my name and the word i type in my favorite field? why it looks like" !?! " ??
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Okay, chances are you have register globals off. If you do have them off, you will probably want to keep them off.

Try changing the following two fragments from this:

Code: Select all

<?php print $YourName; ?>

Code: Select all

<?php print $FavoriteWord; ?>
To this:

Code: Select all

<?php print $_POST['YourName']; ?>

Code: Select all

<?php print $_POST['FavoriteWord']; ?>
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Yah my global register is off. when i write the following code it gives me an output:

<?php
echo '<pre>';
echo 'PHP Version: '.phpversion()."\n";
echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
echo '</pre>';
?>

output:

PHP Version: 4.3.4
Display Errors: On
Error Level: Not E_ALL
Register Globals: Off

I just dont know what's the difference between leaving it off or on. How can i change its status - from off to on?



and thanks nigma. it worked when i used ur code.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

OOPS! I got my answer from the link given my nay. Thank nay.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Leave them off, they are a security risk when left on. It is not that difficult to learn to program without them and it is something you should definitely do.
Post Reply