Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10435 > unrolled thread
| Started by | Twayne <nobody@spamcop.net> |
|---|---|
| First post | 2013-08-07 19:38 -0400 |
| Last post | 2013-08-09 14:05 -0400 |
| Articles | 14 — 6 participants |
Back to article view | Back to comp.lang.php
Counter reset or not? Twayne <nobody@spamcop.net> - 2013-08-07 19:38 -0400
Re: Counter reset or not? Richard Yates <richard@yatesguitar.com> - 2013-08-07 20:30 -0700
Re: Counter reset or not? Twayne <nobody@spamcop.net> - 2013-08-08 12:15 -0400
Re: Counter reset or not? Richard Yates <richard@yatesguitar.com> - 2013-08-10 05:49 -0700
Re: Counter reset or not? Twayne <nobody@spamcop.net> - 2013-08-08 15:13 -0400
Re: Counter reset or not? Richard Damon <Richard@Damon-Family.org> - 2013-08-08 00:06 -0400
Re: Counter reset or not? Twayne <nobody@spamcop.net> - 2013-08-08 12:19 -0400
Re: Counter reset or not? Twayne <nobody@spamcop.net> - 2013-08-08 15:14 -0400
Re: Counter reset or not? UPDATE Twayne <nobody@spamcop.net> - 2013-08-08 15:10 -0400
Re: Counter reset or not? UPDATE Scott Johnson <noonehome@chalupasworld.com> - 2013-08-08 15:28 -0700
Re: Counter reset or not? UPDATE Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-09 00:58 +0200
Re: Counter reset or not? UPDATE Jerry Stuckle <jstucklex@attglobal.net> - 2013-08-08 20:44 -0400
Re: Counter reset or not? UPDATE Twayne <nobody@spamcop.net> - 2013-08-09 14:07 -0400
Re: Counter reset or not? UPDATE Twayne <nobody@spamcop.net> - 2013-08-09 14:05 -0400
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-07 19:38 -0400 |
| Subject | Counter reset or not? |
| Message-ID | <ktulqb$rmk$1@speranza.aioe.org> |
Hi all,
I'm confused; this code isn't working and I don't know why; perhaps you
can tell me or at least point me in the right direction:
<code>
if($_SESSION["cntr"] > "0") {
echo "Count is now : " . $_SESSION["cntr"]." ";
}
ELSE {
$_SESSION['cntr']="0";
$cntr=$_SESSION['cntr'];
echo "Counter : " . $cntr."<br />";
}
</code>
OK: This code is on the first of 3 PHP form pages. The ELSE works fine.
If the count is zero, the initial count of "0" is echoed properly.
But if the code is 1 or greater, set on one of the two succeeding pages,
it still runs the ELSE code and insists on returning the value of "0".
I'm not using session_destroy, nor an I using die(), exit() or
anything else that should bother the SESSION var.
2. If the counter advances to 1 or more, however, when I send the user
back to the first page (where the above code resides), it still prints
the ELSE portion of the code, NOT what the SESSION var has been set to
(1 or greater).
I'm confused!! What am I doing wrong?
TIA,
Twayne`
O
[toc] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-08-07 20:30 -0700 |
| Message-ID | <vm3609dd1045p5be96rul18c9fipshsppc@4ax.com> |
| In reply to | #10435 |
On Wed, 07 Aug 2013 19:38:39 -0400, Twayne <nobody@spamcop.net> wrote:
>Hi all,
>
>I'm confused; this code isn't working and I don't know why; perhaps you
>can tell me or at least point me in the right direction:
>
><code>
>if($_SESSION["cntr"] > "0") {
> echo "Count is now : " . $_SESSION["cntr"]." ";
> }
> ELSE {
> $_SESSION['cntr']="0";
> $cntr=$_SESSION['cntr'];
> echo "Counter : " . $cntr."<br />";
> }
></code>
>
>OK: This code is on the first of 3 PHP form pages. The ELSE works fine.
>If the count is zero, the initial count of "0" is echoed properly.
>
>But if the code is 1 or greater, set on one of the two succeeding pages,
> it still runs the ELSE code and insists on returning the value of "0".
>
> I'm not using session_destroy, nor an I using die(), exit() or
>anything else that should bother the SESSION var.
>2. If the counter advances to 1 or more, however, when I send the user
>back to the first page (where the above code resides), it still prints
>the ELSE portion of the code, NOT what the SESSION var has been set to
>(1 or greater).
>
>I'm confused!! What am I doing wrong?
>
>TIA,
>
>Twayne`
>O
Your code works here if I set $_SESSION['cntr'] just above the if
statement.
Have you tried echoing $_SESSION['cntr'] before the if statement to
confirm that it is what you think it is?
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-08 12:15 -0400 |
| Message-ID | <ku0g77$eik$1@speranza.aioe.org> |
| In reply to | #10437 |
On 2013-08-07 11:30 PM, Richard Yates wrote:
> On Wed, 07 Aug 2013 19:38:39 -0400, Twayne <nobody@spamcop.net> wrote:
>
>> Hi all,
>>
>> I'm confused; this code isn't working and I don't know why; perhaps you
>> can tell me or at least point me in the right direction:
>>
>> <code>
>> if($_SESSION["cntr"] > "0") {
>> echo "Count is now : " . $_SESSION["cntr"]." ";
>> }
>> ELSE {
>> $_SESSION['cntr']="0";
>> $cntr=$_SESSION['cntr'];
>> echo "Counter : " . $cntr."<br />";
>> }
>> </code>
>>
>> OK: This code is on the first of 3 PHP form pages. The ELSE works fine.
>> If the count is zero, the initial count of "0" is echoed properly.
>>
>> But if the code is 1 or greater, set on one of the two succeeding pages,
>> it still runs the ELSE code and insists on returning the value of "0".
>>
>> I'm not using session_destroy, nor an I using die(), exit() or
>> anything else that should bother the SESSION var.
>> 2. If the counter advances to 1 or more, however, when I send the user
>> back to the first page (where the above code resides), it still prints
>> the ELSE portion of the code, NOT what the SESSION var has been set to
>> (1 or greater).
>>
>> I'm confused!! What am I doing wrong?
>>
>> TIA,
>>
>> Twayne`
>> O
>
> Your code works here if I set $_SESSION['cntr'] just above the if
> statement?
Specifically what do you mean by 'set" it above the if? I've tried
various methods of "setting" $_SESSION['cntr'] before the IF, but ...
nothing changes or I get a Notice of an undefined variable if I try to
, say, echo $_SESSION["cntr"] . "<br />"; , it also reports 0! So
somehow, the session variable never makes it back to the first page.
Further to the above, I do not have a value pre-set for the related
input field.
Here's the code from the second page where an error is being purposely
generated if it helps any:
<code>
echo "Counter was : " . $_SESSION["cntr"] . "<br />";
if(strlen($zip)< "5") {
$cntr=$_SESSION["cntr"] + "1";
echo "Counter is " .$cntr."<br />" ;
}
</code>
Both echo statements work, with the expected results when an error
occurs. It's 0 for the first echo, and 1 for the last echo.
Apparently somehow I am destroying the contents of the session var but
darned if I can find it!
An further thoughts or comments would be appreciated; feel free to be
brutal; I'm sure it's something very basic I'm doing. I am in the
process of creating files with nothing but the counter session to get a
closer look maybe.
My sincere apologies for not providing entire code for the pages; it's
simply not allowed.
>
> Have you tried echoing $_SESSION['cntr'] before the if statement to
> confirm that it is what you think it is?
>
No, but ... if I do, it shows $SESSION["cntr"] to be "0". And that
means it's somehow trashing the vars somewhere I'm not aware of.
Thanks much for your response; it at least put things into a better
prospective for me. I think :)
Twayne`
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-08-10 05:49 -0700 |
| Message-ID | <emdc09humm0ff6hs2q9qirb1qugkq9r4ca@4ax.com> |
| In reply to | #10443 |
On Thu, 08 Aug 2013 12:15:30 -0400, Twayne <nobody@spamcop.net> wrote:
>>> <code>
>>> if($_SESSION["cntr"] > "0") {
>>> echo "Count is now : " . $_SESSION["cntr"]." ";
>>> }
>>> ELSE {
>>> $_SESSION['cntr']="0";
>>> $cntr=$_SESSION['cntr'];
>>> echo "Counter : " . $cntr."<br />";
>>> }
>>> </code>
>Specifically what do you mean by 'set" it above the if?
It's part of a basic debugging strategy. If a script is not working,
start breaking it into smaller pieces to see how variables change as
it flows. You are using two pages and session variables. You don't
know if the session variable is being set wrong, or is not accessible
to page 2, or page 2 is faulty. So...
on page 2 insert the line:
$_SESSION['cntr']=1;
before:
if($_SESSION["cntr"] > "0") {
If the results are still screwy then the problem is on page 2. If they
are correct, then the problem is page 1 or in accessing the session
variable on page 2.
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-08 15:13 -0400 |
| Message-ID | <ku0qlg$dd6$1@speranza.aioe.org> |
| In reply to | #10437 |
On 2013-08-07 11:30 PM, Richard Yates wrote: > On Wed, 07 Aug 2013 19:38:39 -0400, Twayne <nobody@spamcop.net> wrote: > Please see my Update for the current situation. It has changed and so has the code. Twayne`
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2013-08-08 00:06 -0400 |
| Message-ID | <ZOEMt.6704$Mq1.3256@en-nntp-05.dc1.easynews.com> |
| In reply to | #10435 |
On 8/7/13 7:38 PM, Twayne wrote:
> Hi all,
>
> I'm confused; this code isn't working and I don't know why; perhaps you
> can tell me or at least point me in the right direction:
>
> <code>
> if($_SESSION["cntr"] > "0") {
> echo "Count is now : " . $_SESSION["cntr"]." ";
> }
> ELSE {
> $_SESSION['cntr']="0";
> $cntr=$_SESSION['cntr'];
> echo "Counter : " . $cntr."<br />";
> }
> </code>
>
> OK: This code is on the first of 3 PHP form pages. The ELSE works fine.
> If the count is zero, the initial count of "0" is echoed properly.
>
> But if the code is 1 or greater, set on one of the two succeeding pages,
> it still runs the ELSE code and insists on returning the value of "0".
>
> I'm not using session_destroy, nor an I using die(), exit() or anything
> else that should bother the SESSION var.
> 2. If the counter advances to 1 or more, however, when I send the user
> back to the first page (where the above code resides), it still prints
> the ELSE portion of the code, NOT what the SESSION var has been set to
> (1 or greater).
>
> I'm confused!! What am I doing wrong?
>
> TIA,
>
> Twayne`
> O
Have you called session_start() (or set session.auto_start) ?
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-08 12:19 -0400 |
| Message-ID | <ku0ge6$f78$1@speranza.aioe.org> |
| In reply to | #10438 |
On 2013-08-08 12:06 AM, Richard Damon wrote:
> On 8/7/13 7:38 PM, Twayne wrote:
>> Hi all,
>>
>> I'm confused; this code isn't working and I don't know why; perhaps you
>> can tell me or at least point me in the right direction:
>>
>> <code>
>> if($_SESSION["cntr"] > "0") {
>> echo "Count is now : " . $_SESSION["cntr"]." ";
>> }
>> ELSE {
>> $_SESSION['cntr']="0";
>> $cntr=$_SESSION['cntr'];
>> echo "Counter : " . $cntr."<br />";
>> }
>> </code>
>>
>> OK: This code is on the first of 3 PHP form pages. The ELSE works fine.
>> If the count is zero, the initial count of "0" is echoed properly.
>>
>> But if the code is 1 or greater, set on one of the two succeeding pages,
>> it still runs the ELSE code and insists on returning the value of "0".
>>
>> I'm not using session_destroy, nor an I using die(), exit() or anything
>> else that should bother the SESSION var.
>> 2. If the counter advances to 1 or more, however, when I send the user
>> back to the first page (where the above code resides), it still prints
>> the ELSE portion of the code, NOT what the SESSION var has been set to
>> (1 or greater).
>>
>> I'm confused!! What am I doing wrong?
>>
>> TIA,
>>
>> Twayne`
>> O
>
> Have you called session_start() (or set session.auto_start) ?
>
Yes; session_start(). set session.auto_start I wasn't aware of though;
something else to check out.
Thanks much,
Twayne
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-08 15:14 -0400 |
| Message-ID | <ku0qmv$dd6$2@speranza.aioe.org> |
| In reply to | #10438 |
On 2013-08-08 12:06 AM, Richard Damon wrote: Richard, Please see my Update for the current situation. It has changed and so has the code. Twayne` >
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-08 15:10 -0400 |
| Subject | Re: Counter reset or not? UPDATE |
| Message-ID | <ku0qfr$da5$1@speranza.aioe.org> |
| In reply to | #10435 |
Hi,
In troubleshooting the above, I've ended up creating two pages of as
minimal code as I know how to make it <g>. I now have working code,
BUT(t), it's throwing a warning I don't know how to address. ALL work is
being done on my Local Apache Server (XAMPP) and PHP 5.3 (same as my
Remote Server uses).
The session is almost working, and it IS incrementing properly. This is
a code sample I picked up at php.net and it's supposedly applicable to
version 4 and 5. I've removed the href to link to the next page and
instead am now using a Submit Button: Same identical results whether the
link line exists or not so I removed it and things still work the same.
By being as basic with the code as I have been, I've removed the
implications of anything else in the code effecting it.
Page 1: PHP code:\
============
<?php
session_start();
// counter1.php
if (empty($_SESSION['cntr'])) {
$_SESSION['cntr'] = 1;
} else {
$_SESSION['cntr']++;
}
?>
<p>
Hello visitor, you have seen this page <?php echo $_SESSION['cntr']; ?>
times.
</p>
<form action="counter2.php" method="post">
Type something: <input type="text" name = "type" <br />
<p> <input type="submit" value="NEXT">
<input type= "reset" value="Clear Form" /> <br />
</form>
</body>
</html>
======= end =========
Page 2: PHP:
<?php
session_start();
// counter2.php
echo $_SESSION["cntr"]. " Before increment. <br />";
$_SESSION["cntr"] = $_SESSION["cntr"]+ "1";
echo $_SESSION["cntr"] . " After increment";
?>
Next (Submit button) here.
========== end ==========
It's acting strangely, at least to me. The first time I run, nothing
initialized, Counter1.php, the results are:
======== start =================
Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
C:\xampp\htdocs\counter1.php:2) in C:\xampp\htdocs\counter1.php on line 3
Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
C:\xampp\htdocs\counter1.php:2) in C:\xampp\htdocs\counter1.php on line 3
Hello visitor, you have seen this page 1 times.
Type something:
============ end =============
The input statement and Forms structure is only so I can use Submit
instead of the link the original code used.
======== start =================
If I click Submit (Next), the second page displays:
Notice: Undefined index: cntr in C:\xampp\htdocs\counter2.php on line 4
Before increment: <nothing>
Notice: Undefined index: cntr in C:\xampp\htdocs\counter2.php on line 5
1 After increment
============ end =============
Now, reloading/refreshing counter1.php results in the following screen
display:
============== start ==========
Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
C:\xampp\htdocs\counter1.php:2) in C:\xampp\htdocs\counter1.php on line 3
Hello visitor, you have seen this page 2 times.
Next (Submit)
=============== end =========
Now counter2.php, the 2nd page, works as I expected and shows:
=========== start ============
2 Before increment.
3 After increment
=========== End =============
And so on, adinfinitum.
So the counter IS incrementing and displaying properly on the
counter1.php page with the exception now only one Warning appears, not
two as in the first time it's run, where there were two statements
returned.
An interesting sidelight is:
Should I run a different script, the original one I asked questions
with, IT ALSO shows the incrementing count! I suppose it makes sense
since the session is never Unset in the new code, but a cute happening
anyway IMO; something to keep in mind!
So, to synopsize:
The very first time counter1.php runs, the counter show "1" as
expected, and two Warnings about headers already sent.
Clicking to go to the next page, show the two errors as above,
And after that, the first page shows only one Warning, and the 2nd
page works flawlessly. That will continue until the session is closed or
the browser closed.
Any solutions, thoughts, comments certainly appreciated!
Twayne`
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-08-08 15:28 -0700 |
| Subject | Re: Counter reset or not? UPDATE |
| Message-ID | <ku1625$4v6$1@dont-email.me> |
| In reply to | #10445 |
On 8/8/2013 12:10 PM, Twayne wrote:
> Hi,
>
> In troubleshooting the above, I've ended up creating two pages of as
> minimal code as I know how to make it <g>. I now have working code,
> BUT(t), it's throwing a warning I don't know how to address. ALL work is
> being done on my Local Apache Server (XAMPP) and PHP 5.3 (same as my
> Remote Server uses).
>
> The session is almost working, and it IS incrementing properly. This is
> a code sample I picked up at php.net and it's supposedly applicable to
> version 4 and 5. I've removed the href to link to the next page and
> instead am now using a Submit Button: Same identical results whether the
> link line exists or not so I removed it and things still work the same.
> By being as basic with the code as I have been, I've removed the
> implications of anything else in the code effecting it.
>
> Page 1: PHP code:\
> ============
> <?php
> session_start();
> // counter1.php
> if (empty($_SESSION['cntr'])) {
> $_SESSION['cntr'] = 1;
> } else {
> $_SESSION['cntr']++;
> }
> ?>
> <p>
> Hello visitor, you have seen this page <?php echo $_SESSION['cntr']; ?>
> times.
> </p>
> <form action="counter2.php" method="post">
> Type something: <input type="text" name = "type" <br />
> <p> <input type="submit" value="NEXT">
> <input type= "reset" value="Clear Form" /> <br />
> </form>
> </body>
> </html>
> ======= end =========
>
> Page 2: PHP:
> <?php
> session_start();
> // counter2.php
> echo $_SESSION["cntr"]. " Before increment. <br />";
> $_SESSION["cntr"] = $_SESSION["cntr"]+ "1";
> echo $_SESSION["cntr"] . " After increment";
> ?>
> Next (Submit button) here.
> ========== end ==========
>
>
> It's acting strangely, at least to me. The first time I run, nothing
> initialized, Counter1.php, the results are:
>
> ======== start =================
> Warning: session_start() [function.session-start]: Cannot send session
> cookie - headers already sent by (output started at
> C:\xampp\htdocs\counter1.php:2) in C:\xampp\htdocs\counter1.php on line 3
>
> Warning: session_start() [function.session-start]: Cannot send session
> cache limiter - headers already sent (output started at
> C:\xampp\htdocs\counter1.php:2) in C:\xampp\htdocs\counter1.php on line 3
>
> Hello visitor, you have seen this page 1 times.
>
> Type something:
>
> ============ end =============
>
> The input statement and Forms structure is only so I can use Submit
> instead of the link the original code used.
> ======== start =================
> If I click Submit (Next), the second page displays:
>
> Notice: Undefined index: cntr in C:\xampp\htdocs\counter2.php on line 4
> Before increment: <nothing>
>
> Notice: Undefined index: cntr in C:\xampp\htdocs\counter2.php on line 5
> 1 After increment
>
> ============ end =============
>
> Now, reloading/refreshing counter1.php results in the following screen
> display:
>
> ============== start ==========
> Warning: session_start() [function.session-start]: Cannot send session
> cache limiter - headers already sent (output started at
> C:\xampp\htdocs\counter1.php:2) in C:\xampp\htdocs\counter1.php on line 3
>
> Hello visitor, you have seen this page 2 times.
>
> Next (Submit)
> =============== end =========
>
> Now counter2.php, the 2nd page, works as I expected and shows:
> =========== start ============
> 2 Before increment.
> 3 After increment
> =========== End =============
>
> And so on, adinfinitum.
> So the counter IS incrementing and displaying properly on the
> counter1.php page with the exception now only one Warning appears, not
> two as in the first time it's run, where there were two statements
> returned.
>
> An interesting sidelight is:
> Should I run a different script, the original one I asked questions
> with, IT ALSO shows the incrementing count! I suppose it makes sense
> since the session is never Unset in the new code, but a cute happening
> anyway IMO; something to keep in mind!
>
> So, to synopsize:
> The very first time counter1.php runs, the counter show "1" as
> expected, and two Warnings about headers already sent.
> Clicking to go to the next page, show the two errors as above,
> And after that, the first page shows only one Warning, and the 2nd
> page works flawlessly. That will continue until the session is closed or
> the browser closed.
>
> Any solutions, thoughts, comments certainly appreciated!
>
> Twayne`
>
>
>
>
>
>
>
>
>
>
I have not read the entire post but just from the error it seems you may
be sending output PRIOR to session_start.
session_start MUST be the first line after the PHP delimiter.
*************
<?php
session_start();
....
?>
****************
One of the biggest overlooked mistakes is having a blank space prior to
the delimiter. This is sometimes caused by the text editor.
***************
<- blank space will be sent.
<?php
session_start();
?>
*******************
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-08-09 00:58 +0200 |
| Subject | Re: Counter reset or not? UPDATE |
| Message-ID | <52042283$0$6554$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #10450 |
Scott Johnson wrote: > One of the biggest overlooked mistakes is having a blank space prior to > the delimiter. This is sometimes caused by the text editor. If one is working with UTF-8 encoded PHP files, there may be even an "invisible" BOM before the opening PHP tag; so one should always save those files without a BOM. However, if a BOM or any whitespace in front of the opening PHP tag causes any trouble is mostly depending on the PHP ini setting output_buffering[1]. I usually set this to "Off" in the development environment, so I can catch these "headers already sent" errors early. [1] <http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering> -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-08-08 20:44 -0400 |
| Subject | Re: Counter reset or not? UPDATE |
| Message-ID | <ku1e26$5a9$3@dont-email.me> |
| In reply to | #10452 |
On 8/8/2013 6:58 PM, Christoph Michael Becker wrote: > Scott Johnson wrote: > >> One of the biggest overlooked mistakes is having a blank space prior to >> the delimiter. This is sometimes caused by the text editor. > > If one is working with UTF-8 encoded PHP files, there may be even an > "invisible" BOM before the opening PHP tag; so one should always save > those files without a BOM. > > However, if a BOM or any whitespace in front of the opening PHP tag > causes any trouble is mostly depending on the PHP ini setting > output_buffering[1]. I usually set this to "Off" in the development > environment, so I can catch these "headers already sent" errors early. > > [1] > <http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering> > In general, buffering should be set to off in production systems. With proper design of your code, you don't need output buffering, and it just adds one more layer of processing to the scripts. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-09 14:07 -0400 |
| Subject | Re: Counter reset or not? UPDATE |
| Message-ID | <ku3b4n$sne$2@speranza.aioe.org> |
| In reply to | #10452 |
On 2013-08-08 6:58 PM, Christoph Michael Becker wrote: > Scott Johnson wrote: > >> One of the biggest overlooked mistakes is having a blank space prior to >> the delimiter. This is sometimes caused by the text editor. > > If one is working with UTF-8 encoded PHP files, there may be even an > "invisible" BOM before the opening PHP tag; so one should always save > those files without a BOM. > > However, if a BOM or any whitespace in front of the opening PHP tag > causes any trouble is mostly depending on the PHP ini setting > output_buffering[1]. I usually set this to "Off" in the development > environment, so I can catch these "headers already sent" errors early. > > [1] > <http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering> > Sounds like good information; thanks for that. Twayne`
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-08-09 14:05 -0400 |
| Subject | Re: Counter reset or not? UPDATE |
| Message-ID | <ku3b0u$sne$1@speranza.aioe.org> |
| In reply to | #10450 |
On 2013-08-08 6:28 PM, Scott Johnson wrote:
> On 8/8/2013 12:10 PM, Twayne wrote:
>> Hi,
>>
...
>> Page 1: PHP code:\
>> ============
>> <?php
>> session_start();
>> // counter1.php
>> if (empty($_SESSION['cntr'])) {
>> $_SESSION['cntr'] = 1;
>> } else {
>> $_SESSION['cntr']++;
>> }
>> ?>
>> <p>
>> Hello visitor, you have seen this page <?php echo $_SESSION['cntr']; ?>
>> times.
>> </p>
>> <form action="counter2.php" method="post">
>> Type something: <input type="text" name = "type" <br />
>> <p> <input type="submit" value="NEXT">
>> <input type= "reset" value="Clear Form" /> <br />
>> </form>
>> </body>
>> </html>
>> ======= end =========
>>
>> Page 2: PHP:
>> <?php
>> session_start();
>> // counter2.php
>> echo $_SESSION["cntr"]. " Before increment. <br />";
>> $_SESSION["cntr"] = $_SESSION["cntr"]+ "1";
>> echo $_SESSION["cntr"] . " After increment";
>> ?>
>> Next (Submit button) here.
>> ========== end ==========
>>
>>
...
>>
>> Any solutions, thoughts, comments certainly appreciated!
>>
>> Twayne`
>>
>
> I have not read the entire post but just from the error it seems you may
> be sending output PRIOR to session_start.
>
> session_start MUST be the first line after the PHP delimiter.
>
> *************
> <?php
> session_start();
>
>
> ....
> ?>
> ****************
>
> One of the biggest overlooked mistakes is having a blank space prior to
> the delimiter. This is sometimes caused by the text editor.
>
>
>
>
> ***************
> <- blank space will be sent.
> <?php
> session_start();
>
>
> ?>
> *******************
Thanks for that, really, although I have it properly positioned.
The situation is now resolved, although I cannot (easily) tell you what
changes I made; I forgot to zip them up.
Basically I deleted the whole code and rewrote from scratch, as I
thought it should be done. And that started to work flawlessly. The
basic code is now:
==========
if(isset($_SESSION['reload']))
$_SESSION['reload']=$_SESSION['reload']+1;
else
$_SESSION['reload']=0;
// echo "This Page reloads = ". $_SESSION['reload']."<br />";
if($_SESSION['reload'] >= 3) {
echo "You have reloaded this page too many times. Statistics indicate
that you <br />most likely are not a legitimate visitor. If you are,
close and reopen your <br />browser, and go to the website, to restart
the form process <br /> after a half hour or so." ;
session_destroy();
die();
}
===========
Page reloads isn't as good as getting specific errors, but I'm working
on that too.
So, thanks anyway, it's appreciated input.
Twayne`
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web