473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

setcookie and reloading pages

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
4 8152

"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Phil Powell | last post by:
Fourth attempt.. it fails now in login, I check by printing $_COOKIE and there is no value there! Guys, what on earth do I do about this???? Here is the code that sets the cookie: if...
5
by: Ben | last post by:
Hi all, In my .php file, I'm using both session_start() and setcookie() before <html> tag. It gives me following warning message: Warning: Cannot modify header information - headers already...
5
by: Admin | last post by:
Ok, fairly new to php but I am learning. This may be an easy question but here it goes anyway. I have a website that is built on php/mysql. My members can send and get email and instant...
6
by: GregoryD | last post by:
I'm going to try to simplify this issue as much as possible. In my public_html/ directory, I have a login script that sets a cookie to be used for authentication purposes. To set the cookie, it...
3
by: Cmaza | last post by:
Hi, I've been dealing with PHP for a few years now and I've never encountered a problem quite like this. I've searched the net for an answer to my problem hoping somebody else may have...
9
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000."...
8
by: SupraFast | last post by:
I have two hosting accounts. On one, my setcookie script works fine; cookies are created. On the other, the same script doesn't work. The function returns TRUE, but no cookies is created. I...
9
by: wangers16 | last post by:
Hi, I am quite new to PHP and recently I have been attempting to create a login script, just one problem, the setcookie function isn't working. I have tried a basic php file with nothing other...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.