Re: Counter reset or not? UPDATE [message #182516 is a reply to message #182497] |
Fri, 09 August 2013 18:05 |
bill
Messages: 310 Registered: October 2010
Karma:
|
Senior Member |
|
|
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`
|
|
|