473,769 Members | 6,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP reading of JAvascript

Ken
I am new to PHP. But this seems like a terrific language. I have been
using JavaScript up to now but it looks like I will be changing to PHP.
Seems to have more potential.

I am confused about using data in a JavaScript cookie in a PHP file.

The JavaScript Cookie

document.cookie = "order=" + escape("website = " + website + "*" + "sale = "
+ sale + "*" + "name = " + name + "*" + "addr1 = " + addr1 + "*" + "addr2 =
" + addr2 + "*" + "city = " + city + "*" + "countycode = " + countycode +
"*" +"state = " + state + "*" + "zip = " + zip + "*" + "mr = " + mr + "*" +
"fname = " + fname + "*" + "lname = " + lname + "*" + "dept = " + dept + "*"
+ "phone = " + phone + "*" + "ext = " + ext + "*" + "email = " + email + "*"
+ "#");
variable: website =

value: website

delimiter: *

End of cookie: #

Is there a command to convert a JavaScript cookie to a PHP cookie?
I have tried to read the cookie in PHP with no success.

$_COOKIE['order'];

$_COOKIE['order='];

How do I pick out the variables and values in PHP from the JavaScript
cookie?

Thanks for your help.

Ken
Jul 17 '05 #1
3 1972
Ken wrote:
I am new to PHP. But this seems like a terrific language. I have been
using JavaScript up to now but it looks like I will be changing to PHP.
Seems to have more potential.

I am confused about using data in a JavaScript cookie in a PHP file.

The JavaScript Cookie

document.cookie = "order=" + escape("website = " + website + "*" + "sale = "
+ sale + "*" + "name = " + name + "*" + "addr1 = " + addr1 + "*" + "addr2 =
" + addr2 + "*" + "city = " + city + "*" + "countycode = " + countycode +
"*" +"state = " + state + "*" + "zip = " + zip + "*" + "mr = " + mr + "*" +
"fname = " + fname + "*" + "lname = " + lname + "*" + "dept = " + dept + "*"
+ "phone = " + phone + "*" + "ext = " + ext + "*" + "email = " + email + "*"
+ "#");
variable: website =

value: website

delimiter: *

End of cookie: #

Is there a command to convert a JavaScript cookie to a PHP cookie?
I have tried to read the cookie in PHP with no success.

$_COOKIE['order'];

$_COOKIE['order='];

How do I pick out the variables and values in PHP from the JavaScript
cookie?

Thanks for your help.

Ken


A javascript cookie to a PHP cooke? eh? a cookie is a cookie, as far as
I know.

~Cameron
Jul 17 '05 #2
Ken wrote:
I am confused about using data in a JavaScript cookie in a PHP file.


I guess you need to get a better idea what a cookie is:
A cookie is some data that the server asks [1] the client to save and
send back to the server for every later request.

[1] The server can ask the client with a HTTP header or
by having the client run a JavaScript script.
In either case the client may not accept the cookie.

If the client accepts cookies and therefore sends them to the server for
every request, the server can do different things based on that data.
Summing up: on the server, with PHP, to use a cookie sent by the client
we get the pieces of data from the $_COOKIE array. It does not matter
/how/ the cookie was created!

A "JavaScript cookie" exists, and (maybe) can be manipulated on the client.
A "PHP cookie" exists on the server, and can be used to eg. format data.
PS: my usual browsing is with JavaScript disabled, and session cookies
enabled.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
"Ken" <kk******@wi.rr .com> wrote in message news:<QH******* **********@twis ter.rdc-kc.rr.com>...
I am new to PHP. But this seems like a terrific language. I have been
using JavaScript up to now but it looks like I will be changing to PHP.
Seems to have more potential.

I am confused about using data in a JavaScript cookie in a PHP file.

The JavaScript Cookie

document.cookie = "order=" + escape("website = " + website + "*" + "sale = "
+ sale + "*" + "name = " + name + "*" + "addr1 = " + addr1 + "*" + "addr2 =
" + addr2 + "*" + "city = " + city + "*" + "countycode = " + countycode +
"*" +"state = " + state + "*" + "zip = " + zip + "*" + "mr = " + mr + "*" +
"fname = " + fname + "*" + "lname = " + lname + "*" + "dept = " + dept + "*"
+ "phone = " + phone + "*" + "ext = " + ext + "*" + "email = " + email + "*"
+ "#");
variable: website =

value: website

delimiter: *

End of cookie: #

Is there a command to convert a JavaScript cookie to a PHP cookie?
I have tried to read the cookie in PHP with no success.

$_COOKIE['order'];

$_COOKIE['order='];

How do I pick out the variables and values in PHP from the JavaScript


Try this:

<html>
<head>
<script>
document.cookie = "hello=foo; "
document.cookie = "bob=hope";
</script>
</head>

<body>
<a href="#" onclick="alert( document.cookie );">TEST</a>
<?PHP
print_r($_COOKI E);
?>
</body>
</html>

You'll have to reload the page once for PHP to be able to read the
cookie (because PHP parses the page before Javascript sets the
cookie). That should clear up any confusion you have about cookies.
But if you can avoid Javascript and just rely on PHP, you should.

If you're storing multiple fields in a single cookie and have
delimiters, do something like:

$arrValues = array();

$arrFoo = preg_split("/\*/", $_COOKIE['cookiename']);
foreach($arrFoo as $var){
list($key,$val) = preg_split("/\=/", $var);
$arrValues[$key] = $val;
}

print_r($arrVal ues);

Though that's untested, so don't blame me if I screwed something up
(I'm not sure the backslashes in the 2 preg_splits are required).
Also, check php.net for the htmlentities, urlencode and urldecode
functions.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
20545
by: Eddie | last post by:
When I use JavaScript to read an element's textDecoration style, I only get one value even if there are more than one in the sytle sheet. For example if the text-decoration is defined as: text-decoration : underline overline; when reading element.currentStyle.textDecoration I only get "underline"!! What's worse is that element.style.textDecorationUnderline returns
1
4735
by: Roger Godefroy | last post by:
Hi there... I want to read fieldvalues from out of a dynamicaly created table (php). But this has to be done by JavaScript. Every row of the table has a select-box, inputbox and a order-button. So if I press on "order" at row 8, I just want to popup "Product 8 - Price - Quantity" using alert()corresponding to the rowvalues from where the button was pressed. Any help appreciated.
3
2450
by: Catherine Lynn Smith | last post by:
I'm looking through the client side javascript reference and there's some mighty useful information in here, but it is not very specific on 'reading' information from event handlers. In the interest of streamlining my scripting, I was thinking I could write multi-purpose functions to handle mouseOver and mouseOut events. Thus far, I am manually passing if it is an Over or Out event, but it occurs to me that there might be a way to read...
3
2681
by: Christian Caron | last post by:
Hi all, I have a page which contains the following tag: <head> <meta name="date_modified" content="20030730" /> </head> (...) <script> (...)
0
376
by: Ben | last post by:
Hello, I am reading a web page using httpwebrequest and httpwebresponse that contains HTML and javascript code. When I read the page I can only read the translated HTML code. I want to read the original code that contains the Javascript (like what is returned to me when I "View Source" in Internet Explorer). Is there a way to disable Javascript processing or something similiar using .NET. Thanks!
1
3123
by: enrique | last post by:
Our server-side software is reading in Big5-encoded data as ASCII when the web pages are generated. It seems to work most of the time, since the HTML meta tag is declaring Big5 as the charset. However, every now and then certain ASCII characters, like the quote (") for example, gets read in and creates Javascript errors when the browser renders them. I think this is a direct side effect of processing our Big5-encoded files as ASCII. ...
9
5522
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex http://www.developersdex.com ***
1
20186
by: paulnightingale | last post by:
Hi I've got a ticker tape that is written in Java Script 1.2 which displays text that has to be currently changed in the program code. What I want to do is to find the bit of javascript to get the program to read a text file so that the text file can be used to update the contents of the ticker tape. Preferably I will produce a bit of code that produces a window in which you type the text you want to display and then this gets saved as a...
6
3576
by: Melih Onvural | last post by:
I need to execute some javascript and then read the value as part of a program that I am writing. I am currently doing something like this: import htmllib, urllib, formatter class myparser(htmllib.HTMLParser): insave = 0 def start_div(self, attrs): for i in attrs: if i == "id" and i == "pr":
1
1183
by: waynes | last post by:
Hello group, first time here. I have question regarding reading form post variables. I have a forms processor that dynamically reads a form, for example: For x = 1 To Request.Form.count() item = Request.Form.key(x) rstData = Request.Form.item(x) ..... adds item & rstdata to a list ..... Next
0
9587
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
10211
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
8870
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...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
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...

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.