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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help??? a good deal of questions 2

Status
Not open for further replies.

MAWarGod

Programmer
Feb 15, 2002
352
US
Code:
#!/usr/bin/perl



# open messages
open (MSG, "messages.txt");
my @lines = <MSG>;
@lines = reverse @lines;
close (MSG);
chomp @lines;

print "Content-Type: text/html\n\n";
foreach my $line (@lines) {
   my ($ip,$user,$password,$user_stripped,$cc,$rr,$his,$np,$ver,$timestamp,$msg) = split(/:::/, $line, 11);
   print "<TABLE WIDTH='100%' border='0' cellpadding='0' cellspacing='0'><TR><TD><font color=$cc>[$timestamp]<b>$user says:</b>$msg<p></font><P></TD></TR></TABLE>\n\n";
}

# add a form to add a message to the file
print qq~<form name="add" action="testi.cgi">
<input type="text" name="name" value="Anonymous" size="20">Name<br>
<input type="text" name="password" size="20">Password<br>
<input type="text" size="2" value="10" name="refresh_rate">refresh<br>
<input type="text" size="2" value="10" name="histroy">histroy<br>
<input type="checkbox" checked="checked" value="1" name="nopic">nopic<br>
<input type="checkbox" checked="checked" value="1" name="verbose">verbose<br>
<td nowrap><select name="CHATCOLOR" size="1">
                      <option value="white" selected>white</option>
                      <option value="blue">blue</option>
                      <option value="blueviolet">blueviolet</option>
                      <option value="chocolate">chocolate</option>
                      <option value="darkgreen">darkgreen</option>
                      <option value="dimgray">dimgray</option>
                      <option value="fuchsia">fuchsia</option>
                      <option value="magenta">magenta</option>
                      <option value="maroon">maroon</option>
                      <option value="mediumblue">mediumblue</option>
                      <option value="navy">navy</option>
                      <option value="olive">olive</option>
                      <option value="orangered">orangered</option>
                      <option value="purple">purple</option>
                      <option value="scarlet">scarlet</option>
                      <option value="sienna">sienna</option>
                      </select></td>Text Color:</td><br>
<input type="text" name="msg">enter text<br>
<input type="submit" value="*Enter*">
</form>~;

##############################
# add.cgi:::                   #
##############################

use CGI;
my $q = new CGI;

open (MSG, ">>messages.txt");
print MSG "\n"
   . $q->param('ip') . ":::" . $q->param('name') . ":::" . $q->param('password') . ":::" .$q->param('user_stripped') . ":::" . $q->param('CHATCOLOR') . ":::" . $q->param('refresh_rate') . ":::" . $q->param('histroy') . ":::" . $q->param('nopic') . ":::" . $q->param('verbose') . ":::" . time . ":::" . $q->param('msg');
close (MSG);
Code:
as passd in browser
?name=%3Cimg+src%3D+http%3A%2F%2F[URL unfurl="true"]www.freespaces.com%2Frealitygonewild%2Fwg1.jpg+align%3Dleft%3E%3Ccenter%3E%3C%2Fimg%3E%3Cbr%3E%3Ccenter%3E%3CFONT+FACE%3Dgaramond%3E%3CFONT+COLOR+%3Dsilver%3E%3CFONT+SIZE%3D4%3EWarGod+of++Venna%3Cbr%3E*Administrator*%3C%2Ffont%3E%3Cbr%3E*Never+say+Never*%3Cbr%3E%3CFONT+COLOR+%3Dsilver%3E%3CFONT+SIZE%3D4%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.chatvenues.com+target%3D_window%3EChat+Venues%3C%2Fa%3E%3Cbr%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.geocities.com%2Fresortofvenna%2Findex.htmltarget%3D_window%3EVenna%3C%2Fa%3E%3CFONT+COLOR+%3Dblue%3E%3CFONT+SIZE%3D3%3E%3Ccenter%3E&password=MYPASSWORD&refresh_rate=10&histroy=10&nopic=1&verbose=1&CHATCOLOR=purple&msg=Help[/URL]

as writen to file messages.txt
Code:
:::<img src= [URL unfurl="true"]http://www.freespaces.com/realitygonewild/wg1.jpg[/URL] align=left><center></img><br><center><FONT FACE=garamond><FONT COLOR =silver><FONT SIZE=4>WarGod of  Venna<br>*Administrator*</font><br>*Never say Never*<br><FONT COLOR =silver><FONT SIZE=4><a href=[URL unfurl="true"]http://www.chatvenues.com[/URL] target=_window>Chat Venues</a><br><a href=[URL unfurl="true"]http://www.geocities.com/resortofvenna/index.htmltarget=_window>Venna</a><FONT[/URL] COLOR =blue><FONT SIZE=3><center>:::MYPASSWORD:::?thathtmluserstringstripped?:::purple:::10:::10:::1:::1:::1167173680:::Help

ok with each post you have to input your name, color, ect. again and again
How do I make it remember all values but $msg
being that $msg would be newly inputed each post
Do I use a getdata or ???
also I would like to uptain IP and have it print to file where $ip is
and have the html user input stripped and added in this space ?thathtmluserstringstripped?


MA WarGod

I believe if someone can think it, it can be programmed
 
Here is a simple function to strip html characters.
Code:
sub strip_html {
	my $text = shift;
	$text =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
	return $text;
}
to be used like
Code:
my $new_text = strip_html( $old_text );

M. Brooks
 
you should be using post instead of get method with the form data:

<form name="add" action="testi.cgi" method="post">

if you would use the CGI module to generate your form widgets the values will be remembered by default. It's covered in the CGI module documentation.






- Kevin, perl coder unexceptional!
 
Change this
Code:
<form name="add" action="testi.cgi">
to
Code:
<form [b]method="POST"[/b] name="add" action="testi.cgi">

M. Brooks
 
Code:
#!/usr/bin/perl

my $ip_addr = $ENV{'REMOTE_ADDR'};
my $new_text = strip_html( $old_text );
# open messages
open (MSG, "messages.txt");
my @lines = <MSG>;
@lines = reverse @lines;
close (MSG);
chomp @lines;

print "Content-Type: text/html\n\n";
foreach my $line (@lines) {
   my ($ip_addr,$user,$password,$user_stripped,$cc,$rr,$his,$np,$ver,$timestamp,$msg) = split(/:::/, $line, 11);
   print "<TABLE WIDTH='100%' border='0' cellpadding='0' cellspacing='0'><TR><TD><font color=$cc>[$timestamp]<b>$user says:</b>$msg<p></font><P></TD></TR></TABLE>\n\n";
}

# add a form to add a message to the file
print qq~<form method="POST" name="add" action="testi.cgi">
<input type="text" name="name" value="Anonymous" size="20">Name<br>
<input type="text" name="password" size="20">Password<br>
<input type="text" size="2" value="10" name="refresh_rate">refresh<br>
<input type="text" size="2" value="10" name="histroy">histroy<br>
<input type="checkbox" checked="checked" value="1" name="nopic">nopic<br>
<input type="checkbox" checked="checked" value="1" name="verbose">verbose<br>
<td nowrap><select name="CHATCOLOR" size="1">
                      <option value="white" selected>white</option>
                      <option value="blue">blue</option>
                      <option value="blueviolet">blueviolet</option>
                      <option value="chocolate">chocolate</option>
                      <option value="darkgreen">darkgreen</option>
                      <option value="dimgray">dimgray</option>
                      <option value="fuchsia">fuchsia</option>
                      <option value="magenta">magenta</option>
                      <option value="maroon">maroon</option>
                      <option value="mediumblue">mediumblue</option>
                      <option value="navy">navy</option>
                      <option value="olive">olive</option>
                      <option value="orangered">orangered</option>
                      <option value="purple">purple</option>
                      <option value="scarlet">scarlet</option>
                      <option value="sienna">sienna</option>
                      </select></td>Text Color:</td><br>
<input type="text" name="msg">enter text<br>
<input type="submit" value="*Enter*">
</form>~;

##############################
# add.cgi:::                   #
##############################

use CGI;
my $q = new CGI;

open (MSG, ">>messages.txt");
print MSG "\n"
   . $q->param('ip_addr') . ":::" . $q->param('name') . ":::" . $q->param('password') . ":::" .$q->param('user_stripped') . ":::" . $q->param('CHATCOLOR') . ":::" . $q->param('refresh_rate') . ":::" . $q->param('histroy') . ":::" . $q->param('nopic') . ":::" . $q->param('verbose') . ":::" . time . ":::" . $q->param('msg');
close (MSG);

sub strip_html {
    my $text = shift;
    $text =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
    return $text;
}

ok and strip_html replaces user_stripped?

MA WarGod

I believe if someone can think it, it can be programmed
 
Code:
##############################
# add.cgi:::                   #
##############################

use CGI;
my $q = new CGI;
my $ip_addr = $ENV{'REMOTE_ADDR'};
my $new_text = strip_html( $old_text );
open (MSG, ">>/home/chatvenu/public_html/scgi-bin/mychat/messages.txt");
print MSG "\n"
   . $q->param('ip_addr') . ":::" . $q->param('name') . ":::" . $q->param('password') . ":::" .$q->param('new_text') . ":::" . $q->param('CHATCOLOR') . ":::" . $q->param('refresh_rate') . ":::" . $q->param('histroy') . ":::" . $q->param('nopic') . ":::" . $q->param('verbose') . ":::" . time . ":::" . $q->param('msg');
close (MSG);

sub strip_html {
    my $text = shift;
    $text =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
    return $text;
}

MA WarGod

I believe if someone can think it, it can be programmed
 
Code:
print MSG "\n"
   . $ip_addr . ":::" . $q->param('name') . ":::" . $q->param('password') . ":::" .$q->param('&strip_html') . ":::" . $q->param('CHATCOLOR') . ":::" . $q->param('refresh_rate') . ":::" . $q->param('histroy') . ":::" . $q->param('nopic') . ":::" . $q->param('verbose') . ":::" . time . ":::" . $q->param('msg');
close (MSG);

ok figured out how get ip to print

MA WarGod

I believe if someone can think it, it can be programmed
 
that probably should be:

Code:
print MSG "\n"
   . $ip_addr . ":::" . $q->param('name') . ":::" . $q->param('password') . ":::" . [b]strip_html($q->param('user_stripped'))[/b] . ":::" . $q->param('CHATCOLOR') . ":::" . $q->param('refresh_rate') . ":::" . $q->param('histroy') . ":::" . $q->param('nopic') . ":::" . $q->param('verbose') . ":::" . time . ":::" . $q->param('msg');
close (MSG);


- Kevin, perl coder unexceptional!
 
how do I get $user_stripped to equel $user but be stripped of the html

Code:
as passd in browser
?name=%3Cimg+src%3D+http%3A%2F%2F[URL unfurl="true"]www.freespaces.com%2Frealitygonewild%2Fwg1.jpg+align%3Dleft%3E%3Ccenter%3E%3C%2Fimg%3E%3Cbr%3E%3Ccenter%3E%3CFONT+FACE%3Dgaramond%3E%3CFONT+COLOR+%3Dsilver%3E%3CFONT+SIZE%3D4%3EWarGod+of++Venna%3Cbr%3E*Administrator*%3C%2Ffont%3E%3Cbr%3E*Never+say+Never*%3Cbr%3E%3CFONT+COLOR+%3Dsilver%3E%3CFONT+SIZE%3D4%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.chatvenues.com+target%3D_window%3EChat+Venues%3C%2Fa%3E%3Cbr%3E%3Ca+href%3Dhttp%3A%2F%2Fwww.geocities.com%2Fresortofvenna%2Findex.htmltarget%3D_window%3EVenna%3C%2Fa%3E%3CFONT+COLOR+%3Dblue%3E%3CFONT+SIZE%3D3%3E%3Ccenter%3E&password=MYPASSWORD&refresh_rate=10&histroy=10&nopic=1&verbose=1&CHATCOLOR=purple&msg=Help[/URL]

Code:
209.34.12.0:::<img src= [URL unfurl="true"]http://www.freespaces.com/realitygonewild/wg1.jpg[/URL] align=left><center></img><br><center><FONT FACE=garamond><FONT COLOR =silver><FONT SIZE=4>WarGod of  Venna<br>*Administrator*</font><br>*Never say Never*<br><FONT COLOR =silver><FONT SIZE=4><a href=[URL unfurl="true"]http://www.chatvenues.com[/URL] target=_window>Chat Venues</a><br><a href=[URL unfurl="true"]http://www.geocities.com/resortofvenna/index.htmltarget=_window>Venna</a><FONT[/URL] COLOR =blue><FONT SIZE=3><center>:::MYPASSWORD:::?thathtmluserstringstripped?:::purple:::10:::10:::1:::1:::1167173680:::Help
Code:
#!/usr/bin/perl


# open messages
open (MSG, "messages.txt");
my @lines = <MSG>;
@lines = reverse @lines;
close (MSG);
chomp @lines;

print "Content-Type: text/html\n\n";
foreach my $line (@lines) {
   my ($ip_addr,$user,$password,$user_stripped,$cc,$rr,$his,$np,$ver,$timestamp,$msg) = split(/:::/, $line, 11);
   print "<TABLE WIDTH='100%' border='0' cellpadding='0' cellspacing='0'><TR><TD><font color=$cc>[$timestamp]<b>$user says:</b>$msg<p></font><P></TD></TR></TABLE>\n\n";
}
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
# add a form to add a message to the file
print qq~<form method="POST" name="add" action="testi.cgi">
<input type="text" name="name" value="Anonymous" size="20">Name<br>
<input type="text" name="password" size="20">Password<br>
<input type="text" size="2" value="10" name="refresh_rate">refresh<br>
<input type="text" size="2" value="10" name="histroy">histroy<br>
<input type="checkbox" checked="checked" value="1" name="nopic">nopic<br>
<input type="checkbox" checked="checked" value="1" name="verbose">verbose<br>
<td nowrap><select name="CHATCOLOR" size="1">
                      <option value="white" selected>white</option>
                      <option value="blue">blue</option>
                      <option value="blueviolet">blueviolet</option>
                      <option value="chocolate">chocolate</option>
                      <option value="darkgreen">darkgreen</option>
                      <option value="dimgray">dimgray</option>
                      <option value="fuchsia">fuchsia</option>
                      <option value="magenta">magenta</option>
                      <option value="maroon">maroon</option>
                      <option value="mediumblue">mediumblue</option>
                      <option value="navy">navy</option>
                      <option value="olive">olive</option>
                      <option value="orangered">orangered</option>
                      <option value="purple">purple</option>
                      <option value="scarlet">scarlet</option>
                      <option value="sienna">sienna</option>
                      </select></td>Text Color:</td><br>
<input type="text" name="msg">entery text<br>
<input type="submit" value="*Enter*">
</form>~;


##############################
# add.cgi:::                   #
##############################

use CGI;
my $q = new CGI;
my $ip_addr = $ENV{'REMOTE_ADDR'};
my $new_text = strip_html( $old_text );
open (MSG, ">>messages.txt");
print MSG "\n"
   . $ip_addr . ":::" . $q->param('name') . ":::" . $q->param('password') . ":::" . strip_html($q->param('user_stripped')) . ":::" . $q->param('CHATCOLOR') . ":::" . $q->param('refresh_rate') . ":::" . $q->param('histroy') . ":::" . $q->param('nopic') . ":::" . $q->param('verbose') . ":::" . time . ":::" . $q->param('msg');
close (MSG);

sub strip_html {
    my $text = shift;
    $text =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
    return $text;
}

also how do I form this to remember all values but $msg each post so that user doesn't fill in name, color ect.

this is kinda what I am trying to do
Code:
print qq~<font color=$cc>welcome<b>$user_stripped</b><form method="POST" name="add" action="testi.cgi">
<input type="hidden" name="name" value="$user">
<input type="hidden" name="name" value="$user_stripped">
<input type="hidden" name="password"value="$password">
<input type="hidden" name="refresh_rate" value="$rr">
<input type="hidden" name="histroy" value="$his">
<input type="hidden" name="nopic" value="$np">
<input type="hidden" name="verbose" value="$ver">
<input type="hidden" name="CHATCOLOR" value="$cc">                  
<input type="text" name="msg">enter text<br>
<input type="submit" value="*Enter*">
</form>~;

and make this like login.cgi or login sub or ?
Code:
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
# add a form to add a message to the file
print qq~<form method="POST" name="add" action="testi.cgi">
<input type="text" name="name" value="Anonymous" size="20">Name<br>
<input type="text" name="password" size="20">Password<br>
<input type="text" size="2" value="10" name="refresh_rate">refresh<br>
<input type="text" size="2" value="10" name="histroy">histroy<br>
<input type="checkbox" checked="checked" value="1" name="nopic">nopic<br>
<input type="checkbox" checked="checked" value="1" name="verbose">verbose<br>
<td nowrap><select name="CHATCOLOR" size="1">
                      <option value="white" selected>white</option>
                      <option value="blue">blue</option>
                      <option value="blueviolet">blueviolet</option>
                      <option value="chocolate">chocolate</option>
                      <option value="darkgreen">darkgreen</option>
                      <option value="dimgray">dimgray</option>
                      <option value="fuchsia">fuchsia</option>
                      <option value="magenta">magenta</option>
                      <option value="maroon">maroon</option>
                      <option value="mediumblue">mediumblue</option>
                      <option value="navy">navy</option>
                      <option value="olive">olive</option>
                      <option value="orangered">orangered</option>
                      <option value="purple">purple</option>
                      <option value="scarlet">scarlet</option>
                      <option value="sienna">sienna</option>
                      </select></td>Text Color:</td><br>
<input type="text" name="msg">entery text<br>
<input type="submit" value="*Enter*">
</form>~;



MA WarGod

I believe if someone can think it, it can be programmed
 
Code:
$user_stripped = strip_html($user);

- Kevin, perl coder unexceptional!
 
$user_stripped = strip_html($user);

so do I use this as
my $user_stripped = strip_html($user);

????

MA WarGod

I believe if someone can think it, it can be programmed
 
If you are getting an error then you have to use "my" when declaring the variable.

- Kevin, perl coder unexceptional!
 
OMG I get it

I am not stripping user_stripped I am stripping name

Code:
use CGI;
my $q = new CGI;
my $ip_addr = $ENV{'REMOTE_ADDR'};
my $new_text = strip_html( $old_text );
$user_stripped = strip_html($user);

open (MSG, ">>/home/chatvenu/public_html/scgi-bin/mychat/messages.txt");
print MSG "\n"
   . $ip_addr . ":::" . $q->param('name') . ":::" . $q->param('password') . ":::" . strip_html($q->param('name')) . ":::" . $q->param('CHATCOLOR') . ":::" . $q->param('refresh_rate') . ":::" . $q->param('histroy') . ":::" . $q->param('nopic') . ":::" . $q->param('verbose') . ":::" . time . ":::" . $q->param('msg');
close (MSG);
open (WHO, ">>/home/chatvenu/public_html/scgi-bin/mychat/userlog.who");
print WHO "\n"
   . $ip_addr . ":::" . strip_html($q->param('name'));
close (WHO);
sub strip_html {
    my $text = shift;
    $text =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
    return $text;
}

Thank You Kevin and Mbrooks

now if I can get it to remember user's and variable from post to post

MA WarGod

I believe if someone can think it, it can be programmed
 
>> now if I can get it to remember user's and variable from post to post

see my post: 26 Dec 06 18:55

- Kevin, perl coder unexceptional!
 
Kevin by posting that url You helped Me alot I put to fav's

but I think by reading it I need to use
Code:
 $user = url_param('name');
 $user_stripped = url_param ('user_stripped');
 $rr = url_param('refresh_rate');
 $his = url_param('histroy');
 $np = url_param('nopic');
 $ver = url_param('verbose');
 $cc = url_param('CHATCOLOR');
is this correct is this what you referred too?
trying to make this work not sure how to from it yet

MA WarGod

I believe if someone can think it, it can be programmed
 
wrong again?

MA WarGod

I believe if someone can think it, it can be programmed
 
read the section about "creating fill out forms". Thats the part I linked you to. You use the CGI module to generate your form as well as parse the form data. There is also an example at the very end of the page.

CREATING FILL-OUT FORMS:

General note The various form-creating methods all return strings to the caller, containing the tag or tags that will create the requested form element. You are responsible for actually printing out these strings. It's set up this way so that you can place formatting tags around the form elements.

Another note The default values that you specify for the forms are only used the first time the script is invoked (when there is no query string). On subsequent invocations of the script (when there is a query string), the former values are used even if they are blank.


- Kevin, perl coder unexceptional!
 
Kevin with reading that I have come up with this am I on the correct path here?
Code:
&Parse_Form;
$user = $formdata{'name'};
$password = $formdata{'password'};
$cc = $formdata{'CHATCOLOR'};
$rr = $formdata{'refresh_rate'};
$his = $formdata{'histroy'};
$np = $formdata{'nopic'};
$ver = $formdata{'verbose'};
$timestamp = $formdata{'time'};
$msg = $formdata{'msg'};
sub Parse_Form {
	if ($ENV{'REQUEST_METHOD'} eq 'GET') {
		@pairs = split(/&/, $ENV{'QUERY_STRING'});
	} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
		read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
		@pairs = split(/&/, $buffer);
		
		if ($ENV{'QUERY_STRING'}) {
			@getpairs =split(/&/, $ENV{'QUERY_STRING'});
			push(@pairs,@getpairs);
			}
	} else {
		print "Content-type: text/html\n\n";
		print "<P>Use Post or Get";
	}

	foreach $pair (@pairs) {
		($key, $value) = split (/=/, $pair);
		$key =~ tr/+/ /;
		$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	
		$value =~s/<!--(.|\n)*-->//g;
	
		if ($formdata{$key}) {
			$formdata{$key} .= ", $value";
		} else {
			$formdata{$key} = $value;
		}
	}
}	
1;


MA WarGod

I believe if someone can think it, it can be programmed
 
but I am trying to bring values in as hidden

Code:
# open messages
open (MSG, "messages.txt");
my @lines = <MSG>;
@lines = reverse @lines;
close (MSG);
chomp @lines;

print "Content-Type: text/html\n\n";
foreach my $line (@lines) {
   my ($ip_addr,$user,$password,$user_stripped,$cc,$rr,$his,$np,$ver,$timestamp,$msg) = split(/:::/, $line, 11);
   print "<TABLE WIDTH='100%' border='0' cellpadding='0' cellspacing='0'><TR><TD><font color=$cc>[$timestamp]<b>$user says:</b>$msg<p></font><P></TD></TR></TABLE>\n\n";
}


print qq~<font color=$cc>welcome<b>$user_stripped</b><form method="POST" name="add" action="testi.cgi">
<input type="hidden" name="name" value="$user">
<input type="hidden" name="name" value="$user_stripped">
<input type="hidden" name="password"value="$password">
<input type="hidden" name="refresh_rate" value="$rr">
<input type="hidden" name="histroy" value="$his">
<input type="hidden" name="nopic" value="$np">
<input type="hidden" name="verbose" value="$ver">
<input type="hidden" name="CHATCOLOR" value="$cc">                  
<input type="text" name="msg">enter text<br>
<input type="submit" value="*Enter*">
</form>~;
I can get the values to print to page but cann't figure out how to from this please help

MA WarGod

I believe if someone can think it, it can be programmed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top