Jump to content

If else == and = condition not working when comparing to Javascript variable


php_padawan

Recommended Posts

Hi Guys,

 

Will you please help me with this?

 

As from what you could see, the value of $bbbb is dynamic during runtime.  I am trying to get a value from a javascript variable to compare it against another variable in just true and false condition.  The problem is that it seems that php is not allowing a comparison between a php variable and javascript. no matter what I try, it can't bring the right output or the true and false from $bbbb

is not working.  WHener I try to just put a simple true and false string to $bbbb, it works fine and normal.  the only problem is that whenever it has a value coming from javascript or '<script type="text/javascript">document.write(IsUserLoggedIn);</script>';

 

I already tried the following:

 

if ($bbbb == true) {

if ($bbbb == 'true') {

if ($bbbb ==  '<script type="text/javascript">document.write(IsUserLoggedIn);</script>'

 

 

I am trying to fix this for a week, hope that someone could help me. thanks :)

 

I really think that the problem lies in the part where I am trying to get the true and false value of a variable from a Javascript.  It is like I need to convert it to php string or something like that.

$save_creation ='<a href="' . create_link( MENU_MYACCOUNT,'creations') . '\"> '.$CI->lang->line('glb_SaveSauvegarder').'creations'.'</a>';
$dialog_box ='<a href="#" onclick="SignInDialog(\'\', \'\', \'' . create_link( MENU_MYACCOUNT) . '\'); return false;">'.$CI->lang->line('glb_SaveSauvegarder').' dialog_box'.'</a>';	    

                
            $bbbb = '<script type="text/javascript">document.write(IsUserLoggedIn);</script>'; 


            if ($bbbb = true) {
            
                	$return .= '</ul><span class="link">' .$save_creation. '</span></div>';
	
	         
	                return $return;
            
            } else {
            
            	$return .= '</ul><span class="link">' . $dialog_box . '</span></div>';
	
	    
	            return $return;
            
            
            }

php is a server-side language. all the php code in a file runs on the server when the page gets requested. only the resulting output (html, javascript, media) is send to the browser.

 

javascript is a client-side language. all the javascript code runs in the browser after it has been received by the browser.

 

to get a value from javascript (in the browser) to php (on the server), you must send that value as part of a http request from the browser to the server. you can either send it as $_POST or $_GET data and if you don't want the page to refresh, you would use AjAX to send the http request.

php is a server-side language. all the php code in a file runs on the server when the page gets requested. only the resulting output (html, javascript, media) is send to the browser.

 

javascript is a client-side language. all the javascript code runs in the browser after it has been received by the browser.

 

to get a value from javascript (in the browser) to php (on the server), you must send that value as part of a http request from the browser to the server. you can either send it as $_POST or $_GET data and if you don't want the page to refresh, you would use AjAX to send the http request.

 

 

but the problem sir is that I am just doing a maintenance on a system. I have no way of modifying how the javascript is being handled and currently, the variable that I needed was coded in javascript as a variable.

You can't compare a JS variable to a PHP variable during the execution of your PHP script. That is just the way it is, learn to deal with it. You can export a PHP variable into Javascript and compare with javascript, but not the reverse. If you need the value of a JS variable in your PHP script then you either have to include it somehow in the request, or do a separate request using ajax or similar.

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.