Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Cookies n Pics

Cookie Info not showint/pic resizing



9:08 am on Aug 27, 2010 (gmt 0)

5+ Year Member

Hi, Actually I have two questions here.
1. When my script writes a cookie I have to refresh the result page before any of the information in the cookie appears. Is there any way to make it available without manually refreshing the page? I thought about using a sub routine with print"Location:scripturl\n\n"; (not actually scripturl but the program url) but the content tag is within the sub rub routine that writes the cookie:
$query = new CGI;
$cookie = $query->cookie(-name=>'MY_COOKIE',
print $query->header(-cookie=>$cookie);
If there were a way of canceling out the content type header I could use the print"Location:....... thing after the cookie writing part or place it between the cookie writing sub routine and the result page with the cookie info showing. I'm basing this on the fact that instead of refreshing the page it would simply going through a one time loop of reloading the page(just a thought). At any rate I'm stuck on this one.

2. The next question involves creating a thumbnail on the fly. I have access to both the GD and the Imagemagic modules but don't have a clue how to use them and can't find any resources. I simply want to create thumbs upon user uploading(to decrease filesize) and possilbly link the thumb to the original. I tried to make sense of the documentation included with the PM files but found myself heading for the bridge.

As you might have guessed already, I'm not real proficient with perl but learning. I'll be glad when I finish up current projects to sit down and do some serious studying. Seems for every hour I spend writing I involve another 19 trying to figure out what went wrong(plus another 20 searching the net for answers). If it weren't for sites like this I'd have to change my strategy like take up bird watching or catching butterflies. Thanks a million times over for all the help and for this site.(I keep hoping I find a post I can answer to).


3:14 pm on Aug 27, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

It took me the longest time to get my head around this, but here's the way cookies work:

Server sends cookie header to client (browser.)
Browser writes cookie wherever it writes it.
Server/client connection terminates.
On the next request, the browser sends the cookie headers back to the server and it's read into %ENV.

That's why you need to do the page refresh. Your programs won't be able to read a cookie until the client sends the cookie headers that it previously stored at the next request.

I have access to both the GD and the Imagemagic modules but don't have a clue how to use them and can't find any resources.

Don't mess with GD, ImageMagick is far more robust. You'll also need PerlMagick, the Perl API to ImageMagick. If you do this

use Image::Magick;
print "content-type:text/html\n\n";
print "We're good.";

... and don't get a 500, you're good to go.

Start Here [imagemagick.org].


4:45 pm on Sep 24, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

1. Cookies
If you are sending the data from a page to perl and creating the cookie you already HAVE that data on the page, you don't need to call the cookie back to read-see if the data was written, this unless you need to do something with the result of the data managed by your perl and cookie.

Per example if you send your username and password and THEN you set the cookie with lets say "pending orders" of course you need to refresh the page or make another call to read that data on the cookie UNLESS you do some AJAX to read that. I'm doing in on several of my projects, specially on some of my CMS functions. I send the data, perl does the magic and from the same page I can call the data via ajax.

2. Resample images
This line does it for me, it grabs a file and creates another one with 300px wide and 75% quality, you could specify height too:
system("convert $originalfile -resize 300 -quality 75 $newfile");


10:58 am on Sep 25, 2010 (gmt 0)

5+ Year Member

Thanx for the info. Actually, the reason I need to read the cookies is because I am doing something with the information. It deals with accessing admin functions of a script. I managed to get around that situation. I'm certain that a knowledge of ajax would be a bonus in my adventure. The script I'm putting together has been quite the education for me.

On the resample images: do I write that as shown? Do I need to specify width and height for the resizing. I'm going to give it a run before the night is over and see what happens. Thanks again.


4:36 pm on Sep 28, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

On the resample images: do I write that as shown?

you could write directly the line or use variables as stated in the example. You might even construct a one line var with all the command you are sending via SYSTEM. Play around with the code. Good luck.

Featured Threads

Hot Threads This Week

Hot Threads This Month