java script to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aajkaal
Forum Newbie
Posts: 3
Joined: Thu Jun 11, 2009 12:05 pm

java script to php

Post 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
Last edited by Benjamin on Thu Jun 11, 2009 7:13 pm, edited 1 time in total.
Reason: Added [code=javascript] tags.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: java script to php

Post by califdon »

At the time PHP is running in the server, there is no user because nothing has been sent to the browser.
aajkaal
Forum Newbie
Posts: 3
Joined: Thu Jun 11, 2009 12:05 pm

Re: java script to php

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: java script to php

Post 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.
(#10850)
aajkaal
Forum Newbie
Posts: 3
Joined: Thu Jun 11, 2009 12:05 pm

Re: java script to php

Post by aajkaal »

All the above code is in one php file. So ...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: java script to php

Post 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.
(#10850)
Post Reply