Page 1 of 1
java script to php
Posted: Thu Jun 11, 2009 12:07 pm
by aajkaal
Code: Select all
<script language='javascript'>
var strUsername;
var objNetwork;
objNetwork= new ActiveXObject("WScript.Network");
strUsername= objNetwork.Username;
strUsername= strUsername.toLowerCase();
document.write(strUsername);
</script>";
<?php
echo $strUsername;
I want to use strUsername (not just display) in the php code. How can I accomplish it
Re: java script to php
Posted: Thu Jun 11, 2009 12:21 pm
by califdon
At the time PHP is running in the server, there is no user because nothing has been sent to the browser.
Re: java script to php
Posted: Thu Jun 11, 2009 12:36 pm
by aajkaal
The javascript (in the php file) works fine on IE as required and expected. I want to transfer the value to the php-code portion of the php file.
Re: java script to php
Posted: Thu Jun 11, 2009 12:49 pm
by Christopher
You can create a link with that value as a parameter and have the user click the link to send a request with the value to the server (and PHP). Or use Ajax to send a request with the value.
Re: java script to php
Posted: Thu Jun 11, 2009 12:56 pm
by aajkaal
All the above code is in one php file. So ...
Re: java script to php
Posted: Thu Jun 11, 2009 1:19 pm
by Christopher
PHP files mostly generate HTML that is sent to the browser. In the code above, the <script> code will be run in the browser. So you need to send the value back to the server with a GET or POST request.