Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

POST doesn't work with CGI.pm

Posted on 2004-04-14
10
Medium Priority
?
188 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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

610 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