473,413 Members | 1,795 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,413 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 2173
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.