It is impossible for you to set PHP variable based off of JavaScript variables, because as far as the JavaScript is concerned, there is no PHP. It's just HTML being echoed or included.
You can do it the other way around (how you have it in cookies) because the PHP will run first and be able to set the variables before the JavaScript runs.
In your example, when you set $dsfd
to $dsfd = "<script>document.write...<script>"
, unless you do something more with $dsfd later, there is no effect.
If you are ok with the idea of using more than one page, then you can probably do something with cookies, but then you have to go from page to page to accomplish what you want, and that might be not an options because of something else.
My last thought on this is that you might be able to use something like hidden <iframe>
elements using PHP to echo variables when the <iframe>
loads or reloads, but I've never done something like that so I can't say.
Hope something in here is helpful.