Hello,
I created a php script in which I call php fumcion which looks like
this
function confirm($vl) {
?>
<head>
<script type='text/javascript'>
<!--
document.cookie = "qrv=''";
alert(document. cookie);
var answer = confirm("ARE YOU SURE?")
if (answer){
alert('ok');
document.cookie = "qrv=yes";
alert(document. cookie);
}
else{
alert('no');
document.cookie = "qrv=no";
alert(document. cookie);
}
//-->
</script>
</head>
<?
}
Later after I call the above function I want to check what is the
session value
echo $_COOKIE["qrv"];
it is null, but the actual cookie in the browser is set to yes or no.
When I try again the echo command give me the right output.
Problem is that I always have to refresh the webpage in order to get
the cookie value.
It looks like php reads the cookie that was set before you load the
browser page.
Any ideas how to fix that?
Thank You
Bartosz Wegrzyn 4 7952
Bart wrote: <script type='text/javascript'> <!-- document.cookie = "qrv=''"; alert(document. cookie); //--> </script>
Later after I call the above function I want to check what is the session value
echo $_COOKIE["qrv"];
it is null, but the actual cookie in the browser is set to yes or no. When I try again the echo command give me the right output.
Problem is that I always have to refresh the webpage in order to get the cookie value. It looks like php reads the cookie that was set before you load the browser page.
It's the old story:
Javascript runs on the users computer, PHP on the server. PHP sends output
"as is" to the client, with the variables available.
Because the cookie is set AFTER the user has gotten the page, at the time
the page was set this cookie variable wasn't available. No way to "fix"
that, that's just how it works. If you need this functionality, it needs a
different approach. Either create the dynamic content using javascript (for
instance XMLHTTPRequest) , or let the user go to a different page.
Grtz,
--
Rik Wasmus
Bart wrote: (..) Problem is that I always have to refresh the webpage in order to get the cookie value. (..) Any ideas how to fix that?
Sounds like you need AJAX!
Thanks I will try other options.
is there a easy way to refresh a page. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vince C. |
last post by:
Hi all.
I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've
tried
Response.Cookies("Test").Expires = Date();
Response.Cookies("Test").Expires = Date().toLocaleString();
Response.Cookies("Test").Expires = Date().toString();
Response.Cookies("Test").Expires = Date().toUTCString();
|
by: Bert |
last post by:
I have been reading the post and the FAQ and have been unable to find
anything that will help with my problem.
First let me say that I am not a web developer, designer and no next to
nothing about javascript. I am just rebuilding my site and need help. We run
a bamboo nursery and the site has listings of over 100 varieties we sell.
The site uses regular pages and framesets for the discriptions of the
bamboo. The framesets have a top...
|
by: Arpan |
last post by:
In my ASP application, a Session variable takes the following form
<%
Dim strRec,strCol
strRec=Request.QueryString("records")
strCol=Request.QueryString("columns")
Session("RecCol")=strCol & "='" & strRec & "'"
%>
|
by: SHarris |
last post by:
Hello,
In our new intranet ASP.NET project, two requirements are that the browser
accept cookies AND JavaScript. We are requiring the use of Internet
Explorer 6+.
1. Using C# in an ASP.NET application, how can we code the project to check
to make sure the browser accepts cookies?
2. Where would we put this code? In Global.asax?
3. Using C# in an ASP.NET application, how can we code the project to
detect and make sure the browser...
|
by: HopfZ |
last post by:
Server sends cookie to browser and the browser send the same cookie
back to the server according to Wikipedia.
Do browsers send even javascript-generated cookie to servers?
For example, if I browse to a page on a server and if the content of
the page is the following:
<html>
<head><script>
alert(document.cookie);
| |
by: WayneH |
last post by:
Hi -
I'm trying to use javascript to determine if a user's browser has cookies enabled or not.
To test: copy this code into a file with a 'html' extension, and load it into your IE browser directly, through a local web server and through a remote web server.
By turning cookies on/off in your browser, running the file, then clicking the 'test1' or 'test2' buttons, the displayed text should accurately inform you if your cookies are On or...
|
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...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |