Solved

POST doesn't work with CGI.pm

Posted on 2004-04-14
10
185 Views
Last Modified: 2013-12-25
I can't get POST to work when I try to use CGI-pm to do my cookie handling. Does anyone have any suggestions what I can do to work around this problem?
0
Comment
Question by:slobstar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:Fataqui
ID: 10827830
Hi

Can you show the code or give an example of what you you are doing, so one can see what the trouble maybe!


Fataqui!
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10827999
POST and GET methods work just fine using the CGI module.  There must be something wrong in your code.  Please show the relevant parts.
0
 
LVL 1

Author Comment

by:slobstar
ID: 10828316
Ok, what I am trying to achieve is just a regular cookie script, I've tried doing it without using any modules but it always feels like the cookies lives their own lives, sometimes they are set and sometimes they are not. If you have any good tutorial or examples of a good cookie script I would be more than glad. However, after a long time without success I wanted to try the cookie module and se if it worked better, it did, but at the same time my FORM POST's didn't work anymore, I read on the net of other people running into the same kind of problems, but I couldn't find a solution to it. But if you say it isn't so then maybe it isn't. Here is my new cookie code:

use CGI;.
my $loffe = new CGI;

sub get_cookies {
  # receive cookie
  my $AuctionWebCookieID = $loffe->cookie("AuctionWebCookieID");
 
  # if there is a cookie
  if($AuctionWebCookieID) {

    # Testa om man finns i Active Customers
    $sql_statement="SELECT cookieid FROM ACTIVECUSTOMER WHERE cookieid='$AuctionWebCookieID'";
    $sth = $dbh->query($sql_statement);
    $numrows = $sth->numrows;
 
    if($numrows<=0) {
      %temp = $sth->fetchhash;
      $sql_statement="INSERT INTO ACTIVECUSTOMER (ownerid,cookieid) VALUES ('9999999999','$AuctionWebCookieID')";
      $sth2 = $dbh->query($sql_statement);
    }
    &get_login_info;
  } else {
    &set_cookie;
  }
}

sub set_cookie{
  # unique number  
  $rnd = 0;
  for($i=0;$i<64;$i++){
    while($rnd < 48 || ($rnd > 57 && $rnd < 65) || ($rnd > 90 && $rnd < 97) || $rnd > 122){
      $rnd = rand(255);
    }
    $WebCookieID .= pack("C",$rnd);
    $rnd = 0;
  }

  # set cookie
  my $cookie_out = $loffe->cookie(-name=>"AuctionWebCookieID",-value=>"$WebCookieID");
  print $loffe->header(-cookie=>$cookie_out);
}
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 48

Expert Comment

by:Tintin
ID: 10828854
There's nothing in your code sample that shows where you are access POST variables.

How have you determined POST "isn't working"
0
 
LVL 1

Author Comment

by:slobstar
ID: 10830968
My bad, I used
my $loffe = new CGI;
instead of
$loffe = new CGI;
so it wasn't the POST!

but I still can't get my cookie handling script to work, it work perfect on my computer but I can't set a cookie on some of my friends computers, they hae enabled cookies but it still don't work.

# this row will work
    $cookie_out = $query->cookie(-name=> 'AuctionWebCookieID',-value=> $WebCookieID, -secure => 0);
# but what do I have to do after this row to set the cookie?
    print $query->header(-cookie=>$cookie_out);

# I've tried somethiing like this but whatever I do I can't set the cookie.
    print "Location: index.cgi\n\n";

# it will never receive the cookie with this row
$AuctionWebCookieID = $query->cookie('AuctionWebCookieID');


sub get_cookies{
  # receive cookie
  $AuctionWebCookieID = $query->cookie('AuctionWebCookieID');

  # if there is a cookie
  if($AuctionWebCookieID) {

    # Testa om man finns i Active Customers
    $sql_statement="SELECT cookieid FROM ACTIVECUSTOMER WHERE cookieid='$AuctionWebCookieID'";
    $sth = $dbh->query($sql_statement);
    $numrows = $sth->numrows;
 
    if($numrows<=0) {
      %temp = $sth->fetchhash;
      $sql_statement="INSERT INTO ACTIVECUSTOMER (ownerid,cookieid) VALUES ('9999999999','$AuctionWebCookieID')";
      $sth2 = $dbh->query($sql_statement);
    }
    &get_login_info;

  } else {
    # Get a unique ID
    $rnd = 0;
    for($i=0;$i<64;$i++){
      while($rnd < 48 || ($rnd > 57 && $rnd < 65) || ($rnd > 90 && $rnd < 97) || $rnd > 122){
        $rnd = rand(255);
    }
    $WebCookieID .= pack("C",$rnd);
    $rnd = 0;
  }

    $cookie_out = $query->cookie(-name=> 'AuctionWebCookieID',-value=> $WebCookieID, -secure => 0);
    print $query->header(-cookie=>$cookie_out);
    print "Location: index.cgi\n\n";
  }
}
0
 
LVL 1

Author Comment

by:slobstar
ID: 10831079
New information and another question?

To get the same result as on my friends computers I need to set the following preferences:

Tools->Internet Options->Privacy->Advanced options
Check  the Override automatic cookie handling box
Check the Block box

On my friends computers they don't have the Override automatic cookie handling checkbox checked, and it doesn't work for them, but it work for me when I don't have that checkbox checked.

My question:
I can't be the first person trying to do a cookie script, and I don't want my users to set different preferences to be able to use my site! What should I do?

 
0
 
LVL 1

Author Comment

by:slobstar
ID: 10831256
How can I determine if a browser can accept cookies or not?
0
 
LVL 1

Author Comment

by:slobstar
ID: 10831486
I guess I finally solved it, if I use the domain argument then it will work on medium security settings, which is default for most people.

$cookie_out = $query->cookie(-name=> 'AuctionWebCookieID',-value=> $WebCookieID,-domain=> '.mydomain.com');
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12002696
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 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