I am trying to set a variable to one of two things depending on if the client has cookies enabled. I have decided NOT to have a prompt saying "cookies must be enabled" if they don't have cookies enabled, I am going to silently use their IP instead.
The cookie has been added already in the calling page with javascript, with no tests done to see if it actually got written.
But I have also recorded the ip in a hidden form field called "ip".
I need to test if the cookie "id" exists, to decide what my scalar "$id" will contain.
Will this work? -
#!/usr/bin/perl -T
-
-
use strict;
-
use warnings;
-
-
use CGI qw(:standard);
-
-
my $ip = param('ip');
-
my $cook = cookie('id');
-
-
my $id = (defined($cook))? $cook : $ip;
-
-
Thanks!
3 2030
I am trying to set a variable to one of two things depending on if the client has cookies enabled. I have decided NOT to have a prompt saying "cookies must be enabled" if they don't have cookies enabled, I am going to silently use their IP instead.
The cookie has been added already in the calling page with javascript, with no tests done to see if it actually got written.
But I have also recorded the ip in a hidden form field called "ip".
I need to test if the cookie "id" exists, to decide what my scalar "$id" will contain.
Will this work? -
#!/usr/bin/perl -T
-
-
use strict;
-
use warnings;
-
-
use CGI qw(:standard);
-
-
my $ip = param('ip');
-
my $cook = cookie('id');
-
-
my $id = (defined($cook))? $cook : $ip;
-
-
Thanks!
While not having much experience with cookies, I did some searching of CPAN and found a couple of things.
First is HTTP::Cookies::Find. This is a module to find cookies on a machine for the present user. This may help you locate cookies.
Second, if that doesn't help, you could always take the Javascript out of the way and set the cookie(s) with Perl so you know what's going on (and can actually log the success and failure of it, unlike the Javascript routines). That other module is called HTTP::Cookies.
Hope this helped in some way.
Regards,
Jeff
While not having much experience with cookies, I did some searching of CPAN and found a couple of things.
First is HTTP::Cookies::Find. This is a module to find cookies on a machine for the present user. This may help you locate cookies.
Second, if that doesn't help, you could always take the Javascript out of the way and set the cookie(s) with Perl so you know what's going on (and can actually log the success and failure of it, unlike the Javascript routines). That other module is called HTTP::Cookies.
Hope this helped in some way.
Regards,
Jeff
Thanks, Jeff!
That sounds a lot better. The only reason I was using javascript was because the referring page is a "static" document with no perl in it.
But I am in the process of switching everything to a Embperl dynamic site, and
should probably generate that page with cgi. It will eliminate a lot of these kinda troubles.
Do you know if that statement: -
-
my $id = (defined($cook)? $cook : $ id;
-
-
will work?
I have never used the "defined" function before.
Thanks, Jeff!
That sounds a lot better. The only reason I was using javascript was because the referring page is a "static" document with no perl in it.
But I am in the process of switching everything to a Embperl dynamic site, and
should probably generate that page with cgi. It will eliminate a lot of these kinda troubles.
Do you know if that statement: -
-
my $id = (defined($cook)? $cook : $ id;
-
-
will work?
I have never used the "defined" function before.
From what I can see in the documentation of the defined function, it looks like it should. I guess the only way would be to test it out.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics
by: propizzy |
last post by:
Appreciate any help!!!
PROBLEM: I have this form that allows the user to dynamically create
additional fields (see javascript code bellow). I am trying to retrieve
the values entered into these...
|
by: Tommy Lang |
last post by:
Hi everybody!
I am trying to learn the basics of C++ myself and have a hard time
understanding some stuff like pointers and references etc.
I have created a small program that adds two numbers...
|
by: Tommy Lang |
last post by:
I am trying to learn to use dynamic variables.
I have pasted the code below.
Is this the proper way of using dynamic variables?
Thanks,
Tommy
...
|
by: Tim.D |
last post by:
People,
I've ventured into the wonderful world of Stored Procedures. My first
experience has been relatively successful however I am stuck on using
host variables to specifiy actualy table or...
|
by: Nathan Bloomfield |
last post by:
Does anyone know if there is any documentation which relates to Access2k + ?
or can anyone help adjust the code?
I am having trouble converting the DAO references.
TITLE :INF: How to...
|
by: Dennis |
last post by:
I have a function which is called from a loop many times. In that function,
I use three variables as counters and for other purposes. I can either use
DIM for declaring the variables or Static. ...
|
by: scott |
last post by:
Is there a way to create dynamic variables when looping through a recordset?
For example below, after the 1st loop I'd have myVarA1 and myVarB1, after
2nd loop, I'd get myVarA2 and myVarB2.
CODE...
|
by: deejayquai |
last post by:
Hi
I'm trying to produce a report based on a dynamic crosstab. Ultimately
i'd like the report to actually become a sub report within a student
end of year record of achievement. The dynamic...
|
by: JWL |
last post by:
Hi
I need to create a bunch of sites with slightly dynamic CSS. Basically,
all the image paths in the CSS need to be dynamic, depending on the
values of certain ASP variables.
I can think of...
|
by: Mark S. |
last post by:
As I understand it, C# doesn't offer dynamic variable names. Below is my
attempted workaround. Is what I'm doing possible?
FYI, I already read all the "why in the world do you need dynamic...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
| |