473,799 Members | 3,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GET vs POST related problem solved

1 New Member
FYI - If you are a computer scientist (or geek), this post may be for you.

I wanted to log any search keywords, etc that are used on my site. I created a simple
program that logs search terms into a log file. The problem I experienced was that
I was getting double entries in the log... that is, when writing to the file, each line I
wrote to the file was repeated twice.

How was that possible? Scanning the code provided no clues. The PHP code in the file is in-line, there are no control structures, so looping is not possible. The changing datestamp on duplicate lines proved that the file was being called from 1 to 3 times... bizarre.

After mucho, mucho hours spent tweaking the code and scanning the net for similar problems (couldn't find any) I almost gave up.

The solution I stumbled on (last thing I could tweak) was to change the search form's METHOD to "POST" from "GET."

It appears (see below) that the GET was somehow running the ACTION processing file from one to three times. Sounds bizarre, but
I have proof that it happened! It is re-creatable. Try it yourself.

Go figure... I'm posting this information in case some other poor soul spends hours trying to figure out a similar double logging problem.

Not sure why the difference between POST vs GET solves the problem - but I'm happy to have stumbled upon a workable solution after many hours... and no joy searching the web for an answer, either.

Any explanation(s) for this strange behavior would be greatly appreciated.

Peter Deac Bakke, Tucson AZ

PS. Website is running PHP4, hosted on www.globalserve rs.com



---------


Input form:

<form action="searchc ode.php" method="GET">

// NOTE:
// To fix my problem, the line above was changed to <form action="searchc ode.php" method="POST">
// The following form is in a table, but I've stripped the table tags out for brevity



<b>Website Name or URL: </b><br />
<input type="text" name="name_form ">


<b> Enter Keywords or Phrases:
<input type="text" name="keywords_ form">

<b>Enter state: </b>

<select name="location_ form">
<option value="" selected="selec ted">None</option>
<option value="US">US - National</option>
<option value="AL">Alab ama</option>
.
.
.
//note: all states are listed as options... they have been removed here for brevity

</select>


<b>Enter Viewpoint : </b> <br />
[PHP]
<?php
include($DOCUME NT_ROOT . "viewpoint.php" );
?>
[/PHP]
<b>Enter Website Type: </b><br />
[PHP]
<?php
include($DOCUME NT_ROOT . "type.php") ;
?>
[/PHP]

<input type="submit" value="Search Websites">
<INPUT value="Clear Fields" type="reset">


</form>


---------



[PHP]

$filecontents = "";

// Time stamp
$timenow = date("Ymd, G:i:s T");
$filecontents .= ($timenow . "|");


if ( ($name_form != NULL) ) {
$filecontents .= ("Name/URL=" . $name_form . "|");
}
if ( ($location_form != NULL) ) {
$filecontents .= ("State=" . $location_form . "|");
}
if ( ($viewpoint_for m != NULL) ) {
$filecontents .=("Viewpoint= " . $viewpoint_form . "|");
}
if ( ($type_form != NULL) ) {
$filecontents .=("Type=" . $type_form . "|");
}
if ( ($keywords_form != NULL) ) {
$filecontents .=("Keywords=" . $keywords_form . "|");
}

$filecontents .= "\n";

$filetoopen = "$pathtofil e . search.log";
$searchlog1 = fopen($filetoop en, "a");
fwrite($searchl og1, $filecontents);
fclose ($searchlog1);
[/PHP]

---------


Meanwhile, in the output file:

// WHILE USING METHOD="GET" in the input form, writing to the file resulted in DOUBLE entries seen below
// Note that the TIMESTAMP at the beginning of duplicate lines is one second later... meaning the
// file's code is executing twice, sometimes three times(!). That is to say, to the best of my knowledge, the action file was
// being called multiple times, somehow. The PHP code in the file performing the writing is in-line, there is no control structure
// or looping in the file, making in-file duplicate writing impossible. The ACTION file must have been called more than once.
// The datestamp differences prove that the php file was executed more than once (!?) ... I even saw three duplicate lines
// occasionally with three different timestamps written to the file.

20061107, 1:07:31 MST|Keywords=zz XXZZXXZ|
20061107, 1:07:32 MST|Keywords=zz XXZZXXZ|
20061107, 1:08:43 MST|Keywords=wh atever|
20061107, 1:08:44 MST|Keywords=wh atever|
20061107, 1:10:53 MST|Name/URL=zxczcxxc|St ate=AL|Keywords =zxczcz|
20061107, 1:10:54 MST|Name/URL=zxczcxxc|St ate=AL|Keywords =zxczcz|
20061107, 1:10:55 MST|Name/URL=zxczcxxc|St ate=AL|Keywords =zxczcz|

// Then, after CHANGING THE INPUT FORM TO USE METHOD="POST", writing output to file was AOKAY - no double entries!!
// Go figure

20061107, 1:13:44 MST|State=AK|
20061107, 1:14:39 MST|State=DE|
20061107, 1:22:03 MST|Name/URL=xyxyxyxyxy| State=KS|Keywor ds= |
20061107, 1:34:11 MST|Name/URL=primary|
20061107, 1:36:50 MST|State=NH|
20061107, 1:38:02 MST|Keywords=fg fghfdh|
20061107, 1:45:33 MST|Name/URL=dfsdfsd|Typ e=Academic|


----END

Again, any explanation(s) for this strange behavior would be greatly appreciated.

Peter Deac Bakke, Tucson AZ
Nov 7 '06 #1
0 2023

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2079
by: Ziaran _ | last post by:
I have written a new debugger. I think people will find it useful. Where can I post it for people to download? Thanks, Nir _________________________________________________________________ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail
2
2483
by: Hans Forbrich | last post by:
The following is a Request for Discussion, following up on some recent posts about distributing a periodic news group 'Charter and FAQ' post. While not formally following RFC/RFD rules, the intent is to use the rules as a guide for the discussion and make a more formal Request for Comment and a follow-up formal vote, possibly before year-end. Proposal: That the following be posted weekly for this news group:
0
1846
by: QWERTY | last post by:
--------------Boundary-00=_O5I3QL80000000000000 Content-Type: Multipart/Alternative; boundary="------------Boundary-00=_O5I3LVC0000000000000" --------------Boundary-00=_O5I3LVC0000000000000 Content-Type: Text/Plain; charset="iso-8859-9" Content-Transfer-Encoding: quoted-printable
1
1679
by: F. Da Costa | last post by:
Hi, In the html (as shown below) there are some <a> tags I need to move into a map. This is no problem (in Gecko) using the js below. However, IE 5+ (nor 6) does not want to play. It gives me an "undefined" error and basically does not give me the objects I expect. Undoubtfully one *can* get a hold of these objects and obviously this is the question. How does one do this in IE??
12
3826
by: Jan Roland Eriksson | last post by:
I have worked some more on this suggested new mFAQ version trying to get all user input to blend into the text. Another review by the NG would be welcome. ===== Archive-name: www/stylesheets/newsgroup-faq Posting-Frequency: once a week Last-modified: July 22, 2004
16
2074
by: Shelly | last post by:
(posted previously on comp.lang.php but no response received. Cross-posted in the dreamweaver forum) I am confused about what goes on with method POST. Here is an overview of a my code, sketching it out: <?php if (isset($_POST) && $_POST=="Submit") { ---Do a bunch of stuff--- if (isset($_SESSION)) unset($_SESSION);
5
17392
by: Tammy | last post by:
Hi, I have an aspx app which needs to post data to a form and read the response. I am confused on whether I should be using the get_url using "POST" method or the post_url using "GET" method. string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains a form string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called by get_Url upon submit
2
1858
by: ThunderMusic | last post by:
hi, I have 2 services running, one doing a job and the other monitoring the job is done and that the other service (the one doing the job) is still running. The thing is, the 1st service fire some events notifying other programs that an alert happened... I want to register to that event in my second service, but I just can't get it working... I receive the following message : Type System.DelegateSerializationHolder and the types...
10
2615
by: Schraalhans Keukenmeester | last post by:
I suspect the following problem IS hosting provider specific, but they haven't been able to help me out so far. Perhaps I am doing something wrong and someone is able to spot the issue... Here goes. The actual path of the root dir of my account with hosting provider (H.P.) is: /usr/local/psa/home/vhosts/mydomain.com/ The webroot is a subdir of the root: /usr/local/psa/home/vhosts/mydomain.com/httpdocs. Include files go in:
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.