Run PHP function after 5 min from the page done load


#1

I want to run PHP code update a row in my database when the user did 5 min in the page. can I do this check for the time spent in PHP or I have to do it in javascript
and how can i do so.

and am getting this error every time i try to set new cookie .

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\public_html\inc\mainheader.php:7) in C:\xampp\htdocs\public_html\functions\dynamic-function.php on line 876


#2

Hi @AwadGorg!

Please add…

php_value output_buffering on

…to /public_html/.htaccess. If the file does not exist, create one and append the upper string :wink:


#3

am already have this code in my .htaccess and am working in my localhost


#4

i took all my functions and but it before the <!doctype html> to be the first headers that sent in the page some of my code work when i did this but other still giving me the same error


#5

In this case you may need to use ob_start() / ob_end_flush()

php.net/ob_start
php.net/ob_end_flush


#6

I used the code you suggested

ob_start() / ob_end_flush()
iand nothing happend still the same problem


#7

I put the set-cookie at line one to be the first header sent by still the same problem

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\public_html\inc\mainheader.php:17) in C:\xampp\htdocs\public_html\inc\mainheader.php on line 1

this starting to become unsolvable


#8

Maybe .htaccess ain’t working on your local system?


#9

this rewrite rule works fine in my localhost but the php buffering has no effect

php_value output_buffering on

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

#10

Try placing session_start(); at the top of your code


#11

Make sure you send absolutely no header: header() after any other text data. That’s the issue.

Wrong:

print('love you!');

header('some header here..');


<div>[....]</div>

<?php header('some header here.'); ?>

Right:

<?php header('....'); ?>

<div>...</div>

#12

but if i go with the right method the div below the header wont work cause it will redirect the user that mean ever code below the header function will stop.
and what i want is to set a cookie not to send a header

and write now am setting the cookie at line 1 as the irst header in the document
but am still getting the same error

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\public_html\inc\mainheader.php:7 ''i have the doctype in this lin) in C:\xampp\htdocs\public_html\functions\dynamic-function.php on line 1


#13

and i already have a session start in line 1


#14

i have a better idea if i created the cookie with JavaScript and handle it with my PHP
code will this gonna effect my code


#15

Try php_flag output_buffering on

_flag instead of _value

I don’t recommend you to use ob_start and ob_end_flush functions because it makes your scripts messy.

.htacces code should fix your problem :wink:


#16

will it worked thanks very much. but I already used javascript to set my cookies but am sure that this will be helpful in the future. thanks again


#17