473,782 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8181

"Greg Bryant" <br**********@y ahoo.com> a écrit dans le message news:
Xn************* *************** ******@199.45.4 9.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("samep age.php");
}
setTimeout("red irect();", 5000);
</script>

5000 is 5 seconds , you can change it

Marouen
Jul 17 '05 #2
Greg Bryant <br**********@y ahoo.com> wrote in message news:<Xn******* *************** ************@19 9.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("Locatio n: ". $_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.gr oup.com> wrote in
news:Rqjsb.3727 84$6C4.144848@p d7tw1no:

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
11319
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 ($hasLoggedIn && ($row = mysql_fetch_row($query))) { setcookie('nordicnet_registration', $row, 0, '/'); @mysql_free_result($query);
5
6463
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 sent by (output started at D:\Apache Group\Apache2\htdocs\YC\songs.php:4) in D:\Apache Group\Apache2\htdocs\YC\ycphpfunc.php on line 148 My .php file looks like this:
5
1554
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 messages. The problem is for the member to get an alert that they have a "new message" the page must be reloaded. Obviously this is a bandwidth kill, plus if the user dosen't pay attention or view any other pages they will never get an alert. Does...
6
2077
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 has something like this: <?php setcookie('code',$value, time + $lifetime, '/', '.example.com'); ?>
3
2294
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 encountered this, but without any luck, so I now resolve to pose the question myself. Code: <?php $somedata="Lorem Ipsum";
9
2296
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." 4. Display last modified date of doc. Here is my attempt. What a headache :-(
8
5871
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 checked to make sure that the variables have values and that the proper expire time is set and etc. Any ideas? <?php foreach($_POST as $name => $value){ if($name == 'hItem'){ $item = $value;
9
26256
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 than a function to set and retrieve the cookie but still nothing. Why is this happening?
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.