Cookies and IP Addresses
Hi all, Can you help me with this? I want to get the servers IP address and the IP address of the referrer. Is there a reliable way to do this? When I used 'REMOTE_ADDR' I get different values even when I go directly to my site and then call 'REMOTE_ADDR'. Does anyone know why? I want to use the IP address to ensure that some of the code is only called from my site or from a valid IP address. I want the IP address and not the URL so I can convert it into Hex. $ENV{'SERVER_NAME'}; $ENV{'HTTP_REFERER'}; $ENV{'REMOTE_ADDR'}; In the discussions on cookies does any one know why when I set a cookie and restart some time later my cookies are lost when I do the following in JavaScript var cookieDate = new Date() cookieDate.setTime(cookieDate.getTime() + 10 * 365 * 24 * 3600 * 1000);//Add 10 years document.cookie = escape(MyCookie=XXX + ;expires= + cookieDate.toGMTString() + ;domain=.UltraTextPro.biz); Mike -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cookies and IP Addresses
Hi, not sure about the REMOTE_ADDR, I've never had any problems with it. To get an IP from a URI try this: use Socket; $referral_address = $ENV{'HTTP_REFERER'}; $referral_address =~ m#^.*http://([^/]+)/.*$#; $IP = inet_ntoa inet_aton $1; If you want the IP address in hex, just use inet_aton. R At 11:06 03/10/2002 +0100, Mike Craig wrote: Hi all, Can you help me with this? I want to get the servers IP address and the IP address of the referrer. Is there a reliable way to do this? When I used 'REMOTE_ADDR' I get different values even when I go directly to my site and then call 'REMOTE_ADDR'. Does anyone know why? I want to use the IP address to ensure that some of the code is only called from my site or from a valid IP address. I want the IP address and not the URL so I can convert it into Hex. $ENV{'SERVER_NAME'}; $ENV{'HTTP_REFERER'}; $ENV{'REMOTE_ADDR'}; In the discussions on cookies does any one know why when I set a cookie and restart some time later my cookies are lost when I do the following in JavaScript var cookieDate = new Date() cookieDate.setTime(cookieDate.getTime() + 10 * 365 * 24 * 3600 * 1000);//Add 10 years document.cookie = escape(MyCookie=XXX + ;expires= + cookieDate.toGMTString() + ;domain=.UltraTextPro.biz); Mike -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI problem
On Wed, 2 Oct 2002 07:43:58 -0700 (PDT), [EMAIL PROTECTED] (Yahaya Mohammed) wrote: Note: forwarded message attached. Your method of forwarding attached messages makes it difficult to cut-n-paste comments in. In the future, put the message in the message body . Anyways, since you are just learning, your method is referred to as the old perl4 cgi-lib subroutine, and is widely frowned upon now. The following is one of the newer methods. ### #!/usr/bin/perl use warnings; use strict; use CGI; my $cgi=new CGI; my %in = $cgi-Vars(); foreach my $key (keys %in){ print $key\t$in{$key}\n; } ## -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly list FAQ posting
NAME beginners-faq - FAQ for the beginners-cgi mailing list 1 - Administriva 1.1 - I'm not subscribed - how do I subscribe? Send mail to [EMAIL PROTECTED] You can also specify your subscription email address by sending email to (assuming [EMAIL PROTECTED] is your email address): [EMAIL PROTECTED]. 1.2 - How do I unsubscribe? Now, why would you want to do that? Send mail to [EMAIL PROTECTED], and wait for a response. Once you reply to the response, you'll be unsubscribed. If that doesn't work, find the email address which you are subscribed from and send an email like the following (let's assume your email is [EMAIL PROTECTED]): [EMAIL PROTECTED] 1.3 - There is too much traffic on this list. Is there a digest? Yes. To subscribe to the digest version of this list send an email to: [EMAIL PROTECTED] To unsubscribe from the digest, send an email to: [EMAIL PROTECTED] 1.4 - Is there an archive on the web? Yes, there is. It is located at: http://archive.develooper.com/beginners-cgi%40perl.org/ 1.5 - How can I get this FAQ? This document will be emailed to the list once a month, and will be available online in the archives, and at http://beginners.perl.org/ 1.6 - I don't see something in the FAQ, how can I make a suggestion? Send an email to [EMAIL PROTECTED] with your suggestion. 1.7 - Is there a supporting website for this list? Yes, there is. It is located at: http://beginners.perl.org/ 1.8 - Who owns this list? Who do I complain to? Casey West owns the beginners-cgi list. You can contact him at [EMAIL PROTECTED] 1.9 - Who currently maintains the FAQ? Kevin Meltzer, who can be reached at the email address (for FAQ suggestions only) in question 1.6 1.10 - Who will maintain peace and flow on the list? Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large, yet padded, clue-sticks to maintain peace and order on the list. If you are privately emailed by one of these folks for flaming, being off-topic, etc... please listen to what they say. If you see a message sent to the list by one of these people saying that a thread is closed, do not continue to post to the list on that thread! If you do, you will not only meet face to face with a XQJ-37 nuclear powered pansexual roto-plooker, but you may also be taken off of the list. These people simply want to make sure the list stays topical, and above-all, useful to Perl/CGI beginners. 1.11 - When was this FAQ last updated? Sept 07, 2001 2 - Questions about the 'beginners-cgi' list. 2.1 - What is the list for? A list for beginning Perl programmers to ask questions in a friendly atmosphere. The topic of the list is, of course, CGI with Perl. 2.2 - What is this list _not_ for? * SPAM * Homework * Solicitation * Things that aren't Perl related * Non Perl/CGI questions or issues * Lemurs 2.3 - Are there any rules? Yes. As with most communities, there are rules. Not many, and ones that shouldn't need to be mentioned, but they are. * Be nice * No flaming * Have fun 2.4 - What topics are allowed on this list? Basically, if it has to do with Perl/CGI , then it is allowed. If your question has nothing at all to do with Perl/CGI, it will likely be ignored. 2.5 - I want to help, what should I do? Subscribe to the list! If you see a question which you can give an idiomatic and Good answer to, answer away! If you do not know the answer, wait for someone to answer, and learn a little. 2.6 - Is there anything I should keep in mind while answering? We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the beginner to the place in the FM they should R :) 2.7 - I don't want to post a question if it is in an FAQ. Where should I look first? Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it. It can save everyone time if you look in the Perl FAQs first, instead of having a list of people refer you to the Perl FAQs :) You can learn about 'perldoc' by typing: perldoc perldoc At your command prompt. You can also view documentation online at: http://www.perldoc.com and http://www.perl.com 3 - Other Resources 3.1 - What other websites may be useful to a beginner ? * Perl Home Page - http://www.perl.com * PerlMonks - http://www.perlmonks.org * Perldoc - http://www.perldoc.com * Perl Archives - http://www.perlarchives.com 3.2 - What resources may be harmful to a beginner? Beware of Perl4-like code-- You might find some script archives and unauthorized mirrors with old Perl4 versions of Selena Sol and Matt Wright scripts. Don't use those scripts. They are outdated and may even in some cases contain bugs or security problems since many may not have been updated in
Re: CGI problem
On Thu, 03 Oct 2002 07:34:13 -0400, [EMAIL PROTECTED] (Zentara) wrote: Oops, keep forgetting the header. :-) The following will send the form variables back to the browser. ### #!/usr/bin/perl use warnings; use strict; use CGI; my $cgi=new CGI; print Content-type: text/html\n\n; my %in = $cgi-Vars(); foreach my $key (keys %in){ print $key\t$in{$key}\n; } ## -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI problem
On Thu, 3 Oct 2002 at 08:52, zentara opined: z:On Thu, 03 Oct 2002 07:34:13 -0400, [EMAIL PROTECTED] (Zentara) z:wrote: z: z:Oops, keep forgetting the header. :-) The following will z:send the form variables back to the browser. z: z:### z:#!/usr/bin/perl z:use warnings; z:use strict; z:use CGI; z:my $cgi=new CGI; z: z:print Content-type: text/html\n\n; z: z:my %in = $cgi-Vars(); z:foreach my $key (keys %in){ z: print $key\t$in{$key}\n; z: } but, of course, you'll want to html escape anything posted to a form before it's sent back to the browser. read this for more info on why: http://www.perl.com/pub/a/2002/02/20/css.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Info about IO::Socket
Hi all, Please tell me where can I find more information about using the IO::Socket. module. I want to avoid using the LWP module, because it is not working as it should. Thank you. Teddy's Center: http://teddy.fcc.ro/ Mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
I've solved a problem. But why?
Hi all, I've tried to make a script that gets a remote html page using IO::Socket. If I wanted to use (like in some example from books) GET $path HTTP/1.1, the script didn't want to work. But it works OK if I ask for HTTP/1.0. The strange thing is that the header returned by the Apache Server running in Windows 2k says that it is HTTP/1.1, even though I've asked for HTTP/1.0. Of course, this is happening only if I rename the file as index.html. If I let it as index.shtml, it doesn't work with any method. It prints only the first 4 KB of the html file. Can you tell me why is not working if I try with HTTP/1.1, and why is not working with .shtml files? Thanks. Here is the script: #!/perl/bin/perl -w print Content-type: text/html\n\n; use IO::Socket; my $host = 127.0.0.1; my $path = /test.html; my $port = 80; my $socket = IO::Socket::INET - new(PeerAddr = $host, PeerPort = $port, Proto = 'tcp', Type = SOCK_STREAM, Timeout = 5, ) or die Cannot connect to the server.\n; $socket-autoflush(1); #print $socket GET $path HTTP/1.0\n, #Host: $host\n\n; print $socket GET /index.shtml\n\n; my $sock = $socket; while ($socket) { print; } $socket-close; Teddy's Center: http://teddy.fcc.ro/ Mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: I've solved a problem. But why?
-Original Message- From: Octavian Rasnita [mailto:[EMAIL PROTECTED]] Sent: Thursday, October 03, 2002 6:58 AM To: [EMAIL PROTECTED] Subject: I've solved a problem. But why? Hi all, I've tried to make a script that gets a remote html page using IO::Socket. If I wanted to use (like in some example from books) GET $path HTTP/1.1, the script didn't want to work. But it works OK if I ask for HTTP/1.0. HTTP 1.1 requires a Host request header. See sec. 14.3 of RFC 2616. http://www.w3.org/Protocols/rfc2616/rfc2616.txt Also, persistent connections are the default. See sec. 8.1. Use LWP. Don't reinvent the wheel. The strange thing is that the header returned by the Apache Server running in Windows 2k says that it is HTTP/1.1, even though I've asked for HTTP/1.0. Of course, this is happening only if I rename the file as index.html. If I let it as index.shtml, it doesn't work with any method. It prints only the first 4 KB of the html file. That sounds like a server-side problem. Can you tell me why is not working if I try with HTTP/1.1, and why is not working with .shtml files? Thanks. Here is the script: #!/perl/bin/perl -w print Content-type: text/html\n\n; use IO::Socket; my $host = 127.0.0.1; my $path = /test.html; my $port = 80; my $socket = IO::Socket::INET - new(PeerAddr = $host, PeerPort = $port, Proto = 'tcp', Type = SOCK_STREAM, Timeout = 5, ) or die Cannot connect to the server.\n; $socket-autoflush(1); #print $socket GET $path HTTP/1.0\n, #Host: $host\n\n; print $socket GET /index.shtml\n\n; my $sock = $socket; while ($socket) { print; } $socket-close; Teddy's Center: http://teddy.fcc.ro/ Mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
mod PERL versus PERL
Hello, Can someone tell me the coding difference and syntax difference between PERL and mod PERL? I'm getting errors in a script where there shouldnt be any. I've recently switched hosts and my new host uses mod PERL Thanks, Roger -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: mod PERL versus PERL
-Original Message- From: Guru Geek [mailto:[EMAIL PROTECTED]] Sent: Thursday, October 03, 2002 3:10 PM To: [EMAIL PROTECTED] Subject: mod PERL versus PERL Hello, Can someone tell me the coding difference and syntax difference between PERL and mod PERL? Perl is a language. mod_perl is an Apache module that allows you to write Apache handlers in the Perl language. I'm getting errors in a script where there shouldnt be any. I've recently switched hosts and my new host uses mod PERL To run regular CGI scripts under mod_perl, they need to be handled by a mod_perl handler that emulates a CGI-like environment. The most common module for this is Apache::Registry. To run CGI scripts under Apache::Registry, you need to be aware of a few things. Your best bet is to read the porting section of the mod_perl guide at http://perl.apache.org/docs/1.0/guide/porting.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Detecting a server-side condition every 30 seconds
Hello all, I've got a requirement to write a script that checks some condition on the server, and to display one image if the condition is true, another if the condition is false. But I want to update the image every time the condition changes. For now, I'm using a META REFRESH tag so that the CGI script is rerun every 30 seconds. But this is not a very good solution, as the whole web page gets redrawn even when nothing has changed. I've also thought about using frames, and having one frame that repeatedly refreshes while the rest of the page stays static. Again, not a very elegant solution. Is there some way (perhaps using JavaScript in conjunction with CGI) to query the server periodically, and only update the image when the condition changes? Here's the relevant excerpt from my code: # $GoNogo = go;# or stop depending on server-side condition print 'End of Header'; Content-type: text/html html head titleMy title here/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 meta http-equiv=Refresh content=30 End of Header # irrelevant code here print End of Javascript; script language=javascript type=text/javascript function setStatus() { if ($GoNogo != go) { document.fgColor = #66; document.TheImg.src=go.gif; document.links[0].href=#; } else { document.fgColor = #006600; document.TheImg.src=stop.gif; document.links[0].href=$launchUrl; } } // -- /script /head End of Javascript # irrelevant code here print 'End of Body'; body onLoad=setStatus() Top of page here center a href=#img name=TheImg /a /center More body text here /body /html End of Body Thanks in advance for any help! Jim Bander, Ph.D. Operations Research Specialist Norfolk Southern Corporation One Georgia Center 600 W Peachtree St, NW, Suite 900 Atlanta, GA 30308 Phone: 404 897-3060Fax: 404 897-3063 e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
CGI simple but not working
Hi all, I'm studying the Learning Perl Second Edition and I'm learning cgi now. The book presents a sample cgi that doesn't produces the expected result as the book says it would. In sumary, this script should generate an one field form with a default value - mint. But what appears in the screen are the strings inside the q() function. Could someone test it and say to me if there is something wrong? The following script was retired from the section 19.6 Form Generation. #!/usr/bin/perl -w # cgi-bin/ice_cream: program to answer *and generate* ice cream # favorite flavor form (version 3) use CGI qw(:standard); my $favorite = param(flavor); print header, start_html(Hello Ice Cream), h1(Hello Ice Cream); if ($favorite) { print q(Your favorite flavor is $favorite.); } else { print hr, start_form; # hr() emits html horizontal rule: HR print q(Please select a flavor: , textfield(flavor,mint)); print end_form, hr; } I'm running Redhat 6.2 perl version 5.005_03 built for i386-linux But i tested this script with RH7.2 v5.6.0 built for i386-linux and it doesn't work too Thanks for any help, - -- Bruno Negrão -- Suporte -- Plugway Acesso Internet Ltda. -- (31)34812311 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Here is that problem with the LWP module
Hi all, I've tried a sinple test script for testing the LWP module and I've received the following result: 501Protocol scheme 'http' is not supported The script works under Red Hat with Perl 5.6.0. The module LWP is not installed by the root. I've installed it in a separate directory and i've used the use lib. Here is the script. Do you have any idea what could be the problem? Thank you. #!/usr/bin/perl -w use LWP::UserAgent; print Content-type: text/html\n\n; my $page = http://localhost/;; my $ua = LWP::UserAgent - new(env_proxy = 0, timeout = 60, keep_alive = 1, ); my $response = $ua - get($page); print $response - code(); print $response - message(); Teddy's Center: http://teddy.fcc.ro/ Mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]