POST doesn't work with CGI.pm

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?
LVL 1
slobstarAsked:
Who is Participating?
 
Computer101Commented:
PAQed, with points refunded (500)

Computer101
E-E Admin
0
 
FataquiCommented:
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
 
TintinCommented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
slobstarAuthor Commented:
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
 
TintinCommented:
There's nothing in your code sample that shows where you are access POST variables.

How have you determined POST "isn't working"
0
 
slobstarAuthor Commented:
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
 
slobstarAuthor Commented:
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
 
slobstarAuthor Commented:
How can I determine if a browser can accept cookies or not?
0
 
slobstarAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.