473,786 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird incrementing problem

Here's the example:

You have a world writable file called lastquote.cfg on your server with a
one or two digit number in it. When you run the script below, it reads the
value, increments the value by one and then rewrites it into the file.

<?php
$fp = fopen("lastquot e.cfg", "r");
$data = fread($fp, 10);
fclose($fp);
echo "Last quote: ".$data."<b r>";

$qid = $data + 1;
$fp = fopen("lastquot e.cfg", "w");
echo "<br>".$qid ;
fwrite($fp, $qid);
fclose($fp);
?>
Sounds simple, right? My problem is that one one computer, this does
exactly as it should. It increments the value and writes the file. But on
my production server, the number will magically be incremented by two,
sometimes by one and I can't find an explanation. The strange thing is
that if I have it echo what it's going to write into the file, it echos the
correct value. But when it writes it, it's incorrect! Any idea what the
hell is going on?
Jul 17 '05 #1
6 1703
> But on my production server, the number will magically be incremented
by two,
sometimes by one and I can't find an explanation. The strange thing is
that if I have it echo what it's going to write into the file, it echos
the
correct value. But when it writes it, it's incorrect! Any idea what
the hell is going on?


If I may take a wild guess, the script is somehow invoked twice. Have you
checked whether there is only a single connection to your webserver
(it's being used on a webserver, isn't it?) that reqests the page
invoking the script? Maybe a forgotten code snippet on some other page?

Perhaps you should try to change the script's name? Or, even better,
simply log each invocation (with the filename/command-line of the script
that, say, included this script) to some local file, so that you are
able to check whether or not it is called from the right pages?

As I said, just some wild guesses...
Mike
Jul 17 '05 #2
Yeah, i think you invoke the script twice somehow! Good idea, change
the name of it and the file it uses and run it again!

Good Luck,Ovidiu
-----------------------------------
http://www.DevPlug.com -- Connecting Developers
Jul 17 '05 #3
Brian
I would be inclined to look at
a. ensuring $data is cast to an integer on reading (see php manual for
cast)
b. ensure $qid is cast to a string before writing
c. write spaces into the file beyond $qid, so that on reading back you don't
pick up other characters.
b. ensuring that each read or write is done from the right place (do a
reset on file in both cases.

failure to do point b could explain why it works when you print out $qid,
because printing it will force it to be a string.

- S

"Brian" <Th************ *@ddress.com> wrote in message
news:Xn******** *************** **@24.93.43.121 ...
Here's the example:

You have a world writable file called lastquote.cfg on your server with a
one or two digit number in it. When you run the script below, it reads
the
value, increments the value by one and then rewrites it into the file.

<?php
$fp = fopen("lastquot e.cfg", "r");
$data = fread($fp, 10);
fclose($fp);
echo "Last quote: ".$data."<b r>";

$qid = $data + 1;
$fp = fopen("lastquot e.cfg", "w");
echo "<br>".$qid ;
fwrite($fp, $qid);
fclose($fp);
?>
Sounds simple, right? My problem is that one one computer, this does
exactly as it should. It increments the value and writes the file. But
on
my production server, the number will magically be incremented by two,
sometimes by one and I can't find an explanation. The strange thing is
that if I have it echo what it's going to write into the file, it echos
the
correct value. But when it writes it, it's incorrect! Any idea what the
hell is going on?

Jul 17 '05 #4
Aha! That's what's going on. I used mail() to send me an email when it
runs, and I got two of them.

But why would the code snippet I posted earlier, put into a non-public PHP
file still run twice? Does it sound like an Apache or PHP configuration
problem?

If I may take a wild guess, the script is somehow invoked twice. Have you
checked whether there is only a single connection to your webserver
(it's being used on a webserver, isn't it?) that reqests the page
invoking the script? Maybe a forgotten code snippet on some other page?

Perhaps you should try to change the script's name? Or, even better,
simply log each invocation (with the filename/command-line of the script
that, say, included this script) to some local file, so that you are
able to check whether or not it is called from the right pages?

As I said, just some wild guesses...
Mike


Jul 17 '05 #5

Brian wrote:
Aha! That's what's going on. I used mail() to send me an email when it runs, and I got two of them.

But why would the code snippet I posted earlier, put into a non-public PHP file still run twice? Does it sound like an Apache or PHP configuration problem?


How is the script invoked?

Ken

Jul 17 '05 #6
Through a web browser.

The only way I could get it from loading twice was to record the epoch that
it last incremented and if it loads again within one second, don't
increment again. Apache has to be misconfigured somewhere because I've
never seen this behavior before.

"Ken Robinson" <ke******@rbnsn .com> wrote in news:1112288578 .518770.10090
@g14g2000cwa.go oglegroups.com:

Brian wrote:
Aha! That's what's going on. I used mail() to send me an email when

it
runs, and I got two of them.

But why would the code snippet I posted earlier, put into a

non-public PHP
file still run twice? Does it sound like an Apache or PHP

configuration
problem?


How is the script invoked?

Ken


Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2888
by: Mothra | last post by:
Here's what I'm trying to do (kill off old Unix logins): --------------------- $i=0; while (<$who>) { chomp($_); my @line = split(/\s+/, $_); # Split it into an array next unless ($line eq "old"); push @{$oldsessions}, @line; $i++;
4
1307
by: Sahil Malik [MVP] | last post by:
Okay so lets say I have a valuetype - lets say DateTime. Look at this code . List<DateTime> dt = new List<DateTime>() ; dt.Add(new dateTime(1999,12,1)) dt.AddDays(1) ; <--- This statement won't actually change the date time stored in the List<T> dt.
4
1390
by: Peter Afonin | last post by:
Hello, I have a weirdest issue I've ever had. I have a function that enters some data into the Oracle table and returns the sequential row number for the new record (autonumber): Private Function AddSystem(ByVal txt As TextBox, ByVal cn As OracleConnection) As Integer Try
10
4608
by: pozz | last post by:
Hi all, I need to write a simple incrementing/decrementing function like this: unsigned char change( unsigned char x, unsigned char min, unsigned char max, signed char d); x is the value to increase/decrease min is the minimum value that x can assume max is the maximum value that x can assume
5
3177
by: jerry | last post by:
I need to modify the code of a command-line tool. The source code starts out like this: int main(int argc, char *argv) { int ch, A, B ; while ((ch = getopt(argc, argv, "AB")) != -1) switch (ch) { case 'A':
3
2276
by: Adam Sandler | last post by:
Hello, I'm able to reproduce my problem but I haven't been able to figure out why it is happening. MS does have an article about such behavior in http://support.microsoft.com/default.aspx?scid=kb;en-us;Q320731 but the workaround prescribed in the KB isn't particularly helpful. The project I'm working on serves up a custom jpg image on the client side at runtime (think MapQuest or Google Maps). We use a COTS product here to handle...
53
4824
by: subramanian100in | last post by:
I saw this question from www.brainbench.com void *ptr; myStruct myArray; ptr = myArray; Which of the following is the correct way to increment the variable "ptr"? Choice 1 ptr = ptr + sizeof(ptr);
4
1199
by: parez | last post by:
Hi, GetNextSequenceNumber2 worked for me in a different class.. but now it does not work.. it does not increment.. will it not get incremented after the return?
9
3376
by: subramanian100in | last post by:
The following portion is from c-faq.com - comp.lang.c FAQ list · Question 6.13 int a1 = {0, 1, 2}; int a2 = {{3, 4, 5}, {6, 7, 8}}; int *ip; /* pointer to int */ int (*ap); /* pointer to array of int */\ ap = &a1; printf("%d\n", **ap);
0
9650
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
9497
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,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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,...
1
7515
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
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.