Page 1 of 1

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

Posted: Sun Jan 04, 2004 1:52 am
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" !?! " ??

Posted: Sun Jan 04, 2004 2:01 am
by Nay

Posted: Sun Jan 04, 2004 2:01 am
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']; ?>

Posted: Sun Jan 04, 2004 2:36 am
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.

Posted: Sun Jan 04, 2004 2:39 am
by crazytopu
OOPS! I got my answer from the link given my nay. Thank nay.

Posted: Sun Jan 04, 2004 2:40 am
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.