Can anyone give advice please?
Thanks
I turned this into a short script setcookie.pl which is on the server. The complete content of the file is only the three lines:
#!/usr/bin/perl
use CGI qw(:standard);
print "Set-Cookie:name=ddil\n";
When I try to run this from a browser command line I get server error 500. I have set the permission to 705 (I also tried 777 but it made no difference).
Further basic questions I am trying to work out:
Do I need to run the script from every page that might be an entry page, if so what is the effect of people running the script several times as they move around the site?
How do I call the script from within an html page?
These are obviously very basic questions but I have found that most of the tutorials on the web seem to assume everyone knows this sort of thing!
Help is appreciated!
Martin
When I try to run this from a browser command line I get server error 500.
That's because you stopped. :-) The cookie is a header. You need to follow it with a content-type, then some output.
#!/usr/bin/perl
use CGI qw(:standard);
print "Set-Cookie:name=ddil\n";
print "content-type: text/html\n\n"; ## Note TWO returns
print "the ddil cookie was set.";
You confused me a bit - command-line should work, but from a browser - yeah that will error. By the way the executable permissions are 755, not 705 or 777 (You may have meant that anyway.)
Do I need to run the script from every page that might be an entry page, if so what is the effect of people running the script several times as they move around the site?
If you want to set a cookie for each page, yes, but you might want to name them all differently. Should have no detrimental effect.
How do I call the script from within an html page?
Hmm you don't. You request the script, it returns an output. Done. If you want to set cookies from an HTML page, you should use Javascript.
OR
Set your links to a script for each page, although that's a convoluted way of doing things . . . .
<a href="cookiescript?page=index.html">Home</a>
#!/usr/bin/perl
use CGI qw(:standard);
print "Set-Cookie:name=ddil\n";
$query = new CGI;
$page = $query->param('page');
print "Location:$page\n\n"; ## Again, note two returns
I didn't put any output in because I don't want any - I only want to set a session cookie! I certainly dont want any text printed to the user's screen. But perhaps this doesnt actually print to the screen? Ive updated the setcookie.cgi script anyway, but it still doesnt seem to be doing anything.
I want to set one cookie, not one per page, it is one and one only. However I want it to be set by every page because people arrive at the site from search engines and land on any page, they may never visit the home page.
I dont understand the difference between calling a script and requesting a script. How to I provoke it into running, cause it to run, make it run....? I have tried putting in the header of an html page the following line:
<SCRIPT TYPE="application/x-perl" SRC="setcookie.pl"></SCRIPT>
but this doesnt seem to work. I don't really want to start the script from a page at all but somehow it has to run when a user session begins.
I dont think setting links to a script can be what I'm looking for since there is no promise at all that a user will click on any links.
I get the feeling that I'm barking up the wrong tree here because what I want to do is so simple, and thousands must have wanted to do it before, yet I am finding it so problematical. All I want to do is set a session cookie, one only, whenever a user looks at any page on the site, so that the session information can be recored in the log and analysed later for statistical reasons.
If anyone can suggest where I go next it will be appreciated....
<meta http-equiv="Set-Cookie" content="value=n;expires=date; path=url">
for a session, remove the expires. A valid GMT date causes the cookie to be persistent - that is, a session cookie will never show up in the cookies.txt of NN browsers or the cookies dir of IE.
<meta http-equiv="Set-Cookie" content="value=n;path=url">
Exemplified with your values:
<meta http-equiv="Set-Cookie" content="ddil=1;path=/">
Alternatively, look into Javascript cookies and set one using Javascript. In either case this goes on every page.