Jump to content

PHP Guestbook wont accept Colon ( : ).


Recommended Posts

Hi :)

 

I just implementet a PHP Guestbook in my Flash site, and it works almost perfectly.

But i have one problem.

 

Every time i try to write on the guestbook, and include a Colon : <---- , it wont work.

How do i make it work?

 

You can see the guestbook here:

 

http://www.meny-graphics.dk/blog

 

by pressing "Mere" under the first entry, and scrolling down.

 

The PHP file can be found here:

 

http://www.meny-graphics.dk/blog/GuestBook.php

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/192314-php-guestbook-wont-accept-colon/
Share on other sites

You need to post the actual code, as we cannot see the code from the .php file. Post it inside of


tags.

 

Here ya go :)

 

 

<?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   = htmlspecialchars($Comments); 
$Comments   = nl2br($Comments);
$Website 	= ereg_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: http://www.macromedia.com/support/flash/ts/documents/htmltext.htm

$Input = "<font size=\"18\"><b>$Name</b></font><br><font size=\"-4\">$Today</font><br><br><font size=\"10\"><b>$Comments</b></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  */

$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 "<br><br><b>Ikke flere kommentarer</b>";
	exit;
	}
}
?>

Can you post the data found in GuestBook.txt ?

 

I can only see it stripping : from some data, and it appears to be splitting data in the GuestBook.txt file on the delimiter: .:::.

 

Maybe the semi colon is interfering with the guestbook file's delimiter some how?

 

PS: function "split" is being outdated from php v6.0 onwards, you should change it to str_split

Can you post the data found in GuestBook.txt ?

 

I can only see it stripping : from some data, and it appears to be splitting data in the GuestBook.txt file on the delimiter: .:::.

 

Maybe the semi colon is interfering with the guestbook file's delimiter some how?

 

PS: function "split" is being outdated from php v6.0 onwards, you should change it to str_split

 

Thanks for the answer ! Though i didnt understand much of it :) Im pretty new to this.

The GuestBook.txt is completely empty, when noone has posted on the guestbook.

 

Its funny - i also had problems posting special characters (ÆØÅ), but i found someone on another random forum who said that i should insert

 

$Comments   = htmlspecialchars($Comments);

 

in the beginning of the php.

I did that, and it worked.

 

Now i only need it to accept Colon, so people can post smiley faces, web adresses, etc :)

Are they being removed using eregi_replace

 

Try removing the following lines

 

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

 

Then try it, just to see if its one of them....

Are they being removed using eregi_replace

 

Try removing the following lines

 

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

 

Then try it, just to see if its one of them....

 

Thanks for the answer. :)

I tried to remove all the lines, but it didnt change anything. :(

try removing

 

$Comments = stripslashes($Comments);

 

to test.

 

Where is the form posting the information to this file?

 

That didnt work either.

 

It works this way:

 

I have a Flash File, with soem GuestBook Flash (AS2) code on it.

When someone fills in the name, and comment fields, and press "Tilføj Kommentar" (Submit), The PHP file writes the comment, into the GuestBook.txt file.

The Flash site, then shows the GuestBoox.Txt file.

 

 

 

I tried almost all the charaters i could find, at it posts perfectly, EXCEPT if the message includes a Colon.

This is very wierd.

 

Try it out.

 

 

 

@fresch, the issue may not be PHP at all. It is most likely on the flash end side. I would do a search about flash removing colon's from posts and see what you come up with. In that code I do not see how it would be removing the colon.

 

The true way to test is echo out $_POST['comments'] before you do anything to it, as this will tell you if the data is coming in without the : or if the colon was removed prior to being posted.

@fresch, the issue may not be PHP at all. It is most likely on the flash end side. I would do a search about flash removing colon's from posts and see what you come up with. In that code I do not see how it would be removing the colon.

 

The true way to test is echo out $_POST['comments'] before you do anything to it, as this will tell you if the data is coming in without the : or if the colon was removed prior to being posted.

 

I have looked everywhere, and i cant find anyone who has the same problem.

This is really wierd :(

When you say,

I tried almost all the charaters i could find, at it posts perfectly, EXCEPT if the message includes a Colon.

This is very wierd.

what exactly do you mean?

 

If the user inputs a colon and clicks submit, it will not save the guestbook data?

If the user inputs a colon and clicks submit, it saves the data, but then when viewing it will not show the post correctly?

Does it save partial amounts of the data if there is a colon? Does it save data up to the colon but nothing beyond?

 

Describe exactly what is failing, and what is working and we might be able to narrow down where the problem is.

  • 1 year later...

Sorry for Bumping this thread - After almost 2 years, i went back to continue working on the site.

And i still have the problem - Whenever i type a Colon in the guestbook, i can't post it.

 

The "Add Comment" button simply does nothing.

Every other character i tried worked fine.

 

You can test it out, by checking the it out here:

 

http://www.meny-graphics.

 

use the oldest Blog Entry, to test with (Click Comment).

 

Thanks a lot for the help so far guys - I really hope to get this solved.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.