You are here: Re: Newbie Question on !isset() « PHP Programming Language « IT news, forums, messages
Re: Newbie Question on !isset()

Posted by LHO on 06/28/05 08:40

Thank you for your help. Now the script works.

Here is some questions about the change.
1) To set the register_globals to 'ON', I edited the PHP.INI file.
Is there other way to set the register_globals 'ON'? Maybe, only for this
program.

2) Is the $posted predefined variable?

3) Is $_POST['serialized_data'] the same as
$HTTP_POST_VARS['serialized_data']? $HTTP_POST_VARS is for earlier PHP
engine.

Thank you again.

Lawrence


"Ken Robinson" <kenrbnsn@rbnsn.com> wrote in message
news:1119926809.181163.254740@g43g2000cwa.googlegroups.com...
> LHO wrote:
>> Hi
>>
>> Below is the code from the book 'PHP By Example'.
>> I typed the code but it did not run the ELSE part. I believe the problem
>> is
>> the $posted in 'if (!isset($posted))'
>> because it is never defined in the code. Where should I define it?
>
> First, this example is assuming that register_globals is set to "on",
> it is now set to "off" at most hosting sites. See
> <http://www.php.net/register_globals>
>
>>
>> Your help is greatly appreciated.
>>
>> Lawrence
>>
>> <?php
>> /* ch11ex06.php - demonstrate serialize() and unserialize() */
>>
>> // Main Program
>>
>> if ($isset[$posted]))
>
> The above should probably read
>
> if (!isset($_POST['submit']))
>
>> {
>> // the form has not been posted; create an object, show that it works
>> // before it is serialized, then serialize it and show the serialized
>> string
>> // in a form.
>> echo 'Creating a new object...<br>';
>> $objDog = new dog;
>> $objDog->name = 'Spike';
>> echo $objDog->name . '<br>';
>> $objDog->Bark();
>>
>> $strSerializedDog = base64_encode(serialize($objDog));
>>
>> echo <<<END_HTML
>> <form action="$PHP_SELF" method="post">
>
> Change "$PHP_SELF" to $_SERVER['PHP_SELF'] in the above statement
>
>> <input type="text" name="serialized_data" value="$strSerializedDog">
>> <input type="submit">
>
> Change the above statement to
>
> <input type="submit" name="submit" value="Submit">
>
>> </form>
>> END_HTML;
>>
>> }
>> else
>> {
>>
>> // the form has been posted; unserialized the posted string into an
>> object
>> // and use it to show that it still works.
>> echo 'Unserializing the object...<br>';
>> $objDog = unserialize(
>> base64_decode($HTTP_POST_VARS['serialized_data']));
>
> Change the above to
>
> base64_decode($_POST['serialized_data']));
>
>> echo $objDog->name . '<br>';
>> $objDog->Bark();
>>
>> }
>>
>> // class definition
>>
>> class dog
>> {
>> var $name;
>> function Bark()
>> {
>> echo "Woof!";
>> }
>> }
>>
>> ?>
>
> If you make the above changes, you're script should work.
>
> You should then write to the authors and/or publisher with your
> comments and corrections.
>
> Ken
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация