Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10450
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Counter reset or not? UPDATE |
| Date | 2013-08-08 15:28 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <ku1625$4v6$1@dont-email.me> (permalink) |
| References | <ktulqb$rmk$1@speranza.aioe.org> <ku0qfr$da5$1@speranza.aioe.org> |
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();
?>
*******************
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web