# Shoutbox in PHP and Flash

**URL:** <https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351>\
**Category:** programming\
**Created:** [November 13, 2003, 12:15am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351 "2003-11-13T00:15:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yeldarb](https://avatars.discourse-cdn.com/v4/letter/y/51bf81/32.png) [@Yeldarb](https://forum.kirupa.com/u/Yeldarb)\
**Post date:** [November 13, 2003, 12:15am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/1 "2003-11-13T00:15:04Z")

</div>

Ok, I’m trying to make a shout box using PHP and Flash, it’s not working though… You can see what I have so far at [www.barbdwyer.com/T6](http://www.barbdwyer.com/T6) . I don’t know PHP, so I had one of my friends write the script for me, but he doesn’t know Flash, so he couldn’t help me set it up.

in flash, i have the following code on my submit button:

```auto
on(press) { 
      getURL ("add.php", "_blank", "POST");
}

```

i also have this in a frame:

```auto
onEnterFrame = function () {
	Name = theName.text;
	Email = theContact.text;
	Comments = theMessage.text;
};

```

then here’s the PHP scripts.

one called add.php:

```php
<?php

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

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

if ($Submit == "Yes") { 
	$filename = "shoutbox.txt"; 
	$fp = fopen( $filename,"r"); 
	$OldData = fread($fp, 80000); 
	fclose( $fp );
	$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>.:::."; 
	$New = "$Input$OldData";
	$fp = fopen( $filename,"w"); 
	fwrite($fp, $New, 80000); 
	fclose( $fp );
	Header("Location: shoutbox.php"); 
} 

?>

```

one called forum.php:

```php
<?php

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

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

if ($Submit == "Yes") { 
	$filename = "shoutbox.txt"; 
	$fp = fopen( $filename,"r"); 
	$OldData = fread($fp, 80000); 
	fclose( $fp );
	$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>.:::."; 
	$New = "$Input$OldData";
	$fp = fopen( $filename,"w"); 
	fwrite($fp, $New, 80000); 
	fclose( $fp );
	Header("Location: index.php"); 
} 

?>
<form name="shoutbox" action="form.php" method="post">
<table align="center" border="0">
  <tr>
    <td>Name:</td>
    <td><input type="text" name="Name"></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input type="text" name="Email"></td>
  </tr>
  <tr>
    <td>Message:</td>
    <td colspan="2" align="right">
<textarea name="Comments"></textarea>
<input type="hidden" name="Submit" value="Yes">
    </td>
  </tr>
  <tr>
    <td colspan="2" align="right"><input type="submit" value="Submit"></td>
  </tr>
</table>
</form>

```

and finally, one called shoutbox.php:

```php
<?php

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

$DataArray = split (".:::.", $Data);

//Put in the starting tag and the ending tag number
for ($n = 0; $n < 20; $n++) {
print $DataArray[$n]; 
}

?>

```

then there is an empty text file called shoutbox.txt

I am completely confused, he told me to make the add.php from the php part of the forum.php, and I know that this worked when it was in HTML, but I got a headache trying to get it to work in flash. Can someone please help, thanks 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2003, 7:26pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/2 "2003-11-13T19:26:47Z")

</div>

You have to use the LoadVars() class to accomplish this (or atleast thats what i think you should use).

On the main timeline on the first frame, do this:  
[AS]  
var dataSend = new LoadVars();

dataSend.Name = theName.text;  
dataSend.Email = theContact.text;  
dataSend.Comments = theMessage.text;

[/AS]

Change this on the button  
[AS]  
on(press) {  
getURL (“add.php”, “\_blank”, “POST”);  
}[/AS]

to this

[AS]  
on(press) {  
\_root.dataSend.send (“add.php”, “\_blank”, “POST”);  
}[/AS]

That should probably do it. You can do this via a function, but it works both ways.

I’m suspecting you have to change something in the PHP script, but try this out and tell me if it works or not.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2003, 9:20pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/3 "2003-11-13T21:20:42Z")

</div>

thanks, i’ll try that out now 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2003, 9:25pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/4 "2003-11-13T21:25:14Z")

</div>

hmm, didn’t work ☹

thanks for trying though

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2003, 10:53pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/5 "2003-11-13T22:53:04Z")

</div>

Why is it get url? It should be loadVariablesNum.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 13, 2003, 10:57pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/6 "2003-11-13T22:57:42Z")

</div>

this is for the sending, not the recieving

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 12:52am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/7 "2003-11-14T00:52:21Z")

</div>

can anyone else try to help, please? thanks again in advance

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 1:00pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/8 "2003-11-14T13:00:56Z")

</div>

I apologize for not getting back. I know what the problem is. Will get back to u in a few

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 1:04pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/9 "2003-11-14T13:04:56Z")

</div>

OK, thank you

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 1:18pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/10 "2003-11-14T13:18:59Z")

</div>

in the php scripts (except the shoutbox.php), add these lines at the top:

```php

$nameReceived = $_POST['Name'];
$emailReceived = $_POST['Email'];
$commentsReceived = $_POST['Comments'];

```

After doing this, change

```php

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

```

to:

```php

$Name = ereg_replace("[^A-Za-z0-9<>]", "", $nameReceived); 
$Email = ereg_replace("[^A-Za-z0-9 @.-/'<>]", "", $emailReceived); 
$Comments = ereg_replace("[^A-Za-z0-9 @.-/'<>]", "", $commentsReceived);

```

in both scripts. Hope it works

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 1:44pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/11 "2003-11-14T13:44:55Z")

</div>

I’ll try that when I get home, thanks so much for your help 😃 :thumb:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 2:48pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/12 "2003-11-14T14:48:15Z")

</div>

Hey no problem. Don’t thank me, thank the forum 😉

And yea, one more thing. Change the $Submit in the if conditions to $\_POST[‘Submit’]. If all of this still doesnt work, post the files if u can.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 4:53pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/13 "2003-11-14T16:53:05Z")

</div>

where is this $Submit that you are talking about? in the if statement?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 7:41pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/14 "2003-11-14T19:41:34Z")

</div>

the line after

$Comments = stripslashes($Comments);

I’m sorry about replying late. I keep waiting for the email notification but it seems like it doesnt work all the time

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 9:49pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/15 "2003-11-14T21:49:18Z")

</div>

hmm, it still doesn’t work… ☹  
I’m uploading the files now, thanks again 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 9:55pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/16 "2003-11-14T21:55:37Z")

</div>

[www.barbdwyer.com/T6/site.zip](http://www.barbdwyer.com/T6/site.zip) it’s a pretty big filesize, 1.5 mb because it has the .fla in there

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 14, 2003, 10:51pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/17 "2003-11-14T22:51:51Z")

</div>

what’s the php file supposed to output? did you try running the file outside of flash, just calling it from the browser?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 15, 2003, 2:10am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/18 "2003-11-15T02:10:39Z")

</div>

I got it to work. I will post the files in some time. Hope u dont mind the delay

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 15, 2003, 7:12am UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/19 "2003-11-15T07:12:00Z")

</div>

yeah, it all worked with HTML, but it didn’t work when I tried to call it from flash.

thanks hamza 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 15, 2003, 5:34pm UTC](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351/20 "2003-11-15T17:34:09Z")

</div>

That’s why I said, use loadVariablesNum and set it to send using POST. It’s not only for recieving. This method worked so many times for me when I had a shoutbox.

- Anyone know how I can make my chatroom faster? I need to learn how to refresh manually every 1 second.

[Next page](https://forum.kirupa.com/t/shoutbox-in-php-and-flash/35351.md?page=2)
