473,409 Members | 2,006 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,409 software developers and data experts.

Dynamic variables

Kelicula
176 Expert 100+
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?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI qw(:standard);
  7.  
  8. my $ip = param('ip');
  9. my $cook = cookie('id');
  10.  
  11. my $id = (defined($cook))? $cook : $ip;
  12.  
  13.  
Thanks!
Oct 8 '07 #1
3 2030
numberwhun
3,509 Expert Mod 2GB
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?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI qw(:standard);
  7.  
  8. my $ip = param('ip');
  9. my $cook = cookie('id');
  10.  
  11. my $id = (defined($cook))? $cook : $ip;
  12.  
  13.  
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
Oct 8 '07 #2
Kelicula
176 Expert 100+
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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. my $id = (defined($cook)? $cook : $ id;
  3.  
  4.  
will work?

I have never used the "defined" function before.
Oct 8 '07 #3
numberwhun
3,509 Expert Mod 2GB
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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. my $id = (defined($cook)? $cook : $ id;
  3.  
  4.  
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
Oct 8 '07 #4

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

Similar topics

11
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...
2
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...
1
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 ...
4
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...
1
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...
28
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. ...
12
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...
2
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...
2
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...
3
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...
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
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:
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...
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
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
tracyyun
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...
0
isladogs
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...
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.