473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help on Perl and Javascript cookie

rajiv07
141 100+
Hi to all

I have doubt on fetch the cookie in perl which is stored in html using javascript.

For that i am using in Javascript

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var exdate=new Date();
  3. var value="rajiv";
  4.  
  5. exdate.setDate(exdate.getDate()+expiredays);
  6.  
  7. document.cookie=c_name+ "=" +escape(value)+
  8. ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
  9. </script>

cookie.pl
----------

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use CGI;
  4.  
  5. my $cgi=new CGI;
  6.  
  7. print $cgi->header;
  8.  
  9. my $cCookie=$cgi->cookie("c_name");
  10.  
  11. print $cCookie;
But the $cCookie has rerurn nothing.

Is any Idea.

Thank u.

Regards

Rajiv
Dec 19 '07 #1
6 2169
eWish
971 Expert 512MB
I would use CGI::Cookie rathe than using the JavaScript to set the cookie. You might also want to use Sessions which would be better than cookies.

--Kevin
Dec 19 '07 #2
rajiv07
141 100+
I would use CGI::Cookie rathe than using the JavaScript to set the cookie. You might also want to use Sessions which would be better than cookies.

--Kevin

Hi

Thanks eWish.But i want to get the cookies which is stored in Javascript(html file).Is any idea to get perl vs Javascript cookies interface.

Thank u.

Regards
Rajiv
Dec 20 '07 #3
numberwhun
3,509 Expert Mod 2GB
Hi

Thanks eWish.But i want to get the cookies which is stored in Javascript(html file).Is any idea to get perl vs Javascript cookies interface.

Thank u.

Regards
Rajiv
I think that is kind of what eWish is saying. Instead of using the Javascript to set your cookie and then trying to read it with Perl, why not just handle it all with Perl and CGI, using the the module that eWish provided?

Regards,

Jeff
Dec 20 '07 #4
rajiv07
141 100+
I think that is kind of what eWish is saying. Instead of using the Javascript to set your cookie and then trying to read it with Perl, why not just handle it all with Perl and CGI, using the the module that eWish provided?

Regards,

Jeff

Hi Jeff

Let me explain what i am trying to do.I have two html file and one pl file.

1, referrer.html
2. index.html
3. referrer.pl

Here the referrer.html links to index.html.In index.html has so many html link to display some other details.But there is one link to connect referrer.pl.Here i want to store the referrer URL in the index.html obviously the referrer will be http:/myhost/referrer.html.Here to store the referrer value i am using javascript cookie in index.html.In referrer.pl i will get the stored cookie value and do some calculation.

For this purpose i want PERL and javascript cookie interface.

Is any idea

Thanks.

Regards

Rajiv.
Dec 20 '07 #5
eWish
971 Expert 512MB
Can you show an example of how you are storing the data for the cookies with the referrer url?

Also, since referrers can be spoofed then you might want to consider using sessions and which is much safer and has less vulnerabilities.

--Kevin
Dec 24 '07 #6
Kelicula
176 Expert 100+
If you really want to read the cookie written by javascript, all you need is the CGI module and a little snippet of code.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI;
  7.  
  8. my $q = new CGI;
  9.  
  10. my $cookie = $q->cookie('theCookieName');
  11.  
  12. # Then if you want to do calculations with the cookie 
  13. #data the value of the cookie is stored in "$cookie" variable.
  14. # CGI also has a redirect function:
  15.  
  16. print $q->redirect(-url=>'http://www.someurl.com');
  17.  
  18. # Or you can just print the location header manually.
  19.  
  20. print "Location: http://www.someurl.com\n\n";
  21.  
  22.  
It doesn't matter what you used to write the cookie, if there's a cookie there, and it is set to the proper domain,
IE: you will be reading the cookie from your cgi, or cgi-bin now with the referer.pl so you will want to make sure that it is valid for that domain.

BUT!!!!!!!!

Did I say that loud enough?

You should listen to eWish, and use sessions, it's much better!!
Some browsers are able to modify what is sent as the $ENV{'HTTP_REFERER'}; variable.

CGI 101:
Never trust the user input, or the browser.

Please give us your code, and maybe we can help you a little better....
Dec 25 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ken | last post by:
I am new to PHP. But this seems like a terrific language. I have been using JavaScript up to now but it looks like I will be changing to PHP. Seems to have more potential. I am confused about...
0
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass...
1
by: Joe | last post by:
I want to be able to detect if I can write cookies out or not. Currently I'm doing: my $cgi = new CGI; my $cookie = $cgi->cookie(-name => $POLL_CODE_TEST, -value => "cookietest",...
2
by: Lisa | last post by:
Can anyone tell me why the cookie created by this javascript... <script language=javascript type="text/javascript"> <!-- function SetCookie(username, value, expires, path, domain) {...
1
by: martingerber | last post by:
Hi, I have the following script (javascript in html document): <html> <head> <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1"> <title>Standort Speichern</title>
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
2
by: BillyTheKid | last post by:
Hello, I am very new to java and I have pasted the following code onto my website: #########################################3 <SCRIPT language=JavaScript> <!-- function...
6
by: von | last post by:
Is it possible to run a Perl script from within a javascript? I have an existing javascript that provides some data - and I want to write that data to a text file on my server via a Perl script...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.