Interaction design • webdevelopment • web art • photography : forum : coding : '[php] refresh problem'

[php] refresh problem huphtur, 020421 03:31
i produced lil 'guestbook' php script. when refresh is pressed after a submit, i get IE alert: "The page cannot be refreshed without resending the information... etc etc. Retry/Cancel" Retry resubmits the form. Any idea how to resolve this?

(this is prolly the simplest problem in the book, but im drawing a big blank here, so i accept all flames heh)
Re: [php] refresh problem milov, 020421 10:25
header("Location: $HTTP_REFERER");
Re: [php] refresh problem huphtur, 020421 18:08
hrm.. took me a while to figure this one out
(since im absolute beginner)
but i put php in same page as the form
so got "cannot add header" warnings
now i split up the php from the page
the form now sends data thru seperate php
and in the php i put the header()
it works! even with an anchor!
Re: [php] refresh problem mados, 020422 14:50
All you have to do is to check if the submitted guestbook entry is equal to the entry submitted last. If they are, simply ignore the detected reload. This way no header() or something like that is needed. A reload will be ignored, regardless whether it was intentional or not.
Re: [php] refresh problem kutte, 020525 04:35
whats about:

header ("Location: $HTTP_REFERER");

dint try it, but should do it?
c c, 020818 03:13
Re: [php] refresh problem,jjmb,Jack, 020827 14:16
Same problem, but de solution gives this message:

Warning: Cannot add header information - headers already sent by (output started at /home/httpd/ in /home/httpd/ on line 180

Wat can be wrong?
It works locally (localhost)

Thanks in avance,
Re: [php] refresh problem,philbert,Philbert, 020827 15:02
I am not versed in PHP, but the same problem appears in ASP.
If you try to redirect a page after you have already sent data back to the browser (probably something like 'echo' in php) the web server is not able to do that.

Most of the ASP pages I have that include a form, submit to a special submit page, which does not send data back to the browser. After processing the data submitted in the form, the submit page then redirects to the original asp page with the form on it.

e.g.: form_page.asp -> submits to form_page_submit.asp -> redirects back to form_page.asp

The form values are lost in the redirect, so if you refresh the page, it will not complain about resubmitting the form values.
Re: [php] refresh problem,jjmb,Jack, 020827 18:53
Thanks, that works. I had thinked of that way, but thought it would be possible with one file. I can live with two files to keep retransmission of the data in separate files.

Re: [php] refresh problem haikal, 020913 12:57
Re: [php] refresh problem,manish_agrawal012,manish Agrawal, 020919 11:29
Add a line like this in the <head> section of your page:

<META HTTP-EQUIV=Refresh CONTENT="X; URL=<?php print $PHP_SELF ?>">

Where X is number of seconds before the page refreshes.
Re: [php] refresh problem me, 020927 14:42
try changing the form element method="post" to method="get" this will make the contents of the submitted form go into the url, but will not cause the refresh prompt box to appear!
Re: [php] refresh problem glpunk, 020927 18:42
I have the same problem.... when refresh the page reinsert the data.... I use form action $PHP_SELF (I need that...). exist anyway to not reinsert data with this method???? maybe "kill" or "destroy" the $HTTP_POST_VARS?? Tkx
Re: [php] refresh problem artypants, 021002 08:44
Isn't there some way to call a refresh of the refering page from the submit function page?
Re: [php] refresh problem Lea, 021127 13:25
Hi ,

I have also the problem when I click on refresh button and I got the message "the page cannot be refreshed without resending the information..."

I read here Jack's recomendition about spesial submit page. So u wont to implement this way but I dont know how do it,

I work with html and JSP pages.

Please if you can xplain me how do it ?
I hope to your help,

Thanks and Regards,

Re: [php] refresh problem dafdfadfadfa, 021220 20:38
Re: [php] refresh problem MacNasty, 030107 09:34
try var_dump() see
Re: [php] refresh problem Slowhand, 030108 09:45
My gustbook is 2 part.
index.php with form that action with fetch.php
fetch.php is can handle header("Location: index.php") to call back the GB. This prevent the multimessages reloading problems.
I hope you help this...
Re: [php] refresh problem,vikramb,Vikram B, 030116 14:01
This message states that it will re-send information, whether or not you filled anything out. This is because many websites have something called "hidden fields," which the user cannot see. These fields hold dynamic values that are used throughout the site. In order to reload/refresh the page, the information must be re-sent to the server, regardless of whether or not you have entered anything. Please click "retry," and the reload/refresh process will complete, and bring you to the requested page.
Re: [php] refresh problem test, 030121 00:50
this board serdar, 030121 00:54
im looking for like this php board (sign and view on the same page). how can i find the sources ?
this board 3dfiction, 030121 00:55
im looking for like this php board (sign and view on the same page). how can i find the sources ? please mail to me.
Re: [php] refresh problem,davide.barbaresi,Davide, 030226 15:41
Hi, i have the same problem...when i submit my dates in a form, the program produces this warning message: Warning: Cannot add header information - headers already sent by (output started at /var/www/html/dbvendor/config.php:48) in /var/www/html/dbvendor/insert_comic.php on line 23.....i see your solutions but i can't resolve my problem...Can you have another solutions for me?.....
Re: [php] refresh problem It's normal, 030514 22:27
It's juste the way the protocol http header hang the informations you submit, using post will do this warning because while you refresh, they resend the information again. The best solution is to use 2 pages as you did and that all. No more problem guys.
Re: [php] refresh problem Savut, 030514 22:29
all the header() must be used before you output any html code. You can't use the header() function after beginning to write something. You have to solve it.
Re: [php] refresh problem,stefandima,Stefan, 030618 13:18
I see the problem solve (i guess) in phpmyadmin from phpdev (the version it's not important, in all). But i dont find out how. From what i read above nobody realy solve the problem.
The: header("refresh: X, ....") it's not good because it's make refresh after X secs.
The: var_dump ..... no coment
It's easy, all i want to know it's how i realise in php if it's the first run or it's a refresh.
Re: [php] refresh problem,dan,Dan, 030625 06:45
I've read this whole post and here is my solution to having a page refresh without resending the information:

At the end of my script I set $HTTP_POST_VARS and $_POST arrays to empty arrays.

$HTTP_POST_VARS = array();
$_POST = array();

Depending on what version of PHP you use you really only need to set one of the two POST variables but I set both just in case.

This has worked for me but please let me know by email if there is any problem with what i'm doing.

Re: [php] refresh problem 1, 030728 09:33
Re: [php] refresh problem hmm, 030729 23:27
Re: [php] refresh problem sadfsdf, 030806 13:59
Re: [php] refresh problem tomx, 030810 22:35
headers already sent..
that's isn't real problem..
you simply cannot use echo or print in script included at first..
AND after the "?>" tag in included script there cannot be any newline or
space symbol..
that's all folks.. (it works :))
Re: [php] refresh problem tomx, 030810 23:09
:%s/that's isn't/that's not/g

excuse my horrible english :)
Re: [php] refresh problem dAniel, 030813 09:34
@Dan: unsetting $_POST does not work (at least with IE).

But it's simple:
use $_SESSION to store the $_POST data!
for action of the form put a very small .php file like this:

-- data_submit.php --

this reloads the page (header command), but without POSTed data. But we have stored it in $_SESSION and can access and unset it. Great, huh? :)

you simply have to use sessions for this, which offer a lot of flexibility besides this. use
  for that (see manual, if you're not familiar to it).

nice scripting!
Re: [php] refresh problem dAniel, 030813 09:37
you'll better put a space into the location header:
header('location: data.php');

IIRC I read about browsers who need exactly one space there.
Re: [php] refresh problem brent, 030816 01:36
Use Dan's solution. I've been working at this for a while, came across his solution, and no more duplicate entries after refresh.

(put at end of code)
$HTTP_POST_VARS = array();
$_POST = array();
Re: [php] refresh problem dora, 030816 01:51
I'm making a shopping cart with php and sessions, and the problem with refreshing the page appears when the user is at the stage when the basket needs to updated (product added or removed / quantity changed etc.).
Say, the user adds a product to the basket (using two separate .php pages) and after the basket contents are updated and shown, the user hits the refresh button. Although there is no form involved in the process (just anchor links carrying the data) the refresh causes the insert/update to happen once more.
Now, obviously I've added a "check-to-see-if-it's-already-inserted" function, but still the user gets a message similar to "this product is already inserted", when they really haven't requested such a thing.
The "meta refresh" just makes the page refresh in a loop.

Has anybody got any other ideas?

Re: [php] refresh problem,rag_chirag,chirag modi, 030822 06:33
how to make progress status in php?
Re: [php] refresh problem dumbo, 030829 15:01
well i don't know if you want it in ur php page or not but go to internet options, advanced, then scroll down 2 bottom. click the very last thing *warn if forms submittal is being redirected*
Re: [php] refresh problem sdf, 030915 12:08
Re: [php] refresh problem,kimdemanila,kaye, 030923 10:27
I have this problem about refreshing a jsp but I still need the value of the variable that has been passed from another page. You see everytime I refresh the jsp the value is lost, can I refresh the jsp without losing the value passed from other pages? tnks in advance.
Re: [php] refresh problem alex, 030929 03:45
hm...may be problem with browser???
Re: [php] refresh problem asf, 031007 16:29
Re: [php] refresh problem matus from Slovakia, 031016 05:45
the same problem

so whats the trick to solve it???

the array function didn't work

I don't wanna separate my code though

its been only few weeks I'm working with php... please help

go to "", they have it done... I don't know how!
Re: [php] refresh problem matus from Slovakia, 031016 05:47
ups, its
Re: [php] refresh problem,rajneeshgarg,Rajneesh Garg, 031017 08:36
Regarding the refresh notification, I simply followed the following steps:
On page1, I submitted the form so as to capture the page's information. Use get method while submitting the form.
I didnt receive any message following this. If get method is not used, and default method (post method) is used, refresh notification may appear.
Re: [php] refresh problem iascoot, 031105 07:36
hey, i use:
header('Status: 302 Moved Temporarily');
header("Location: index.php"); /* Redirect browser */
in the submit code, refreshes perfectly
Re: [php] refresh problem,himakumar,hima kumar, 031117 14:01
i included one file into another file and included file have sends headers,another file also have but i can't remove them and it is giving "headers already sent"
what can i do?
Re: [php] refresh problem Adeesha Wickremasin…, 031122 20:13
Hey people,
cut and paste the following code in the very top of your 'header' page. This only applies to PHP pages and I have only tried it on MSIE. Also this method won't be applied to php shopping cart pages because credit card #'s will be stored in cache.
But I used this method to search something on the database from my main page. The search results displays on a different page. And there I have 'next','previous' links to go back and forth through the results.
Also you should use 'action=post' in the main page and 'action=get' in the display page.
Try it out! it worked for me!
(make sure you have a common page called header.php or something and paste the following code there. Then call header.php from any page).
header("Cache-Control: yes-store, yes-cache");
header("Pragma: yes-cache");
header("Cache-control: private"); //to not lose filled out information
//<META HTTP-EQUIV="Expires" CONTENT="-1">
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //a past date(can use -1)
serg ergserg, 040108 20:33
sergserg$HTTP_POST_VARS = array();
$_POST = array();
Re: [php] refresh problem Jimmy, 040108 23:25
Use javascript location().
Re: [php] refresh problem thawat, 040112 08:59
Re: [php] refresh problem,gibimpaul,Gibi Paul, 040126 14:59
I did the following change at my php.ini file
session.cache_limiter =nocache
session.cache_expire = -10
This has worked but please let me know by email if there is any problem with this.

Gibi Paul
Back Button Hacking,NathanKayy,Nathan, 040206 08:22
I have a JSP page with some <input...> fields and a submit button. I had written a simple servlet and using that in this JSP page, to insert the captured data in database. JSP pages uses POST.

After entering data and pressing submit. The data gets captured and JSP page refreshes with all fields blank.. waiting for new data.

The problem is... Now, if i do a page Refresh..
I get the typical MS message "The page cannot be refreshed without resending the information...blah blah ok cancel".
And pressing OK...reenters the old data taking it from the request object, though the screen is blank before a refresh.

Any comments is highly appreciated.

Re: [php] refresh problem nub, 040209 04:26
Just testing this websites submit form :P
[empty] dans sweet page, 040305 13:55
dans sweet page
Re: [php] refresh problem Gareth Morris, 040309 13:01
There is some terrible advice in this thread.
I had this problem and solved it like this:

1) change the action="" attribute of your <form> tag from action="myform.php" to action="myform.php?add=1". You can still use method="POST" and POST all your other variables.

2) at the top of your php script, you can do a check for:

// ** START SCRIPT ** //

if ($_GET["add"]=="1") {
// .. place your update/insert logic here ..
// redirect to the same page, but without the add=1 variable
header("Location: myform.php")
// stop processing of script after redirect

// normal display of page should go here - this is where the redirect above will redirect to.

// ** END SCRIPT ** //

The way this works is that the form submits to a page with URL of yourpage.php?add=1 - and then it redirects to yourpage.php. The users browser thinks these two are actually different pages, but they are not, and it is very simple to check what stage we are at (submit or normal display) using the logic given above.

Hope that helps.
Re: [php] refresh problem Ray, 040320 01:25

Finally a voice of clarity! Your solution worked perfectly! Thanks a bunch. Actually my open source uses the same method but my mind went blank...

Re: [php] refresh problem,jamie_venk,Venkat, 040417 16:53
Hi ,

i have got this problem also.. although i dont work on php... i have a page which contains 4 frames which are made by a servlet .. for some operation another small popup is generated where data is filled and sent back to the old frame... but on clicking on save IE gives me this warning of not been to send the data and asks to refresh the page... i cannot change it to GET request as it is a part of a huge framework and it may affect other pages.. where do i add the META CONTENT refresh tag if it will solve the problem. in the popup form or in the main frame.. please help me out as it is requires a very quick solution.... thanx.. any other way is also welcome....
Re: [php] refresh problem,nykornman,joe, 040520 05:55
Re: [php] refresh problem ygh, 040523 19:27
dcx tgyfv
Re: [php] refresh problem Muhameed, 040529 17:44
Everyone go to , i am sure it will solve your problemos. Gracias mucho.

Re: [php] refresh problem Leif, 040611 22:45
Hey, the guy who has written this page must know how to do it... Where is he in all this?
Re: [php] refresh problem Mathieu \'P01\' HEN…, 041118 11:14
:\ those ukrainian spammers
Re: [php] refresh problem service, 041129 11:59

Your guestbook is very nice. Thenk you
Re: [php] refresh problem Milo, 041129 12:20
Oh, so that's why you spammed it 10 times?
Re: [php] refresh problem Mathieu \'P01\' HEN…, 041129 14:54
^__^ is it so hard to think some people loves you enough to post 10 messages in a row ?

Watching the IP, I see that's still that moron from Ukrain.
Re: [php] refresh problem Calm_Pear, 041130 16:36
blah... again no real question... :-/
Re: [php] refresh problem Calm_Pear, 041207 13:58
hey Milo, can't you just block this morons ip address in a htaccess file?
Re: [php] refresh problem inharry, 041210 20:40
Gareth: you are the man! :)

Your solution worked perfectly!
I used header("location: ".$PHP_SELF) instead of header("location: myform.php")

Re: [php] refresh problem,sakkiidit,markov, 041223 19:11
I've tried that, but I'm still having trouble; I' really new at this so that's why: it'd help if I had an actual PHP book instead of online tutorials! Well, this is the last thing I need to do anyhow.

I've probably got the code messed up somehow.

In the first page, I have:

In the second (php) page:
//connect to server and choose flight database
$conn = mysql_connect($servername, $username, $password) or die("Could not connect: " . mysql_error());
$db=mysql_select_db("res_flight", $conn);

if ($_GET["add"]=="1") {//this works! It gets the value from previous page!

//code that collects the user's input $_POST['userinput'] from the previous page and goes through choices, etc.
.it prints out "echo's" necessary stuff
header("Location: res_testflight.php");

Re: [php] refresh problem test, 050322 18:15
I used before any html is outputted but after youve done stuff with you data
if (is_int($insert_book)) {
header ("Location: ".$HTTP_REFERER."?suc=1");
and then in the html body before your form or errors appears just then use
<? if ($_GET['suc'] == 1) { ?>
<table width="80%" border="1" cellspacing="0" cellpadding="0">
<td colspan="3" class="head">Book inserted into datebase</td>
<? } else { ?>
....html <form> etc
Pages: 1