CGI / postprocess of values

C

cwpbl

Hello,

I have a very simple test.cgi program, using CGI.pm wich display a
textfield.
After the form has been submitted, I have a new url, saying :
http://host/cgi-bin/test.cgi?my_textfield_content=azertyu

OK.
Now, I want the value of my_textfield_content appear as an encoded
string, in the url, something like
http://host/cgi-bin/test.cgi?my_textfield_content=VgHo98km==

I have already written the (de)(en)coding function.
But how can I call this encoding function to have value of
my_text_field_content modified ?
 
C

cwpbl

Le 08/01/2013 23:24, Ben Morrow a écrit :
Why?

(This is not a stupid question. What are you trying to do that makes you
think you need this?)

1. I need a url which does not contains some characters (like |) because
these url , entered in a wiki (dokuwiki), are not interpreted correctly.
2. url are send to some users. I do not want they modify these url (easy
to do if in clear).
I hope you mean 'I have already found MIME::Base64, and I know how to
use it'.
I use 8bits -> 7bits + encode_base64.

sub cps {
my $bstr = unpack('B*', $_[0]);
$bstr =~ s/.(.{7})/$1/g;
return pack('B*', $bstr);
}

sub ec{
return encode_base64(cps($_[0]),"");
}

The problem is : where call ec ?
 
J

Justin C

Le 08/01/2013 23:24, Ben Morrow a écrit :

1. I need a url which does not contains some characters (like |) because
these url , entered in a wiki (dokuwiki), are not interpreted correctly.

I think you have two options. You receive whatever characters the user
wants to submit, and then you tidy the information how you want when
you receive it, or you write some javascript that does the change when
the user clicks submit, the script does the submit after doing the
changes to the string - the problem with this is that any user with
half a clue will see what your code does and, if they so desire will
still find a way of submitting what they want.

2. url are send to some users. I do not want they modify these url (easy
to do if in clear).

Security through obscurity is no security at all.
I hope you mean 'I have already found MIME::Base64, and I know how to
use it'.
I use 8bits -> 7bits + encode_base64.

sub cps {
my $bstr = unpack('B*', $_[0]);
$bstr =~ s/.(.{7})/$1/g;
return pack('B*', $bstr);
}

sub ec{
return encode_base64(cps($_[0]),"");
}

The problem is : where call ec ?

Call it when you receive the form back from the user.


Justin.
 
C

cwpbl

Le 08/01/2013 22:40, Henry Law a écrit :
This is intrinsically what the "submit" function does; it sends to the
server program the value of the field in the form.


Unless you write some local code (javascript or whatever) to encode the
contents of "textfield" /before/ submission then it will be sent off
unencoded.

I think I have understood your question. But it would be better if you
post test.cgi, so we can see what you're doing.
Thank you,
here are the interesting parts of the script :

use CGI;
....
my $filter = $q->param('filter') || ".";
....
sub cps {
my $bstr = unpack('B*', $_[0]);
$bstr =~ s/.(.{7})/$1/g;
return pack('B*', $bstr);
}

sub ec{
return encode_base64(cps($_[0]),"");
}
....
my $q = new CGI;
print
$q->header( "text/html" ),
$q->start_html( ... );
....
print
$q->start_form(-action=>"", -method=>'GET', name=>'filter_form' ),
$q->textfield(-name=>'filter',-default=>"", -size=>20),
$q->submit(-name=> "filter_btn", -value=>"OK"),
$q->end_form();
[...]
print
$q->table( ... ),
$q->end_html();


I want to have the value of filter param modified ( with ec funtion) in
the new url. How "insert" this processing in the script ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top