[SOLVED]Not sure if it is a question for a php forum...
Moderator: General Moderators
[SOLVED]Not sure if it is a question for a php forum...
Ok here's the deal...
I use cookies in my site in javascript and not in php because I have asp pages. I can't turn them to php so that's out of the question.
When I get information from the cookies I need to pass it from a javascript variable to a php variable so I can store it in a database.
Is there any way to do it or am I waisting my time looking for one;
Thanks
Maria
I use cookies in my site in javascript and not in php because I have asp pages. I can't turn them to php so that's out of the question.
When I get information from the cookies I need to pass it from a javascript variable to a php variable so I can store it in a database.
Is there any way to do it or am I waisting my time looking for one;
Thanks
Maria
Last edited by grammic on Fri Sep 17, 2004 6:56 am, edited 1 time in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
PHP is server based. Once it has been delivered to the client for javascript usage that is it, no more server side handling. Javascript is Client side. Once the page has been delivered to the client it can do it's magic. The only way for javascript to change PHP values is to deliver information back to the server. This is normally performed as mentioned through POST ot GET values. POST/GET via a form (possible hidden values) or sometimes GET via the javascript Location command.
As far as I am aware (I simply have never heard anything to the contrary) cookies don't depend on the language they've been created with. So you should be able to read a cookie set with ASP with PHP, Javascript and vice versa.
Regarding server- and client-side: the lines are beginning to blur (See also: http://www.sitepoint.com/blog-post-view.php?id=192138 and http://www.sitepoint.com/blog-post-view.php?id=193677 )
Regarding server- and client-side: the lines are beginning to blur (See also: http://www.sitepoint.com/blog-post-view.php?id=192138 and http://www.sitepoint.com/blog-post-view.php?id=193677 )
I think I should be a little more descriptive because I've managed to confuse even myself!
I have .asp pages on my site with a lot of links. I want to keep track of the links a user follows so I use cookies, every time a link is chosen a cookie is set. I can do that only in javascript because it's the only client-side language I know and the scripts are recognized as javascript.
Now, the only thought I have was to use the onunload event to get the cookies. That means I can only use javascript to get the cookies. Then I have to find a way to pass the data to the php script that handles the insertion of it to the database. I can't use forms, I want it to be done quietly because I already have other forms, it would be to tiring for the users.
Is there any way to do it; Can I use something else besides the onunload event;
I kind of think it can't be done because I' m asking to much...
I have .asp pages on my site with a lot of links. I want to keep track of the links a user follows so I use cookies, every time a link is chosen a cookie is set. I can do that only in javascript because it's the only client-side language I know and the scripts are recognized as javascript.
Now, the only thought I have was to use the onunload event to get the cookies. That means I can only use javascript to get the cookies. Then I have to find a way to pass the data to the php script that handles the insertion of it to the database. I can't use forms, I want it to be done quietly because I already have other forms, it would be to tiring for the users.
Is there any way to do it; Can I use something else besides the onunload event;
I kind of think it can't be done because I' m asking to much...
you do not have to use "post" method, you can also use "get method" via link,
something like that
?carriage=1224584
and 1224584 implies the actual link.
at the top of your asp page, you can get this value and understand that user wants 1224584,
then increment its current stats, and redirect the user
if you can explain the scenario better, we can help better
something like that
?carriage=1224584
and 1224584 implies the actual link.
at the top of your asp page, you can get this value and understand that user wants 1224584,
then increment its current stats, and redirect the user
if you can explain the scenario better, we can help better
Ok I'll try...
Let's say I have the following page which I save as .asp
Now I have set four cookies. How can I get them on unload and then pass them to a php script;
I already use a form.
I don' t know if that makes more sense...
Let's say I have the following page which I save as .asp
Code: Select all
<html>
<head><title>test</title>
<SCRIPT src="cookie.js" type=text/javascript></SCRIPT>
<script>
var line1="course"
var line2="one"
var line3="two"
var line4="three"
</script>
</head>
<body onload=setCookie("course",line1);>
<!--#include file="something.asp"-->
<form method="post" name="do" action="do.php" target="_blank">
<input type="Hidden" name="math" >
<input type="submit" name="enter" value="submit"
onClick="document.formsї'do'].math.value='go'">
</form>
<br><br><br><br>
<a href="http://www.bla.org/index.htm" onclick=setCookie("one",line2);>one</a>
<a href="http://www.bli.org/do.html" onclick=setCookie("two",line3);>two</a>
<a href="dada.doc" onclick=setCookie("three",line3);>three</a><br>
</body>
</html>I already use a form.
I don' t know if that makes more sense...
Code: Select all
echo $_COOKIE['course'];Code: Select all
document.write.getCookie(course); in javascript i blieve..Code: Select all
<%
'get varible named as id, since it is sent by href tag, you can use GET-method
'set cookie
'get corresponding web address to this id from db
'redirect user to the address that is obtained from db
%>
<html>
<head><title>test</title>
<SCRIPT src="cookie.js" type=text/javascript></SCRIPT>
<script>
var line1="course"
var line2="one"
var line3="two"
var line4="three"
</script>
</head>
<body onload=setCookie("course",line1);>
<!--#include file="something.asp"-->
<form method="post" name="do" action="do.php" target="_blank">
<input type="Hidden" name="math" >
<input type="submit" name="enter" value="submit"
onClick="document.formsї'do'].math.value='go'">
</form>
<br><br><br><br>
<a href="?id=1">one</a>
<a href="?id=2">two</a>
<a href="?id=3">three</a>
<br>
</body>
</html>