Jump to content

How to get value from variable??


waynem

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.