Solved

Setting a cookie from a CGI script (IIS 4.0, NT 4.0)

Posted on 1998-08-26
3
146 Views
Last Modified: 2013-12-25
OS: Win NT 4.0
WS: IIS 4.0

I have a simple CGI script that is supposed to set a cookie and then do a redirect to an image graphic url. The redirect works but the cooie does not get set...

I have tried the following:

1. print "Set-Cookie: CNAME=CVALUE; expires=Mon, 01-JAN-2029 23:59:59 GMT \nLocation: http://www.blah.com/image.gif\n\n";

2. print "Location: http://www.blah.com/image.gif \nSet-Cookie: CNAME=CVALUE; expires=Mon, 01-JAN-2029 23:59:59 GMT \n\n";

3. Just doing the print Location and then using a javascript to print a document.cookie setting.

None of these seem to work as far as having the cookie get set, though the edirect does work. Can anyone help?

Thanks,
Andy
         
0
Comment
Question by:icculus
  • 2
3 Comments
 
LVL 1

Author Comment

by:icculus
ID: 1828313
Edited text of question
0
 
LVL 4

Accepted Solution

by:
mitek earned 50 total points
ID: 1828314
One way to do that would be printing out a page that will contain an http-equiv refresh command:

$redirect_url = "http://www.site.com/abc.asp";
print qq(
Set-Cookie: CNAME=CVALUE; expires=Mon, 01-JAN-2029 23:59:59 GMT \n
Content-Type: text/html\n\n
<HTML>
<HEAD>
<META HTTP-EQUIV="refresh" CONTENT="0; URL=$redirect_url">
</HEAD>
<BODY></BODY>
</HTML>
);

The main point is, this will set the cookie AND immediately redirect to wherever is necessary.
This approach is used in many websites we developed.

0
 
LVL 1

Author Comment

by:icculus
ID: 1828315
Unfortunately this is not working... While the code does set the cookie, the image then appears broken. I did check to make sure the image url was valid and indeed it is...

-andy
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Update a File not in all folders 2 46
home folder path for users 4 72
Do Psexec queries install files on remote computers 6 62
Questions about this React unit test 4 63
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question