473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Basic question about incuding files and funcitons

I have a very basic question about how to include files to be used by
another file. I'm trying to include a bad word filter into the guestmap on
my website. I know almost nothing about PHP code. I've tried everything I
can think of but I keep getting error messages. The bad word filter code I
found else where is this:
File name is badwords.php

<?php
//* Check.php */

function check( ) /* Establishes the function check */
{

global $message; /* Gets All Variables */

//To Add New Words, Just Copy One Line From Below And Paste It Below The
Third Line.
//Just Replace the first word in quotes with the word you would like,
//and the second word in quotes to what you would like to change it to.//

$message = str_replace("bad word1","**",$message); /* Replaces the word
"hey" into "****" */
$message = str_replace("bad word2","**",$message);
$message = str_replace("bad word 3","**",$message);

echo $message;

}

return check(); //* Returns the function check() */

?>

I would like to keep this as a separate file and include it into the main
file. In the main file I inserted the two code lines:

include('badwords.php')
check('$message')

I've tried a lot of different things to get this to work but I always get
error messages when I run it on my website. I would like to keep it in a
separate file from the main file because of all the bad words. Also I need a
function because I would like to have it check the variables for several
fields.

So what should I do to get this to work?

--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/
Oct 5 '05 #1
6 1461
If you're calling it as

check($message)

you need to change the declaration of the function to

function check ($message)
{
....
}

and remove the "return check()" line from the separate page where you
have the function. Also, it would help if you told us exactly what
errors you are getting.

Greetings.

Oct 5 '05 #2
I've made the suggested changes and the error I get is:

Parse error: parse error, unexpected T_STRING in
/home/songc1/public_html/guestmap/guestmap_place.php on line 27

In the file guestmap_place.php, I have the lines:

include('badwords.php')

check($message)

Line 27 is ' check($message) '

The file ' badwords.php ' now reads:

<?php
//* badwords.php */

function check($message) /* Establishes the function check */
{

global $message; /* Gets All Variables */

//To Add New Words, Just Copy One Line From Below And Paste It Below The
Third Line.
//Just Replace the first word in quotes with the word you would like,
//and the second word in quotes to what you would like to change it to.//

$message = str_replace("badword1","**",$message); /* Replaces the word "hey"
into "****" */
$message = str_replace("badword2","**",$message);
$message = str_replace("badword3","**",$message);

echo $message;

}
?>


--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

"Samuel" <le*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
If you're calling it as

check($message)

you need to change the declaration of the function to

function check ($message)
{
...
}

and remove the "return check()" line from the separate page where you
have the function. Also, it would help if you told us exactly what
errors you are getting.

Greetings.

Oct 5 '05 #3
I believe I've discovered two problems with the code. First I didn't put in
the ";". So I changed the file in guestmap_place.php to now read:

include('badwords.php');
check($message);

Also I realized that I had a problem with the file name "badwords.php". The
actual file had a space between the "s" and the ".". I corrected that.

Now I get this error message:

Warning: Cannot modify header information - headers already sent by (output
started at /home/songc1/public_html/guestmap/badwords.php:38) in
/home/songc1/public_html/guestmap/guestmap_place.php on line 75
--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

"Jimmy Clay" <ji*****@netzero.net> wrote in message
news:1128553799.b80372a73b0fa22d0671e1bc9256e27f@t eranews...
I've made the suggested changes and the error I get is:

Parse error: parse error, unexpected T_STRING in
/home/songc1/public_html/guestmap/guestmap_place.php on line 27

In the file guestmap_place.php, I have the lines:

include('badwords.php')

check($message)

Line 27 is ' check($message) '

The file ' badwords.php ' now reads:

<?php
//* badwords.php */

function check($message) /* Establishes the function check */
{

global $message; /* Gets All Variables */

//To Add New Words, Just Copy One Line From Below And Paste It Below The
Third Line.
//Just Replace the first word in quotes with the word you would like,
//and the second word in quotes to what you would like to change it to.//

$message = str_replace("badword1","**",$message); /* Replaces the word
"hey" into "****" */
$message = str_replace("badword2","**",$message);
$message = str_replace("badword3","**",$message);

echo $message;

}
?>


--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

"Samuel" <le*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
If you're calling it as

check($message)

you need to change the declaration of the function to

function check ($message)
{
...
}

and remove the "return check()" line from the separate page where you
have the function. Also, it would help if you told us exactly what
errors you are getting.

Greetings.


Oct 5 '05 #4
Interesting the bad word filter seems to be working, but now the program
will not refresh the screen. I get this message:

Warning: Cannot modify header information - headers already sent by (output
started at /home/songc1/public_html/guestmap/badwords.php:36) in
/home/songc1/public_html/guestmap/guestmap_place.php on line 75

I believe line 75 must refer to this line of code:

//go back to the map
header('Location: '.$_SERVER['HTTP_REFERER']);

I'm not sure what to do.

--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

"Jimmy Clay" <ji*****@netzero.net> wrote in message
news:1128556086.1f0f39036372d86c36deacf6d25b51f6@t eranews...
I believe I've discovered two problems with the code. First I didn't put in
the ";". So I changed the file in guestmap_place.php to now read:

include('badwords.php');
check($message);

Also I realized that I had a problem with the file name "badwords.php".
The actual file had a space between the "s" and the ".". I corrected that.

Now I get this error message:

Warning: Cannot modify header information - headers already sent by
(output started at /home/songc1/public_html/guestmap/badwords.php:38) in
/home/songc1/public_html/guestmap/guestmap_place.php on line 75
--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

"Jimmy Clay" <ji*****@netzero.net> wrote in message
news:1128553799.b80372a73b0fa22d0671e1bc9256e27f@t eranews...
I've made the suggested changes and the error I get is:

Parse error: parse error, unexpected T_STRING in
/home/songc1/public_html/guestmap/guestmap_place.php on line 27

In the file guestmap_place.php, I have the lines:

include('badwords.php')

check($message)

Line 27 is ' check($message) '

The file ' badwords.php ' now reads:

<?php
//* badwords.php */

function check($message) /* Establishes the function check */
{

global $message; /* Gets All Variables */

//To Add New Words, Just Copy One Line From Below And Paste It Below The
Third Line.
//Just Replace the first word in quotes with the word you would like,
//and the second word in quotes to what you would like to change it to.//

$message = str_replace("badword1","**",$message); /* Replaces the word
"hey" into "****" */
$message = str_replace("badword2","**",$message);
$message = str_replace("badword3","**",$message);

echo $message;

}
?>


--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

"Samuel" <le*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
If you're calling it as

check($message)

you need to change the declaration of the function to

function check ($message)
{
...
}

and remove the "return check()" line from the separate page where you
have the function. Also, it would help if you told us exactly what
errors you are getting.

Greetings.



Oct 6 '05 #5
ji*****@netzero.net says...
Interesting the bad word filter seems to be working, but now the program
will not refresh the screen. I get this message:

Warning: Cannot modify header information - headers already sent by (output
started at /home/songc1/public_html/guestmap/badwords.php:36) in
/home/songc1/public_html/guestmap/guestmap_place.php on line 75

I believe line 75 must refer to this line of code:

//go back to the map
header('Location: '.$_SERVER['HTTP_REFERER']);

I'm not sure what to do.


The line
header('Location: '.$_SERVER['HTTP_REFERER']);
is trying to set the header information AFTER
/home/songc1/public_html/guestmap/badwords.php:36
has already set the header information, by:
(a) issuing a print or echo statement
or
(b) containing some white space that the browser is rendering as output

The more common problem is (b)

Best way to check is to call badwords.php directly into a browser, and see
if you get any (even blank) output rather than a "document contains no
data" message.

Geoff M
Oct 6 '05 #6
Thanks for eveyone's help. It seems to be working now. Here's the program I
came up with:

start of program

<?php

//* badwords.php */

//* Establishes the function check */
function check($message)
{

global $message; //* Gets All Variables */

//To Add New Words, Just Copy One Line From Below And Paste It Below The
Third Line.
//Just Replace the first word in quotes with the word you would like,
//and the second word in quotes to what you would like to change it to.//

$message = str_ireplace("badwordq","**",$message); //* Replaces the word
"hey" into "****" */
$message = str_ireplace("badword2","**",$message);
$message = str_ireplace("badword3","**",$message);
}

?>

end of program

The header problem seems to have been caused by a single space after the
"?>" at the very end.

Also I replace str_replace() with str_ireplace because str_ireplace is not
case sensitive.

In the main program I inserted the lines:

include('badwords.php');
check($message);

--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

"Jimmy Clay" <ji*****@netzero.net> wrote in message
news:1128508887.e5f1c5bf8db916918a5a06c28f641829@t eranews...
I have a very basic question about how to include files to be used by
another file. I'm trying to include a bad word filter into the guestmap on
my website. I know almost nothing about PHP code. I've tried everything I
can think of but I keep getting error messages. The bad word filter code I
found else where is this:
File name is badwords.php

<?php
//* Check.php */

function check( ) /* Establishes the function check */
{

global $message; /* Gets All Variables */

//To Add New Words, Just Copy One Line From Below And Paste It Below The
Third Line.
//Just Replace the first word in quotes with the word you would like,
//and the second word in quotes to what you would like to change it to.//

$message = str_replace("bad word1","**",$message); /* Replaces the word
"hey" into "****" */
$message = str_replace("bad word2","**",$message);
$message = str_replace("bad word 3","**",$message);

echo $message;

}

return check(); //* Returns the function check() */

?>

I would like to keep this as a separate file and include it into the main
file. In the main file I inserted the two code lines:

include('badwords.php')
check('$message')

I've tried a lot of different things to get this to work but I always get
error messages when I run it on my website. I would like to keep it in a
separate file from the main file because of all the bad words. Also I need
a function because I would like to have it check the variables for several
fields.

So what should I do to get this to work?

--

Jimmy Clay

Read free ebooks !!!!!
Go to my web page:
www.songofthecoyote.com/

Oct 6 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bbxrider | last post by:
i'm new to javascript but have programmed lots in vb, cobol, basic, etc jscript seems much more object oriented to me, much more direct manipulation of properties at least, than vb, don't know...
5
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler...
2
by: Sandra | last post by:
Hi there! Hope I have the right chat forum for this. Anyway, if someone could help me, I would really appreciate it. I have a few Microsoft Word XP files and here is what's happening... ...
6
by: Michael Tissington | last post by:
I have setup up Forms Authentication on my website and added configuration/mappings for exe, pdf and zip files (using C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll) However when...
17
by: Plissken.s | last post by:
Hi, Can you please tell me what is the guideline in Putting implmentation in .h files? I see examples where they put the implementation of getter/setting in the .h files where funcitons is > 10...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
21
by: Al Christoph | last post by:
I posted this last week end in the MSDN forums. No luck there. Let's see what the experts here have to say:-)))) I have a rather convoluted project. The distributable will come in eight...
6
by: JimmyKoolPantz | last post by:
I have been given the task of converting a program from VFP (visual foxpro) to Visual Basic.net. My question is "Is it possible to generate a DBF file Dynamically(at runtime) using Visual...
28
by: Randy Reimers | last post by:
(Hope I'm posting this correctly, otherwise - sorry!, don't know what else to do) I wrote a set of programs "many" years ago, running in a type of basic, called "Thoroughbred Basic", a type of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.