Reputation: 1492
I am trying to set a cookie using PHP, so it's the same as the one output by the Perl code below:
my %auth;
$auth{'username'} = $username;
$auth{'password'} = $password;
my $wholesaleauth = $co->cookie
(
-name=>'wholesaleauth',
-value=>\%auth,
-expires=>'+1h',
-path=>'/'
);
Now I do not know perl and all and do not want to change the perl code. I need to basically mimic the cookie. When I look at the cookie in my chrome cookie management it says the value is:
password&PASSWORD&username&USERNAME
I am trying to basically mimic that but in PHP.
Upvotes: 0
Views: 808
Reputation: 1492
I was able to get it to work properly but using setrawcookie instead. That would not use percent coding and was able to be identical to the perl set cookie.
Upvotes: 0
Reputation: 118156
I understand you are only trying to port the existing script. However, assuming those are really the user name and password people used to log in to the site, I would say you have a major security hole.
Other than that:
#!/usr/bin/perl
use strict; use warnings;
use CGI::Cookie;
my %auth;
$auth{'username'} = 'not safe';
$auth{'password'} = 'get me outta here';
my $wholesaleauth = CGI::Cookie->new(
-name=>'wholesaleauth',
-value=>\%auth,
-expires=>'+1h',
-path=>'/'
);
print "Set-Cookie: $wholesaleauth\n";
Outputs:
Set-Cookie: wholesaleauth=password&get%20me%20outta%20here&username¬%20safe;
path=/; expires=Thu, 14-Jan-2010 08:05:12 GMT
Cookies work in a common way regardless of the language or library used to construct or output them.
See also the section titled drawbacks of cookies.
Upvotes: 3
Reputation: 342819
not tested and $value is made up. Put in your own $value
$username="username";
$password="password";
$auth['password']=$password;
$auth['username']=$username;
$value = "password\&".$auth['password']."\&username\&".$auth['username'];
echo $value;
setcookie("wholesaleauth", $value, time()+3600,"/");
see the PHP manual for more info
Upvotes: 2
Reputation: 496
That cookie doesn't look quite right, what library are you using in perl (the $co->cookie parts)? I'd suggest CGI::Cookie in perl:
http://perldoc.perl.org/CGI/Cookie.html
Then you can get cookies in PHP via the $_COOKIE['cookiename'] variable, and set them via setcookie:
http://php.net/manual/en/function.setcookie.php
Upvotes: 1