How do I do this using CGI ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AssFairy
    Confirmed User
    • Jun 2003
    • 674

    #1

    How do I do this using CGI ?

    I have a web page that generates a string of hexadecimal characters when the surfer is browsing and I want to store them in a text file.

    EG. http://mydomain.com/cgi.pl?AAC7EE

    What I want to do is append a text file and add the "AAC7EE" or any other string after the ? to the file.

    Any help is appreciated.
    I sale lube
  • hyper
    Confirmed User
    • Mar 2002
    • 5294

    #2
    store the query string in a $variable
    open a txt file and write the $variable in it

    Comment

    • AssFairy
      Confirmed User
      • Jun 2003
      • 674

      #3
      Originally posted by hyper
      store the query string in a $variable
      open a txt file and write the $variable in it
      cool but how, I don't know jack about CGI

      I already have the webpage that generates the text string I just need to know how to save all the info after the ? to a file when they click the link.
      I sale lube

      Comment

      • NetRodent
        Confirmed User
        • Jan 2002
        • 3985

        #4
        Which language are you trying to write it in?
        "Every normal man must be tempted, at times, to spit on his hands, hoist the black flag, and begin slitting throats."
        --H.L. Mencken

        Comment

        • hudson
          Confirmed User
          • Jul 2003
          • 2948

          #5
          Originally posted by AssFairy


          cool but how, I don't know jack about CGI

          I already have the webpage that generates the text string I just need to know how to save all the info after the ? to a file when they click the link.
          yo...you need to learn perl than...not so hard

          Comment

          • AssFairy
            Confirmed User
            • Jun 2003
            • 674

            #6
            Originally posted by NetRodent
            Which language are you trying to write it in?
            Whatever is quickest and easiest

            It used to be stored in a mysql database but this is no longer possible.

            Whilst the surfer is browsing a string of data is generated and appears after the ? in their browser, I don't care how its done but I need to store that information in a plain asci file.

            I was hoping this to be just 3 or 4 lines of CGI code
            I sale lube

            Comment

            • icedemon
              Confirmed User
              • Jun 2003
              • 1022

              #7
              Code:
              #!/usr/bin/perl
              
              print "Content-type: text/plain\n\n";
              if ($ENV{'QUERY_STRING'}) {
              	open(FILE, ">>file.txt") || die (print "$!\n");
              	print FILE $ENV{'QUERY_STRING'} . "\n";
              	close(FILE);
              }
              Here is some perl code you can use.
              Clips4Sale.com

              Comment

              • AssFairy
                Confirmed User
                • Jun 2003
                • 674

                #8
                Originally posted by icedemon
                Code:
                #!/usr/bin/perl
                
                print "Content-type: text/plain\n\n";
                if ($ENV{'QUERY_STRING'}) {
                	open(FILE, ">>file.txt") || die (print "$!\n");
                	print FILE $ENV{'QUERY_STRING'} . "\n";
                	close(FILE);
                }
                Here is some perl code you can use.
                Many thanks I'll have a go at getting this to work
                I sale lube

                Comment

                • hudson
                  Confirmed User
                  • Jul 2003
                  • 2948

                  #9
                  Originally posted by icedemon
                  Code:
                  #!/usr/bin/perl
                  
                  print "Content-type: text/plain\n\n";
                  if ($ENV{'QUERY_STRING'}) {
                  	open(FILE, ">>file.txt") || die (print "$!\n");
                  	print FILE $ENV{'QUERY_STRING'} . "\n";
                  	close(FILE);
                  }
                  Here is some perl code you can use.
                  you can add to the code after the first print statement...for example:


                  print "<b>hello there</b>";

                  to print to the browser....just remember the semicolon to terminate the statement and to "escape" things like a quotation mark:

                  print "<a href=\"./dir/index.html\">home</a>";

                  see... add a backslash before the quotation mark: \"
                  Last edited by hudson; 01-05-2004, 05:37 PM.

                  Comment

                  • AssFairy
                    Confirmed User
                    • Jun 2003
                    • 674

                    #10
                    It don't appear to be working, for some reason when I click the link I get redirected to my 404 page!!!

                    I used unix format when I uploaded the script and set the test.pl file and the file.txt to 666 (chmod)
                    I sale lube

                    Comment

                    • icedemon
                      Confirmed User
                      • Jun 2003
                      • 1022

                      #11
                      You need to chmod the test.pl to 755 if it's not set to that already. Show the link and I'll see what might be happening. You can also check your error log files to see what might be happening to.
                      Clips4Sale.com

                      Comment

                      • hudson
                        Confirmed User
                        • Jul 2003
                        • 2948

                        #12
                        probably has something to do with your directory not allowing a cgi type file. so it rejects the file and redirects you a la .htaccess

                        well, that's my guess...any others?

                        Comment

                        • AssFairy
                          Confirmed User
                          • Jun 2003
                          • 674

                          #13
                          Originally posted by icedemon
                          You need to chmod the test.pl to 755 if it's not set to that already. Show the link and I'll see what might be happening. You can also check your error log files to see what might be happening to.
                          Yeeeeeeeeeeeeeeeeeeeeah baby that works FINE

                          Thanks for the help peeps I can get on with saving the world now
                          I sale lube

                          Comment

                          • hudson
                            Confirmed User
                            • Jul 2003
                            • 2948

                            #14
                            Originally posted by AssFairy
                            Yeeeeeeeeeeeeeeeeeeeeah baby that works FINE

                            Thanks for the help peeps I can get on with saving the world now
                            cool beans...now you have experienced the life of a programmer

                            Comment

                            • AssFairy
                              Confirmed User
                              • Jun 2003
                              • 674

                              #15
                              Originally posted by hudson


                              cool beans...now you have experienced the life of a programmer

                              I don't know about that but I think I had a small orgasm when I saw it work (at last)
                              I sale lube

                              Comment

                              • hudson
                                Confirmed User
                                • Jul 2003
                                • 2948

                                #16
                                Originally posted by AssFairy
                                I don't know about that but I think I had a small orgasm when I saw it work (at last)
                                yep...that's it...absolute terror followed by a small orgasm

                                Comment

                                • Rorschach
                                  So Fucking Banned
                                  • Aug 2002
                                  • 5579

                                  #17
                                  and that aching feeling in your nuts like you can't sit still when it just won't fucking work

                                  Comment

                                  • hudson
                                    Confirmed User
                                    • Jul 2003
                                    • 2948

                                    #18
                                    Originally posted by Rorschach
                                    and that aching feeling in your nuts like you can't sit still when it just won't fucking work

                                    Comment

                                    Working...