By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

setcookie and reloading pages

P: n/a
Wondering why my setcookies didn't have any impact, I noticed the line in
the manual that said the page needs to be reloaded before they take effect
(which does make a certain kind of sense). So, how do I force a page to
reload?

Thanks,
Greg
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Greg Bryant" <br**********@yahoo.com> a écrit dans le message news:
Xn**********************************@199.45.49.11. ..
Wondering why my setcookies didn't have any impact, I noticed the line in
the manual that said the page needs to be reloaded before they take effect
(which does make a certain kind of sense). So, how do I force a page to
reload?

Thanks,
Greg


Call this

<script>
function redirect()
{
window.location.replace("samepage.php");
}
setTimeout("redirect();", 5000);
</script>

5000 is 5 seconds , you can change it

Marouen
Jul 17 '05 #2

P: n/a
Greg Bryant <br**********@yahoo.com> wrote in message news:<Xn**********************************@199.45. 49.11>...
Wondering why my setcookies didn't have any impact, I noticed the line in
the manual that said the page needs to be reloaded before they take effect
(which does make a certain kind of sense). So, how do I force a page to
reload?


if ( ! isset($_COOKIE['foo']) )
{
setcookie('foo', .....); //set cookie..
//reload the page for cookie to work properly
header("Location: ". $_SERVER['PHP_SELF']);
exit;
}

---
"We live to die; we die to live"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

P: n/a
Greg Bryant wrote:
Wondering why my setcookies didn't have any impact, I noticed the line in
the manual that said the page needs to be reloaded before they take effect
(which does make a certain kind of sense). So, how do I force a page to
reload?

Thanks,
Greg


You could use an HTML META REFRESH tag to force the browser to refresh
if a cookie is not set...

How are you setting your cookies? Using non-PHP code (ie javascript?) or
straight PHP code? If you are using PHP, why do you need to set, then
re-read the cookie with a page refresh? Why not set the cookie and have
any remainder part of your code use the same vvariable/value that you
used when setting the cookie - From that point forward, any link the
user clicks on will read the cookie automatically from the headers (if
cookies are enabled).

does that help any?

randelld
Jul 17 '05 #4

P: n/a
"Randell D." <pl*******************@news.group.com> wrote in
news:Rqjsb.372784$6C4.144848@pd7tw1no:

You could use an HTML META REFRESH tag to force the browser to refresh
if a cookie is not set...

How are you setting your cookies? Using non-PHP code (ie javascript?)
or straight PHP code? If you are using PHP, why do you need to set,
then re-read the cookie with a page refresh? Why not set the cookie
and have any remainder part of your code use the same vvariable/value
that you used when setting the cookie - From that point forward, any
link the user clicks on will read the cookie automatically from the
headers (if cookies are enabled).

does that help any?

randelld


Thanks - good suggestions all. This is my first PHP project, so I'm
learning as I go. The project is a small port/enhance from CF, and I
haven't played too much with the overall architecture, which has left me
with what I thought at first were oddities, but I'm getting used to them
(form validation pages reloading the form page if there's an error is
kind of kinky recursive, not expected on a scripting language :). Since
it's basically C with a few changes, it's not hard to learn (2 days to
port the site, 4 more to add database, signin pages, cookies, actual
field validation, mail support, etc). Pretty much finished with
"Beginning PHP" book, time to swallow the next one.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.