Jump to content

Recommended Posts

Hello,

 

I'll put me hands up if you can crack this…  :)

 

I have a php variable that is:

 

$a= "<SCRIPT language=JavaScript>document.write(areCookiesEnabled())</script>";

 

And if I:

 

Echo $a;

 

I get

 

True

 

Which is perfect. However the value of $a is:

 

not "true" its "<SCRIPT language=JavaScript>document.write(areCookiesEnabled())</script>"

 

So if I try a:

 

If ($a == 'true') {

 

It doesn't work because:

 

$a is '<SCRIPT language=JavaScript>document.write(areCookiesEnabled())</script>' not 'true'

 

How do I extract the value from $a? So that $a will be 'true'??

 

 

Hope this makes sense if someone can shed some light i will email them a beer  :D

 

Link to comment
https://forums.phpfreaks.com/topic/239226-how-to-get-value-from-variable/
Share on other sites

PHP and JavaScript don't mix like that.

 

In terms of page loading rendering etc.. PHP does its thing server side and renders everything before any initial output to the browsers. Where JavaScript loads there after when the page is done loading. So in order for you to pull off what you want to do is go the AJAX route, make a small javascript that detects the cookies like you already have define it as a var instead of writing it to the body of the document. then post it to a php file thats going to do whatever it is you wanna do based on if the result is true or false.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.