I am trying to "commmunicate" between webpages located on different servers. Server1 has "full" capacity with PHP, mysql Server2 is a webserver without PHP, mysql. I have a framed page with Frame1: menu/navigation on server 1 Frame2: The material to be shown, on server 2. When I link different pages to each other on server 2 I WISH TO MAKE KNOWN TO THE PAGE/FRAME ON SERVER 1 THAT THE MATERIAL HAS CHANGED. I tried to write a cookie from server1 by putting an inline frame in a server2 file. However, it only seems to work "sometimes". EDIT: It seems to work in FF but not in IE8, even though I marked "allow third party cookies" (which I cannot ask users to do, anyway.) EDIT2: I must say that the behavior of the cookie is very erratic. I am not sure how it changes. Server2 html-file: <div style="visibility: hidden;"> <iframe src="http://server1.com/set_cookie.php?value=abcd" width="1" height="1" --> < iframe></div> Code (markup): I do not with to slow down navigation with "meta refresh" intermediate pages. What should I do? Edit: I also tried manipulating one window from the other by parent.frame2.location.href = file.htm I also found problems with this method.
As far as I know you cannot change cookies of different domains. On site 1 you'll only be able to edit cookies for site 1, in short
get rid of the iframe, it can be dodgy. you can try <img src="http://server1.com/set_cookie.php?value=abcd" width="1" height="1" /> instead - cookies are being served with any files really. and yes, you can't really read cross-domain cookies although if you run some js from the other server, it may work.... hrm
Thanks for quick replies! Maybe I have been careless, I just realized that I have had problems in my addresses. Sometimes writing www.server1.com and sometimes server1.com. This has created two sets of cookies. When I have started to clean up my messy addressing it seems as if it may work all the way out. I apologize for a somewhat messy post. Thanks for good replies. @dimitar: I hadn't thought of putting the php in an image-tag. That is an interesting possibility. As soon as my testing environment improves I will try it too.
using img tags can also be an alternative to using ajax to send data to the server as well, if a response is not required. Im not sure if this is recommended but I can't see a problem with it...
hey, thank you for the post - I just had a similar problem myself, the cookie thing did it for me too.
I am not really proficient in this subject. (Esp. not AJAX) I can't really understand how it would work?
well say, you have to send data to the server via GET to set some session variables, for example, userid=45&language=en&theme=dark you can do so by using ajax and call a file like... // ... create xhr object and then: xhr.open('GET', 'sess.php?userid=45&language=en&theme=dark', true); xhr.send(null); Code (javascript): or simply do: <img src="sess.php?userid=45&language=en&theme=dark&randomizer=<?=rand(0,100000)?>" width="1" height="1" /> PHP: notice i use a call to a random number to prevent caching issues not going through to the server. that's all there is to it, really. you can mimic the same in js by using new Image(); and set the src property to same.
Sorry for late reply, I am on a trip, but I still appreciate the help I get a lot, of course. Thanks dimitar. I had tried something similar to your last example. I don't know where it went wrong. I will check and come back. Thanks.
I normally use a random number to be sure, but you can make sure the page isn't cached within the server-side code as well. For Asp and asp.net : Response.Expires = -1 should do it.. but I am unsure of the php equivalent.
Thanks dimitar, many good suggestions. I now find that I had a big blunder in my php-code. The simple reason it couldn't be put in an img-tag was that it had text output. Seeing your example I also got inspired to write (copy) my first ajax-pages. Really a very, very cool thing. I have used the random method. I just tried it out on my own. I never understood where the caching took place? It never helped to empty the cache of the browser! I was on a trip in Asia and was running pages on a US server. I think it was different for different browsers too. I just took a wild guess that, for example, Microsoft put cache-servers to make US pages load more quickly in Asia???
caching is clientside. basically, if you call the same url, i.e.: <img src="sess.php?userid=45&language=en&theme=dark" width="1" height="1" /> it may not fetch the whole thing and assume no change / obey your webserver general caching policy. at which point your script won't get the call up... not ideal
Well, some caching is client side, and some caching is indeed in the middle. There are proxy machines who do a lot of caching, as well as large portals such as schools and large corporations. So there can be caching between you and the server.
The caching problem was really irritating until I started using random numbers in the url. The problem did not occur just for some "small/special" part of the webpage. One page within my personal homepage displays a random proverb from a mySQL database. The same proverb came up no matter what I did! (Including emptying browser cache or reload-button) I was surfing from a computer in a hotel in Vietnam. In Sweden it was OK. Server is in the US. (I can't give browser type and version details, sorry) EDIT: I found the original thread: The problem occurred only for IE(8) and not FF. I'm drifting more and more OT, sorry.