Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl commenting Script? 2

Status
Not open for further replies.

ETbyrne

Programmer
Dec 27, 2006
59
US
Hi, I'm new to Perl and I am reading a book on it.

I was wondering if anybody knew of a script that allows someone to comment on a page but, the same script can be used for multiple pages.

Thanks for all help!
-ETbyrne
 
your question is vague. What do you mean by "comment on page"? Is this a CGI script or not? Or are you just searching for a canned script? If so, search on script archives such as
- Kevin, perl coder unexceptional!
 
I'm looking for a cgi script. I've been looking for a simple "guesrbook like" script that can work with multiple pages.

What I mean by "guestbook like" is all I want it to do is allow someone to comment on a page, and possibly rate it. But, at the same time, being able to use the same javascript on multiple pages that links to the same script. (you know, so I can to upload the script one and use it for a whole site.

I've looked at tons of script archives and I have never found what I'm looking for.

You don't know me.
 
where do the comments get posted? In a common file/page or on the page that is being commented about?

- Kevin, perl coder unexceptional!
 
The comments would be posted on the page that is being commented about.

You don't know me.
 
A simple solution would be to have the CGI print out JavaScript, and have each page tell it what page it's on.

Code:
<script src="comment.cgi?page=home"></script>

and

Code:
#!/usr/bin/perl -w
use URI::Escape;

my $code = qq~<b>some <i>html</i> codes</b> <u>to print out</u> onto the page (can be anything at all)~;

# uri encode our HTML so it doesn't conflict with the JavaScript
my $enc = uri_escape($code);

# print out JS for the page
print "Content-Type: text/javascript\n\n";
print qq~
document.writeln (unescape("$enc"));
~;

And what the code does is up to you. But you have a query param of "page", maybe it can read and write from "./comments/$page.txt" to save comments per-page?

-------------
Cuvou.com | The NEW Kirsle.net
 
Thanks! So let me get this straight, I can put in any forms inside the javascript without altering the CGI script?

You don't know me.
 
I don't know, that sounds a bit dangerous to me. All anyone might need to do is edit the html source code to send the data to a different page and the cgi script will open and add the data to the wrong page, maybe an important page that should not be tampered with.

Don't risk security for convenience. Make sure this will work properly before going live with a commenting system of this nature.

- Kevin, perl coder unexceptional!
 
How are sites with lots of different pages that allow you to comment on them set up?

You don't know me.
 
I don't know, it could be done many ways, but anytime you allow those pesky internet users to post stuff on your website you should treat it like poison. But any page that you want comments to be posted on should be checked against a list, if it's not on the list, throw out the comments.

If you can't figure out how to do it yourself and their are no canned scripts that do what you want, consider hiring a programmer to do the job for you. Just like you would hire a plumber or electrician or other professional to do work for you that you are not capable of or just don't want to do.

There are many freelance sites that allow you to post a job and accept bids.

- Kevin, perl coder unexceptional!
 
Dude, I'm just 15, I can't afford to pay someone to make a script for my websites.

You don't know me.
 
Thanks for all the help anyways.:)

You don't know me.
 
dude, like your sig says:

You don't know me.


You're welcome, keep looking around, hopefully you find a script you can use.

- Kevin, perl coder unexceptional!
 
Since getting a scrpt that can comment on multiple pages is out of the question, I have looked at tons of free script achives for a very simple questbook/commenting script that all it does is ask for name and comments.

But, I can't find a single simple script. Instead I find all of these complex guestbooks with this and that feature. The thing with these scripts is they are hard to set up and you can't use a reagular html page. (you know, they are on their own page)

If somebody could point me to one that would be great! :)

-ETbyrne

You don't know me.
 
How would I build a simple guestbook that writes the data from let's say index.shtml to a .txt file and then goes back to indext.shtml?

indext.shtml only has a textbox and a textarea.

You don't know me.
 
your basic .shtml page (comments.shtml):

Code:
<html>
<head>
<title>something</title>
</head>
<body>
<!your ssi tag here to display the comments file>
<hr>
Add your comments:<br>
<form action="cgi-bin/comments.pl" method="post">
<input type="text" name="name"><br>
<textarea name="comments"></textarea><br>
<input type="submit">
</form>
</body>
</html>

comments.pl (untested code):

Code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
$CGI::POST_MAX = 1024 * 10;  # max 10K posts
$CGI::DISABLE_UPLOADS = 1;  # no uploads
my $name = param('name') or error('Enter a name');
my $comments = param('comments') or error('Enter some comments');
($name,$comments) = escapeHTML($name,$comments);

open(my $FH,">>path/to/comments.txt") or die "$!";
print $FH "<hr>Name: $name<br>Comments:<br>$comments<hr>\n";
undef $FH;

print "Location: [URL unfurl="true"]http://www.yoursite.com/comments.shtml";[/URL]

sub error{
   my $error = shift;
   print header,start_html,h1($error),end_html;
   exit;
}





- Kevin, perl coder unexceptional!
 
Thanks! I'll try that.

You don't know me.
 
It's not working, I keep getting this error...

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Use of uninitialized value in concatenation (.) or string at e:\0\74\38\237038\user\240783\htdocs\mywebs\tmportal\test\comments.pl line 13.
Location:

You don't know me.
 
Add two line breaks after the Location header

Code:
print "Location: [URL unfurl="true"]http://www.yoursite.com/comments.shtml[/URL][COLOR=blue]\n\n[/color]";

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top