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
Solved

POST doesn't work with CGI.pm

Posted on 2004-04-14
10
184 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
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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

829 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