Welcome, Guest
  • Author Topic: Revised GuestBook.php script  (Read 127284 times)

    Flash-db

    • Administrator
    • Systems Administrator
    • *****
    • Posts: 1876
      • View Profile
      • Flash-db.com
    Revised GuestBook.php script
    « on: 01/24/03, 00:33 »
    If you are having trouble with the guestbook.php script used for the guestbook.  Please try this slightly modified script:


    <?php
    // If you are using an old version of php, remove the next set of lines.
    // or use $HTTP_POST_VARS["..."] instead.
    $Submit    $_POST["Submit"];
    $Name       $_POST["Name"];
    $Email       $_POST["Email"];
    $Website    $_POST["Website"];
    $Comments    $_POST["Comments"];
    $NumLow    $_REQUEST["NumLow"];
    $NumHigh    $_REQUEST["NumHigh"];

    // Replace special characters - you can remove the next 5 lines if wanted.
    $Name       ereg_replace("[^A-Za-z0-9 ]"""$Name);
    $Email       ereg_replace("[^A-Za-z0-9 \@\.\-\/\']"""$Email);
    $Comments   ereg_replace("[^A-Za-z0-9 \@\.\-\/\']"""$Comments);
    $Website    eregi_replace("http://"""$Website);
    $Website    ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]"""$Website);

    // Remove slashes.
    $Name       stripslashes($Name);
    $Email       stripslashes($Email);
    $Website    stripslashes($Website);
    $Comments    stripslashes($Comments);

    // ###################################################################################
    // ########## Reading and Writing the new data to the GuestBook Database #############

    if ($Submit == "Yes") {
    // Next line tells the script which Text file to open.
       
    $filename    "GuestBook.txt";

    // Opens up the file declared above for reading 

       
    $fp       fopen$filename,"r"); 
       
    $OldData    fread($fp80000); 
       
    fclose$fp ); 

    // Gets the current Date of when the entry was submitted
       
    $Today       = (date ("l dS of F Y ( h:i:s A )",time()));

    // Puts the recently added data into html format that can be read into the Flash Movie.
    // You can change this up and add additional html formating to this area.  For a complete listing of all html tags
    // you can use in flash - visit: www.macromedia.com/support/flash/ts/documents/htmltext.htm

       
    $Input "Name: <b>$Name</b><br>Email: <b><u><a href=\"mailto:$Email\">$Email</a></u></b><br>Website: <b><u><a href=\"http://$Website\" target=\"_blank\">$Website</a></u></b><br>Comments: <b>$Comments</b><br><i><font size=\"-1\">Date: $Today</font><br><br>.:::.";

    /* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file  */

       
    $New "$Input$OldData";

    // Opens and writes the file.

       
    $fp fopen$filename,"w"); 
       if(!
    $fp) die("&GuestBook=cannot write $filename ......&");
       
    fwrite($fp$New800000); 
       
    fclose$fp ); 
    }

    // ###################################################################################
    // ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##



    // Next line tells the script which Text file to open.
       
    $filename "GuestBook.txt";

    // Opens up the file declared above for reading 

       
    $fp    fopen$filename,"r"); 
       
    $Data    fread($fp800000); 
       
    fclose$fp );

    // Splits the Old data into an array anytime it finds the pattern .:::.
       
    $DataArray split (".:::."$Data);

    // Counts the Number of entries in the GuestBook
       
    $NumEntries count($DataArray) - 1;

       print 
    "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
       for (
    $n $NumLow$n $NumHigh$n++) {
       print 
    $DataArray[$n];
          if (!
    $DataArray[$n]) {
             Print 
    "<br><br><b>No More entries</b>";
          exit;
          }
       }
    ?>
    « Last Edit: 01/24/03, 01:57 by Flash-db »
    Flash-DB

    Joel Kilgore

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Joel's_site
      • Email
    Re:Revised GuestBook.php script
    « Reply #1 on: 02/19/03, 23:35 »
    I am very new to the whole concept of Flash and PHP. (Three weeks ago I had never used either)
    I recently downloaded the GuestBook and PHP package and found these errors.
    I was going to post the solution but I see that you already have.
    It's good to know that I found the answer myself though. I learned quite a bit in the process.

    Joel Kilgore

    dev

    • Server what's that
    • *
    • Posts: 2
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #2 on: 03/11/03, 18:32 »
    Hi Jeff.

    I am using your PHP script with little modifications ...

    BUT,

    1) whenever someone enters  ':' then the Guest book hangs ( says loading new..... )

    2) you are replacing & with space, How can I have & itself entered into Comments. because some times it is good to have & value itself.

    Please let me know .

    Thanks for your help,
    -Devender

    My PHP SCRIPT: >>>>>>>>>>>>>>>>>>>>>>>





    <?
    ############### Begin GuestBook Script #####################################

    ##The first 3 lines use a regular expression to match a pattern then replace it with nothing.  The only reason for this is so we only allow necessary characters to be entered into the guestbook. This also takes out slashes which are sometimes added in the post headers to make the string friendly.  You can erase or take these lines out if you want.


     $Name = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
     $Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
     $Comments  = ereg_replace("[\&]", "and", $Comments);
     $Website = eregi_replace("http://", "", $Website);
     $Website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);

     $Name = stripslashes($Name);
     $Email = stripslashes($Email);
     $Website = stripslashes($Website);
     $Comments = stripslashes($Comments);


    ####################################################################################

    ########### Reading and Writing the new data to the GuestBook Database #############

    if ($Submit == "Yes") {
    #Next line tells the script which Text file to open.
     $filename = "GuestBook.txt";

    #Opens up the file declared above for reading

     $fp = fopen( $filename,"r");
     $OldData = fread($fp, 80000);
     fclose( $fp );

    #Splits the Old data into an array anytime it finds the pattern .:::.
     $DataArray = split (".:::.", $OldData);

    #Counts the Number of entries in the GuestBook
     $NumEntries = count($DataArray);



    #Gets the current Date of when the entry was submitted
     $Today = (date ("F dS Y, h:i:s A",time()));

    #Puts the recently added data into html format that can be read into the Flash Movie.

     $Input = "<font size=\"-1\"><b>SNo: $NumEntries</b> (Date: $Today EST)</font><br>
    <font size=\"-1\">Name: <b>$Name</b></font><br>
    <font size=\"-1\">Email: <u><a href=\"mailto:$Email\">$Email</a></u></font><br>
    <font size=\"-1\">Website: <u><a href=\"http://$Website\" target=\"_blank\">$Website</a></u></font><br>
    <font size=\"-1\">Comments: $Comments</font><br>------------------------------------------------<br>

    .:::.";

    #This Line adds the 'GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file

     $New = "$Input$OldData";

    #Opens and writes the file.

     $fp = fopen( $filename,"w+");
     fwrite($fp, $New, 80000);
     fclose( $fp );
    }
    ####################################################################################
    ########## Formatting and Printing the Data from the Guestbook to the Flash Movie ##

    #Next line tells the script which Text file to open.
     $filename = "GuestBook.txt";

    #Opens up the file declared above for reading

     $fp = fopen( $filename,"r");
     $Data = fread($fp, 80000);
     fclose( $fp );

    #Splits the Old data into an array anytime it finds the pattern .:::.
     $DataArray = split (".:::.", $Data);

    #Counts the Number of entries in the GuestBook
     $NumEntries = count($DataArray) - 1;

     print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
     for ($n = $NumLow; $n < $NumHigh; $n++) {
     print $DataArray[$n];
         if (!$DataArray[$n]) {
         Print "

    <b>No More entries</b>";
         exit;
         }
     }
     


    ####################################################################################
    ###############  End GuestBook Script




    bart peeters

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #3 on: 03/18/03, 04:53 »
    Hi,

    I have a little question.. the guestbook worked fine on our server until the system administrator had the luminous idea to upgrade the php-version to the latest version. Of course momentarily it doesn't work anymore  >:(
    When the guestbook is opened , i get the following messages :

    Notice : undefined variable Numlow in (then the path) on line 72

    and

    Notice : undefined variable Numhigh in (then the path) on line 72



    Anyone any idea what causes this?

    Greetz

    Bart

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:Revised GuestBook.php script
    « Reply #4 on: 03/19/03, 06:58 »
    Hi Bart,
    just read the first entry in this thread.
    There is the solution.
    The new PHP-Version (4 and beyond) does not automatcly read the POST or GET Variables.
    You have to make it to read them as you like with the $HTTP_POST (or GET)_VARS["name of the var"];
    happy flashing
    8)
    Ronald

    bart peeters

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #5 on: 03/21/03, 10:45 »
    Hey Ronald,

    I tried the adjusted script and it works. Thanks for the swift reply. I tried the new script right after I posted my message due to server problems , should have waited of course.. my bad  ;D

    What I do have are large breaks between the categories ( the sender , his email, his website etc etc ) which weren't there with the old script. Any ideas?

    I know , this is probably something really obvious but i'm fairly new to this php-thing... so bare with me  ;)

    Have a  nice weekend and thanks for the help

    Bart

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:Revised GuestBook.php script
    « Reply #6 on: 03/21/03, 12:29 »
    Don't worry, be happy 8)

    For that weird fill of your fields, I'd like to see your procedure.

    happy flashing
    8)
    Ronald

    bart peeters

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #7 on: 03/25/03, 10:56 »
    Well , so far I didn't alter anything in the original revised php.
    For the result...if you'd like you could take a look at a website i made for
    a local art photographer.. http://www.filipnaudts.be ,in the flash version under 'contact'.
    The first 2 entries are made with the new php , the others with the old version.


    Still flashing happily  ;D

    Bart

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:Revised GuestBook.php script
    « Reply #8 on: 03/25/03, 11:21 »
    Hi Bart,
    great artwork and SUPER SITE!!!

    To your Problem. It seams you generate Paragraphs instead of Linebreaks.
    Look over the code again, if it inserts p-tags or br-tags.

    happy flashing
    8)
    Ronald

    bart peeters

    • Server what's that
    • *
    • Posts: 5
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #9 on: 03/26/03, 11:03 »
    Alright ! Seems you were right , the code was indeed generating paragraphs instead of breaks. I owe you one  ;D

    Greetz

    Bart

    Riff

    • Server what's that
    • *
    • Posts: 20
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #10 on: 04/26/03, 14:04 »

    If you are having trouble with the guestbook.php script used for the guestbook.  Please try this slightly modified script:

    <br><?php<br>// If you are using an old version of php, remove the next set of lines.<br>// or use $HTTP_POST_VARS["..."] instead.<br>$Submit    = $_POST["Submit"];<br>$Name       = $_POST["Name"];<br>$Email       = $_POST["Email"];<br>$Website    = $_POST["Website"];<br>$Comments    = $_POST["Comments"];<br>$NumLow    = $_REQUEST["NumLow"];<br>$NumHigh    = $_REQUEST["NumHigh"];<br><br>// Replace special characters - you can remove the next 5 lines if wanted.<br>$Name       = ereg_replace("[^A-Za-z0-9 ]", "", $Name);<br>$Email       = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);<br>$Comments   = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);<br>$Website    = eregi_replace("http://", "", $Website);<br>$Website    = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);<br><br>// Remove slashes.<br>$Name       = stripslashes($Name);<br>$Email       = stripslashes($Email);<br>$Website    = stripslashes($Website);<br>$Comments    = stripslashes($Comments);<br><br>// ###################################################################################<br>// ########## Reading and Writing the new data to the GuestBook Database #############<br><br>if ($Submit == "Yes") {<br>// Next line tells the script which Text file to open.<br>   $filename    = "GuestBook.txt";<br><br>// Opens up the file declared above for reading <br><br>   $fp       = fopen( $filename,"r"); <br>   $OldData    = fread($fp, 80000); <br>   fclose( $fp ); <br><br>// Gets the current Date of when the entry was submitted<br>   $Today       = (date ("l dS of F Y ( h:i:s A )",time()));<br><br>// Puts the recently added data into html format that can be read into the Flash Movie.<br>// You can change this up and add additional html formating to this area.  For a complete listing of all html tags<br>// you can use in flash - visit: www.macromedia.com/support/flash/ts/documents/htmltext.htm<br><br>   $Input = "Name: <b>$Name</b><br>Email: <b><u><a href=\"mailto:$Email\">$Email</a></u></b><br>Website: <b><u><a href=\"http://$Website\" target=\"_blank\">$Website</a></u></b><br>Comments: <b>$Comments</b><br><i><font size=\"-1\">Date: $Today</font><br><br>.:::.";<br><br>/* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file  */<br><br>   $New = "$Input$OldData";<br><br>// Opens and writes the file.<br><br>   $fp = fopen( $filename,"w"); <br>   if(!$fp) die("&GuestBook=cannot write $filename ......&");<br>   fwrite($fp, $New, 800000); <br>   fclose( $fp ); <br>}<br><br>// ###################################################################################<br>// ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##<br><br><br><br>// Next line tells the script which Text file to open.<br>   $filename = "GuestBook.txt";<br><br>// Opens up the file declared above for reading <br><br>   $fp    = fopen( $filename,"r"); <br>   $Data    = fread($fp, 800000); <br>   fclose( $fp );<br><br>// Splits the Old data into an array anytime it finds the pattern .:::.<br>   $DataArray = split (".:::.", $Data);<br><br>// Counts the Number of entries in the GuestBook<br>   $NumEntries = count($DataArray) - 1;<br><br>   print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";<br>   for ($n = $NumLow; $n < $NumHigh; $n++) {<br>   print $DataArray[$n];<br>      if (!$DataArray[$n]) {<br>         Print "<br><br><b>No More entries</b>";<br>      exit;<br>      }<br>   }<br>?><br>



    Hi, I used the above script after it stopped working due to my site hosts turned Register Globals off and Safe Mode on.  Host uses PHP version 4.1.2


    Everything works okay bothin sign and read...BUT i have about 20 entries and when i click on next 5, i get the following message:

    Notice:  Undefined index: 25 in /home/site/443/web/GB.php on line 90

    Notice:  Undefined index: 25 in /home/site/443/web/GB.php on line 91


    Line 90 in the above script excluding the line

    $Comments   = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);


    is the line that starts:  print $DataArray[$n];

    Why am i getting this?

    Please help

    Riff


    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:Revised GuestBook.php script
    « Reply #11 on: 04/26/03, 16:11 »
    Hi,
    is it possible, that your file does not have any entry yet?
    happy flashing
    8)
    Ronald

    Riff

    • Server what's that
    • *
    • Posts: 20
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #12 on: 04/26/03, 18:18 »
     Hi Ronald,

    There are 20 entries in the guestbook from before, on the older script, the guestbook works, it's just that if i go past the 20 entries i get the message that i have highlighted, which i think is the servers php telling me there's a problem.

    Check out the book at http://www.voycemusic.co.uk

    You will know what i mean.

    Cheers

    Riff

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #13 on: 04/26/03, 20:12 »
    Hi,

    they also changed error reporting...
    The message you get indicates that the scriipt tries to get non-existent entries  in
    print $DataArray[$n];
    this should actually be
    if(isset($DataArray[$n]))
      print $DataArray[$n];
    else
    {  print "no more entries";
      break;
    }

    Musicman

    Mattias Lindroth

    • Server what's that
    • *
    • Posts: 1
      • View Profile
      • Email
    Re:Revised GuestBook.php script
    « Reply #14 on: 09/16/03, 19:37 »
    im kindof a total newbie to php, but i gave it a shot and copied this php script

    <?php
    // If you are using an old version of php, remove the next set of lines.
    // or use $HTTP_POST_VARS["..."] instead.
    $Submit    = $_POST["Submit"];
    $Name      = $_POST["Name"];
    $Email      = $_POST["Email"];
    $Website    = $_POST["Website"];
    $Comments    = $_POST["Comments"];
    $NumLow    = $_REQUEST["NumLow"];
    $NumHigh    = $_REQUEST["NumHigh"];

    // Replace special characters - you can remove the next 5 lines if wanted.
    $Name      = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
    $Email      = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
    $Comments  = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
    $Website    = eregi_replace("http://", "", $Website);
    $Website    = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);

    // Remove slashes.
    $Name      = stripslashes($Name);
    $Email      = stripslashes($Email);
    $Website    = stripslashes($Website);
    $Comments    = stripslashes($Comments);

    // ###################################################################################
    // ########## Reading and Writing the new data to the GuestBook Database #############

    if ($Submit == "Yes") {
    // Next line tells the script which Text file to open.
     $filename    = "GuestBook.txt";

    // Opens up the file declared above for reading

     $fp      = fopen( $filename,"r");
     $OldData    = fread($fp, 80000);
     fclose( $fp );

    // Gets the current Date of when the entry was submitted
     $Today      = (date ("l dS of F Y ( h:i:s A )",time()));

    // Puts the recently added data into html format that can be read into the Flash Movie.
    // You can change this up and add additional html formating to this area.  For a complete listing of all html tags
    // you can use in flash - visit: www.macromedia.com/support/flash/ts/documents/htmltext.htm

     $Input = "Name: <b>$Name</b>
    Email: <b><u><a href=\"mailto:$Email\">$Email</a></u></b>
    Website: <b><u><a href=\"http://$Website\" target=\"_blank\">$Website</a></u></b>
    Comments: <b>$Comments</b>
    <i><font size=\"-1\">Date: $Today</font>

    .:::.";

    /* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file  */

     $New = "$Input$OldData";

    // Opens and writes the file.

     $fp = fopen( $filename,"w");
     if(!$fp) die("&GuestBook=cannot write $filename ......&");
     fwrite($fp, $New, 800000);
     fclose( $fp );
    }

    // ###################################################################################
    // ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##



    // Next line tells the script which Text file to open.
     $filename = "GuestBook.txt";

    // Opens up the file declared above for reading

     $fp    = fopen( $filename,"r");
     $Data    = fread($fp, 800000);
     fclose( $fp );

    // Splits the Old data into an array anytime it finds the pattern .:::.
     $DataArray = split (".:::.", $Data);

    // Counts the Number of entries in the GuestBook
     $NumEntries = count($DataArray) - 1;

     print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
     for ($n = $NumLow; $n < $NumHigh; $n++) {
     print $DataArray[$n];
         if (!$DataArray[$n]) {
           Print "

    <b>No More entries</b>";
         exit;
         }
     }
    ?>

    but instead of showing entries in the flash movie, it shows:



    ";

     for ($n = $NumLow; $n



    thats it and nothing works...

    uhm any ideas of what i should do??

    ??? ??? ???