note 23843 added to function.setcookie
| From: | tonyhana at lvcm dot com | Date: | Tue, 30 Jul 2002 05:59:16 +0000 |
| Subject: | note 23843 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33963@lists.php.net to get a copy of this message | ||
you can do some tricky things combining php/javascript and multiple servers, such as read and write
cookies across domains, get around cookie size limitations, and execute remote javascript and php
for a local html only server, but be careful of the multithreaded nature of web servers and
clients..
IE consider this code on a local html only server, which invokes remote code on a php server....
<script src='http://remote_server/your_cookie_reader_routine.php'></script>
in which your remote php code reads and writes cookies, and/or echos out javascript which is then
executed back on the local host. Something like..
echo "var cookie1='$cookie1';";
/* Which will read a cookie on the remote machine, then echo it out as javascript, which will then
be executed on the local machine, and be made available as a javascript variable.
and more remote code...*/
echo <<<END
var localHTML="<img src='http://remote_server/a_cookie_writer_script.php";
localHTML+="?data=WhateverYouWantToSendToRemoteServer";
localHTML=localHTML+"&ALocalCookie="+ALocalCookie;
localHTML+="'>";
document.write(localHTML);
END;
The above is Javascript code echoed out on a remote server, to be executed on a local html only
server, which creates an img using document write, which sends some data and a local cookie back to
the remote server. At that point you can either write the data to a remote cookie or feed it into a
database. To actually display the image see imagecreate().
But be aware that when you write cookies on the remote server using <img> tags, the execution
is most probably going to be multi threaded-(unless you do something about it-like put the server
into s-l-o-w single threaded mode). Which means it will start executing the rest of the html code on
the local page, while you are still processing this <img tag> remotely. That means if you use
code like this to track multiple banners, counters, recip links, or whatever on the local page, they
will surely all try to load up at the same time, and overwrite each others cookies or data, so if
you're getting strange results this might be why.
This doesnt seem to happen when you use a <script src=>, the local page will wait for the
remote script to complete execution, or time out, before continuing. But then you cant remotely
modify the script tag to send back dynamic info about the local server.
Stuff like this opens up the possibility to get around the data and qty limitations of cookies, by
spreading the data across multiple domains. Which might be handy if you dont want to hog up all your
harddisk space, and are willing to send the data off into the wild.
A nice thing about this type of trick is that you can give other webmasters a very simple piece of
code to insert into their pages.. IE
<script src='http://...yourscript.php'></script>
And at this point you now have the ability to record all kinds of data and insert all kind of code
into their pages, and modify it at will, using innerHTML writes or the document.write() methods.
All perfect for php driven popup exchanges, banner exchanges, link trades, counters, link lists, top
lists, dynamic pic posts, dynamic galleries, affiliate tracking, etc,etc, in which you can give the
webmaster a simple web based interface to choose which services he would like to include in his
page. And which he will have no need to change the code on his site at all, except for the original
addition of that one line of script. Its also a great way to hide (or at least remove the ability to
change) the javascript from your affiliates/webmasters.
--
http://www.php.net/manual/en/function.setcookie.php
http://master.php.net/manage/user-notes.php?action=edit+23843
http://master.php.net/manage/user-notes.php?action=delete+23843
http://master.php.net/manage/user-notes.php?action=reject+23843