[29862] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1105 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 11 16:10:12 2007

Date: Tue, 11 Dec 2007 13:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 11 Dec 2007     Volume: 11 Number: 1105

Today's topics:
    Re: "use constant X=>(1,2);" or "use constant X=>[1,2]; <bik.mido@tiscalinet.it>
    Re: comparing binary strings <bik.mido@tiscalinet.it>
    Re: How to execute tar inside a perl script ? <josef.moellers@fujitsu-siemens.com>
    Re: Information I hope will be passed to Larry Wall <bik.mido@tiscalinet.it>
        multiple return regex question vorticitywolfe@gmail.com
        Regex without assignment <gur.tom@gmail.com>
    Re: Regex without assignment <mritty@gmail.com>
    Re: Regex without assignment <jurgenex@hotmail.com>
    Re: Regex without assignment <gur.tom@gmail.com>
        regexp and binary values <teknet7@poczta.onet.pl>
    Re: regexp and binary values <peter@makholm.net>
    Re: regexp and binary values <ben@morrow.me.uk>
    Re: regexp and binary values <teknet7@poczta.onet.pl>
    Re: regexp and binary values <abigail@abigail.be>
    Re: regexp and binary values <cwilbur@chromatico.net>
    Re: regexp and binary values <jurgenex@hotmail.com>
        Session Problem in Perl <visitprakashindia@gmail.com>
    Re: Session Problem in Perl <rkb@i.frys.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 11 Dec 2007 17:29:06 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: "use constant X=>(1,2);" or "use constant X=>[1,2];"?
Message-Id: <6ketl3d24sh7d3velqgc1q8jnd4lh0ff1f@4ax.com>

On Mon, 10 Dec 2007 14:46:42 -0800 (PST), TonyV
<kingskippus@gmail.com> wrote:

>Actually, what I read a long time ago was O'Reilly's "Perl Best
>Practices," section 4.5: Use named constants, but don't use
>"constant".  (I.e. the constant pragma.)  It follows with several good

Actually, many experienced and knowledgeable hackers beg to differ
with some PBP item or another: after all it's just a list of
suggestions. While some of the points they make are perfectly fine,
constant.pm *does* have its use.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Tue, 11 Dec 2007 21:18:04 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: comparing binary strings
Message-Id: <03stl3905dbg7fepnvnp5q4cqhgtbqc74c@4ax.com>

On 10 Dec 2007 22:03:43 GMT, Joost Diepenmaat <joost@zeekat.nl> wrote:

>I'll give it a shot in the latest blead perl (once I've got and compiled 
>it) to see what's what.

No need for blead. 5.10 beta is out - or is that still "blead"?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Tue, 11 Dec 2007 12:35:35 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to execute tar inside a perl script ?
Message-Id: <fjlsm9$a7t$1@nntp.fujitsu-siemens.com>

Martijn Lievaart wrote:
> On Tue, 11 Dec 2007 09:07:01 +0100, Josef Moellers wrote:
>=20
>=20
>>Ben Morrow wrote:
>>
>>>Quoth Joost Diepenmaat <joost@zeekat.nl>:
>>>
>>>
>>>>On Mon, 10 Dec 2007 21:44:01 +0000, Ben Morrow wrote:
>>>>
>>>>
>>>>
>>>>>Quoth Joost Diepenmaat <joost@zeekat.nl>:
>>>>>
>>>>>
>>>>>>On Mon, 10 Dec 2007 14:39:12 -0600, aaah wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>This is a correct, but it's prob worth expanding on this slightly =
to
>>>>>>>get you going, from within your code, try the following:
>>>>>>>
>>>>>>>my $tar_cmd =3D "tar czvf "/usr/local/myname/$tarfile"  ./*.php" ;=

>>>>>>
>>>>>>That's not valid perl. You probably mean
>>>>>>
>>>>>>my $tar_cmd =3D "tar czvf /usr/local/myname/$tarfile ./*.php" ;
>>>>>
>>>>>No, he probably meant
>>>>>
>>>>>   my $tar_cmd =3D qq{tar czvf "/usr/local/myname/$tarfile" ./*.php}=
;
>>>>
>>>>Which won't work, because it won't interpolate ./*.php. Which sort of=

>>>>proves both our points :-)
>>>
>>>
>>>Yes it will. That is, ./*.php will be passed literally to the shell,
>>>which will then expand it before calling tar. This is why $tarfile
>>>needs two levels of quoting, with qq{} (for Perl) and "" (for the
>>>shell).
>>
>>(Stomping the ground with the foot) No it won't:
>>
>>The list form of system will bypass the shell: josef@bounty:/usr/lib>
>>perl
>>system("ls", "*");
>>ls: *: No such file or directory
>>
>>Hence, no expansion will take place.
>=20
>=20
> It's no list, it's a single string with wildcard characters, hence it=20
> will be passed to the shell and it will be expanded.
>=20
> # perl -e 'system qq{ls *}'
> <snip listing of files>

Sorry, you're right, I mixed up both examples in Ben's reply and didn't=20
notice the globbing operator in this section:

It would be *much* better to use the list form
of system: it avoids all these nasty quoting issues, including the one
you haven't noticed yet when you have a file 'My Script.php'.

     system tar =3D> czvf =3D> "/usr/local/myname/$tarfile", <*.php>;

--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=C3=B6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html



------------------------------

Date: Tue, 11 Dec 2007 16:36:23 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Information I hope will be passed to Larry Wall
Message-Id: <08btl3tts49uitg5g57g17gpn53q9dbktc@4ax.com>

On Mon, 10 Dec 2007 09:19:33 +0000 (UTC), George Peter Staplin
<georgepsSPAMMENOT@xmission.com> wrote:

>Unfortunately it seems Larry Wall is lying about several aspects of Tcl 
>in his recent article on perl.com

I think you'll find that Larry Wall is a very fine and knowledgeable
person, but he's not perfect. If he claimed something that turns out
not to be true about Tcl, I could bet quite about anything that it was
not to spread fud about it, but just due to misinformation. And he's
shown on several occasions to be able to change his mind. You can
write to him directly, rather than ranting here.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Tue, 11 Dec 2007 13:04:36 -0800 (PST)
From: vorticitywolfe@gmail.com
Subject: multiple return regex question
Message-Id: <f4fe98a6-004a-47d7-b4ff-d22c0b76609b@t1g2000pra.googlegroups.com>

Hello,

I have a string like such  "STAT 09834Z 12004KT VV001 BKN150 OVC220
A3025 T00281039"

I want to grab the VV001 BKN150 and OVC220 part in different variables
$1, $2, $3, etc..

I am parsing the string with this regex:

@return =  m/((VV|BKN|OVC)\d{2,4})/g;

and print with

for(@return){print $_,"\n";}

Why does it return:
VV001
VV
BKN150
BKN
OVC250
OVC

?
in the regex I think it's somewhat explicit in keeping the first 2 or
3 characters together and then keeping the rest appended, but perhaps
I'm misinterpreting what it's doing.  Any help would be appreciated.

Thank you!
Jonathan


------------------------------

Date: Tue, 11 Dec 2007 07:17:07 -0800 (PST)
From: Tom Gur <gur.tom@gmail.com>
Subject: Regex without assignment
Message-Id: <0522ebf3-3ac9-4fdd-a471-300a3ecd998d@o42g2000hsc.googlegroups.com>

Hi,

is there a way for me to use a regex without assignment ?

e.g:
Lets say I have: $filepath = "/dir_a/dir_b/";
and a function: &accept_only_backslashes(); that as the name implies -
accept only backslashes

right now, the only way I can use regex to help is:
$temp = $filepath;
$filepath =~ s/\//\\/g
&accept_only_backslashes($filepath);
$filepath = $temp;

this is very ugly.
is there a way to just send the value of the substitution, without
actually changing the variable ?

Thanks,
Tom




------------------------------

Date: Tue, 11 Dec 2007 07:45:13 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Regex without assignment
Message-Id: <444ce644-eae1-4a9b-944e-dc5fc0fa52d4@r1g2000hsg.googlegroups.com>

On Dec 11, 10:17 am, Tom Gur <gur....@gmail.com> wrote:

> is there a way for me to use a regex without assignment ?
>
> e.g:
> Lets say I have: $filepath = "/dir_a/dir_b/";
> and a function: &accept_only_backslashes(); that as the name
> implies - accept only backslashes
>
> right now, the only way I can use regex to help is:
> $temp = $filepath;
> $filepath =~ s/\//\\/g
> &accept_only_backslashes($filepath);
> $filepath = $temp;
>
> this is very ugly.
> is there a way to just send the value of the substitution, without
> actually changing the variable ?

If you perform a s/// on an assignment expression, only the new
variable is changed, not the original.  So you could change the above
to:
(my $temp = $filepath) =~ s#/#\\#g;
accept_only_backslashes($temp);

$filepath will not be changed at all.

Paul Lalli


------------------------------

Date: Tue, 11 Dec 2007 15:53:56 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regex without assignment
Message-Id: <ooy7j.1639$sf.1316@trndny04>

Tom Gur wrote:
> is there a way for me to use a regex without assignment ?

A regular expression does not do any assignments (except for the 
backreferences or capturing of course).

> e.g:
> Lets say I have: $filepath = "/dir_a/dir_b/";
> and a function: &accept_only_backslashes(); that as the name implies -
> accept only backslashes
>
> right now, the only way I can use regex to help is:
> $temp = $filepath;
> $filepath =~ s/\//\\/g

The only regular expression in the line above is /\//. On top of that you 
are doing a substitution and a binding. I don't see any assignment.

> &accept_only_backslashes($filepath);

Do you know what the & does and are you sure you want that semantic?

> $filepath = $temp;
>
> this is very ugly.
> is there a way to just send the value of the substitution, without
> actually changing the variable ?

Ohhhhhhh, you were talking about the s operator the whole time, not about 
regular expressions? Then why on earth were you dangling that red herring 
and ranting about REs all the time?

And no, both operator, s/// as well as tr///, will modify their argument 
rather then returning the new string as a result.
However you can somewhat simplify your code by tying the substitution to 
$tmp and passing that string as argument to the function call. Then you 
don't need that second assignment to restore the original value.

jue 




------------------------------

Date: Tue, 11 Dec 2007 08:14:44 -0800 (PST)
From: Tom Gur <gur.tom@gmail.com>
Subject: Re: Regex without assignment
Message-Id: <8aea4e2a-689a-4aaa-b9b0-1211069fe30c@w28g2000hsf.googlegroups.com>

On Dec 11, 5:45 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Dec 11, 10:17 am, Tom Gur <gur....@gmail.com> wrote:
>
>
>
> > is there a way for me to use a regex without assignment ?
>
> > e.g:
> > Lets say I have: $filepath = "/dir_a/dir_b/";
> > and a function: &accept_only_backslashes(); that as the name
> > implies - accept only backslashes
>
> > right now, the only way I can use regex to help is:
> > $temp = $filepath;
> > $filepath =~ s/\//\\/g
> > &accept_only_backslashes($filepath);
> > $filepath = $temp;
>
> > this is very ugly.
> > is there a way to just send the value of the substitution, without
> > actually changing the variable ?
>
> If you perform a s/// on an assignment expression, only the new
> variable is changed, not the original.  So you could change the above
> to:
> (my $temp = $filepath) =~ s#/#\\#g;
> accept_only_backslashes($temp);
>
> $filepath will not be changed at all.
>
> Paul Lalli

Thanks a lot !


------------------------------

Date: Tue, 11 Dec 2007 13:13:52 +0100
From: vertigo <teknet7@poczta.onet.pl>
Subject: regexp and binary values
Message-Id: <op.t256xejpmv59ja@pluton>

Hello

I have a place in code:
if ($_ =3D~ /$myvariable/){....}

the problem is that $myvariable is supplied by the user and malicius use=
r
can give me binary code or code with special characters.
How can i treat all characters in $myvariable as strings ?
(when special variables are provided my program fails like this:
Unmatched ) in regex; marked by <-- HERE in m/ GET /?showimage=3D') <-- =
HERE  =

%20UNION%20SELECT%20'pixelpost_15rc1.nasl-1196815102.jpg'%20as%20id%2c%2=
01625282529%20as%20headline%2c%20820629856%20as%20datetime%2c%2017817486=
84%20as%20body%2c%201300225929%20as%20category%2c%201242744851%20as%20im=
age/*  =

HTTP/1.1/ at /root/skrypty/raportweb_h1.pl line 20, <FILEALL> line 1.
)

Thanx

-


------------------------------

Date: Tue, 11 Dec 2007 12:27:00 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: regexp and binary values
Message-Id: <87odcx8lij.fsf@hacking.dk>

vertigo <teknet7@poczta.onet.pl> writes:

> Hello
>
> I have a place in code:
> if ($_ =~ /$myvariable/){....}
>
> the problem is that $myvariable is supplied by the user and malicius user
> can give me binary code or code with special characters.
> How can i treat all characters in $myvariable as strings ?

You'll have to quote the variable with an \Q. 

  if (/\Q$myvariable/)  {
      ...
  }

Read 'perldoc perlre' for more inforamtion.

//Makholm



------------------------------

Date: Tue, 11 Dec 2007 12:26:35 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: regexp and binary values
Message-Id: <r8c235-ro1.ln1@osiris.mauzo.dyndns.org>


Quoth vertigo <teknet7@poczta.onet.pl>:
> Hello
> 
> I have a place in code:
> if ($_ =~ /$myvariable/){....}
> 
> the problem is that $myvariable is supplied by the user and malicius user
> can give me binary code or code with special characters.
> How can i treat all characters in $myvariable as strings ?

See \Q in perlop or quotemeta in perlfunc.

Ben



------------------------------

Date: Tue, 11 Dec 2007 13:36:37 +0100
From: vertigo <teknet7@poczta.onet.pl>
Subject: Re: regexp and binary values
Message-Id: <op.t257zbr9mv59ja@pluton>



> vertigo <teknet7@poczta.onet.pl> writes:
>
>> Hello
>>
>> I have a place in code:
>> if ($_ =3D~ /$myvariable/){....}
>>
>> the problem is that $myvariable is supplied by the user and malicius =
 =

>> user
>> can give me binary code or code with special characters.
>> How can i treat all characters in $myvariable as strings ?
>
> You'll have to quote the variable with an \Q.
>
>   if (/\Q$myvariable/)  {
>       ...
>   }
>
> Read 'perldoc perlre' for more inforamtion.
>
> //Makholm
>

thanx! it's working :)


------------------------------

Date: 11 Dec 2007 12:37:24 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: regexp and binary values
Message-Id: <slrnflt144.6gm.abigail@alexandra.abigail.be>

                                          _
vertigo (teknet7@poczta.onet.pl) wrote on VCCXV September MCMXCIII in
<URL:news:op.t256xejpmv59ja@pluton>:
__  Hello
__  
__  I have a place in code:
__  if ($_ =~ /$myvariable/){....}
__  
__  the problem is that $myvariable is supplied by the user and malicius user
__  can give me binary code or code with special characters.
__  How can i treat all characters in $myvariable as strings ?


You do that with \Q as answered by others.

But if all you want to know is whether $myvariable appears in $_,
you might use index() instead of a regexp:

    if (index ($_, $myvariable) >= 0) { ... }


Abigail
-- 
perl -swleprint -- -_='Just another Perl Hacker'


------------------------------

Date: 11 Dec 2007 10:00:17 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: regexp and binary values
Message-Id: <87ir358ef2.fsf@mithril.chromatico.net>

>>>>> "v" == vertigo  <teknet7@poczta.onet.pl> writes:

    v> Hello I have a place in code: if ($_ =~ /$myvariable/){....}

    v> the problem is that $myvariable is supplied by the user and
    v> malicius user can give me binary code or code with special
    v> characters.  How can i treat all characters in $myvariable as
    v> strings ?  

If you're just looking to see if what's in $myvariable is a substring
of $_, why bother with a regular expression?  perldoc -f index

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: Tue, 11 Dec 2007 16:02:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: regexp and binary values
Message-Id: <Hwy7j.21801$Bg7.6591@trndny07>

vertigo wrote:
> Hello
>
> I have a place in code:
> if ($_ =~ /$myvariable/){....}
>
> the problem is that $myvariable is supplied by the user and malicius
> user can give me binary code or code with special characters.
> How can i treat all characters in $myvariable as strings ?

So you are using a chainsaw and are asking how to disable the motor such 
that is doesn't cut as fast. Yes, you can do that by pulling the spark plug, 
also known as quotemeta or \Q...\E.
However the better solution seems be to use a more fitting tool like a hand 
saw in the first place, see 'perldoc -f index'.

jue 




------------------------------

Date: Tue, 11 Dec 2007 07:55:20 -0800 (PST)
From: Praki <visitprakashindia@gmail.com>
Subject: Session Problem in Perl
Message-Id: <80d17a9b-ecd6-4f42-9030-43491e27f0fd@t1g2000pra.googlegroups.com>

Greetings All,

i m creating a session storing the loging credentials. i want to
access that data later after crossing two pages.i have created the
sesion but i could not get the data back some where i m going wrong
can u point me where ..

my first first file getting the login credentials

#!/usr/local/bin/perl5
&top();
&login_check();
&bottom();
sub top{
print <<EOM1;
Content-type: text/html


<html>
  <head>
    <title>Login Authentication</title>
  </head>
<body>
EOM1
}
sub bottom{
print <<EOM2;
</body>
</html>
EOM2
}
sub login_check{
print <<EOM;
<h3>Enter the login Password</h3>
<form  method="post" action="cookie.cgi">
<input type="hidden" name="username"  value='Submit'>
<p>Username: <input type="text" name="uid" size="20"></p>
<p>Password: <input type="password" name="passwd" size="20"></p>
<input type="submit" value="Submit" name="submit">
</form>
EOM
}

second file where i m creating the session.

#!/usr/local/bin/perl5
use Net::LDAP;
&top();
&login_check();
&bottom();

sub top{
  print <<EOM1;
Content-type: text/html


<html>
  <head>
    <title>Login Authentication</title>
  </head>
<body>
EOM1
}
sub bottom{
  print <<EOM2;
</body>
</html>
EOM2
}
sub login_check{
  my ($ret);
  use CGI;
  my $query = new CGI;
  $query->param("submit");
  my $userid = $query->param("uid");
  my $password = $query->param("passwd");
use CGI;
use CGI::Session;

$session = new CGI::Session("driver:File",undef,{'Directory'=>"/
tmp"});
$sid = $session->id();
print "Session id:".$sid;

#$session->name($userid);
# Write the session variable on the server
$session->param('username',$userid);
$session->param('password',$password);
print "username:".$userid."pass:";

$usernam = $session->param('username');
$passwor = $session->param('password');

print "username from the cookie:".$usernam;

#create session cookie
$cookie = $query->cookie(CGISESSID => $session->id);
print $query->header( -cookie=>$cookie );
#print "cookie:".$cookie;
   print <<EOM;
      <h5>Cookie created  <a href="/cgi-bin/sesion/cookie/
test.cgi">click here to check</a> </h5>
EOM
}

Third file to access the session values.

#!/usr/local/bin/perl5
&top();
&cookie_check();
&bottom();
sub top{
print <<EOM1;
Content-type: text/html


<html>
  <head>
    <title>Login Authentication</title>
  </head>
<body>
EOM1
}
sub bottom{
print <<EOM2;
</body>
</html>
EOM2
}
sub cookie_check{
use CGI;
use CGI::Session;
my $query = new CGI;

$sid = $query->cookie('CGISESSID') || $query->param('CGISESSID') ||
undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
$username = $session->param('username');
$password = $session->param('password');

print <<EOM;
<h3>Cookie test  $username $password</h3>
EOM
}

i m not getting the values when  i read here. i dont know where the
cookie is created. i check with the server i  could see the session
which is created in the server.please tell me where i m going
wrong.....

thanks in advance..
Prakash


------------------------------

Date: Tue, 11 Dec 2007 12:41:18 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Session Problem in Perl
Message-Id: <a8601001-9048-4d01-b933-2df7b18d3dd9@b1g2000pra.googlegroups.com>

On Dec 11, 7:55 am, Praki <visitprakashin...@gmail.com> wrote:
> Greetings All,
>
> i m creating a session storing the loging credentials. i want to
> access that data later after crossing two pages.i have created the
> sesion but i could not get the data back some where i m going wrong
> can u point me where ..
>
> my first first file getting the login credentials
>
> #!/usr/local/bin/perl5
> &top();
> &login_check();
> &bottom();
> sub top{
> print <<EOM1;
> Content-type: text/html
>
> <html>
>   <head>
>     <title>Login Authentication</title>
>   </head>
> <body>
> EOM1}
>
> sub bottom{
> print <<EOM2;
> </body>
> </html>
> EOM2}
>
> sub login_check{
> print <<EOM;
> <h3>Enter the login Password</h3>
> <form  method="post" action="cookie.cgi">
> <input type="hidden" name="username"  value='Submit'>
> <p>Username: <input type="text" name="uid" size="20"></p>
> <p>Password: <input type="password" name="passwd" size="20"></p>
> <input type="submit" value="Submit" name="submit">
> </form>
> EOM
>
> }
>
> second file where i m creating the session.
>
> #!/usr/local/bin/perl5
> use Net::LDAP;
> &top();
> &login_check();
> &bottom();
>
> sub top{
>   print <<EOM1;
> Content-type: text/html
>
> <html>
>   <head>
>     <title>Login Authentication</title>
>   </head>
> <body>
> EOM1}
>
> sub bottom{
>   print <<EOM2;
> </body>
> </html>
> EOM2}
>
> sub login_check{
>   my ($ret);
>   use CGI;
>   my $query = new CGI;
>   $query->param("submit");
>   my $userid = $query->param("uid");
>   my $password = $query->param("passwd");
> use CGI;
> use CGI::Session;
>
> $session = new CGI::Session("driver:File",undef,{'Directory'=>"/
> tmp"});
> $sid = $session->id();
> print "Session id:".$sid;
>
> #$session->name($userid);
> # Write the session variable on the server
> $session->param('username',$userid);
> $session->param('password',$password);
> print "username:".$userid."pass:";
>
> $usernam = $session->param('username');
> $passwor = $session->param('password');
>
> print "username from the cookie:".$usernam;
>
> #create session cookie
> $cookie = $query->cookie(CGISESSID => $session->id);
> print $query->header( -cookie=>$cookie );
> #print "cookie:".$cookie;
>    print <<EOM;
>       <h5>Cookie created  <a href="/cgi-bin/sesion/cookie/
> test.cgi">click here to check</a> </h5>
> EOM
>
> }
>
> Third file to access the session values.
>
> #!/usr/local/bin/perl5
> &top();
> &cookie_check();
> &bottom();
> sub top{
> print <<EOM1;
> Content-type: text/html
>
> <html>
>   <head>
>     <title>Login Authentication</title>
>   </head>
> <body>
> EOM1}
>
> sub bottom{
> print <<EOM2;
> </body>
> </html>
> EOM2}
>
> sub cookie_check{
> use CGI;
> use CGI::Session;
> my $query = new CGI;
>
> $sid = $query->cookie('CGISESSID') || $query->param('CGISESSID') ||
> undef;
> $session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
> $username = $session->param('username');
> $password = $session->param('password');
>
> print <<EOM;
> <h3>Cookie test  $username $password</h3>
> EOM
>
> }
>
> i m not getting the values when  i read here. i dont know where the
> cookie is created. i check with the server i  could see the session
> which is created in the server.please tell me where i m going
> wrong.....
>
> thanks in advance..
> Prakash

There are a number of issues that should be addressed, but the main
issue is in cookie.cgi.  Your &top sub is outputting headers without
the session cookie and then &login_check tries to output the headers
again, this time with the session cookie, but it's too late.  You can
only send the header once.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1105
***************************************


home help back first fref pref prev next nref lref last post