473,854 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to include JavaScript into PHP to get 2 Variables ??? Need urgent help with that

3 New Member
Short Description of the Project:

we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we want to give them the opportunity to run these modules from home as well, we are trying to get the USERNAME/COMPUTERNAME as well, so the students, when they sign up for the modules, they can ONLY run the modules fromhome PC.

We found a nice JavaScript, that gives us opportunity to get these 2 values, but we are not able to retrieve these into PHP.

The JavaScript is as follow:
[code]
//~~Author~~. Curtis Riley
//~~Email_Address ~~. curril@tristate gt.org
//Gets the current user's name, domain, and PC name, then gets the global
//groups on the domain that the user is a member of, and then checks the
//local groups on the PC to see if the user is a member. All of the data is
//displayed as collected in an Internet Explorer window controled by the
//script.

//~~Script~~.
// WSH and ADSI demo program
// Gets global and local groups
// for the current user and machine
// and displays them in IE
// Requires: ADSI 2.5, WSH 2.0,
// Scripting 5.1, IE4
//Global ActiveX objects
//Creates an instance of IE
var ie = new ActiveXObject ("InternetExplo rer.Application ");

//Global variables
var gsUserName, gsUserDomain, gsComputerName;
var gaGlobalGroups = new Array();
var gaLocalGroups = new Array();
var gaMembershipFro m = new Array();

// Begin Main Program

BuildOutputWind ow();
ShowStatus("Get ting Information..." );

gsUserName = Get_UserName();
gsUserDomain = Get_UserDomain( );
gsComputerName = Get_ComputerNam e();
ShowUserData();

gaGlobalGroups = Get_UserGlobalG roups(gsUserNam e, gsUserDomain);
ShowGlobalGroup Data(gaGlobalGr oups);

gaLocalGroups = Get_UserLocalGr oups(gsUserName , gsUserDomain, gsComputerName, gaGlobalGroups) ;
ShowLocalGroupD ata(gaLocalGrou ps);

ShowStatus("Gro up information retrieved.");

// End Main Program

// ADSI and WSH Functions

// Gets the PC Name from the WSH
function Get_ComputerNam e(){
ShowStatus("Get ting Computer Name...");
var WshNetwork = new ActiveXObject ("WScript.Netwo rk");
return (WshNetwork.Com puterName);
}
// End function GetComputerName (){

// Gets the User Name from the WSH
function Get_UserName(){
ShowStatus("Get ting User Name...");
var WshNetwork = new ActiveXObject ("WScript.Netwo rk");
return (WshNetwork.Use rName);
}
// End function GetUserName(){

// Gets the Domain Name from the WSH
function Get_UserDomain( ){
ShowStatus("Get ting Domain Name...");
var WshNetwork = new ActiveXObject ("WScript.Netwo rk");
return (WshNetwork.Use rDomain);
}
// End function Get_UserDomain( ){

// Gets the global groups the user is a member of from ADSI
function Get_UserGlobalG roups(sUserName , sUserDomain){
ShowStatus("Get ting User Global Group Membership...") ;
var oDomain; //Will hold the NT domain object
var eDomain; //an Enumerator that points to oDomain
var oGroup; //Will hold a group object
var i; //Counter variable

var VB_array; //a Dictionary object used to create a VBArray
var VBGroupFilter; //will hold the value "Group" in a VBArray

var aGroups = new Array(); //Holds the groups the user is a member of

// Create a VBarray to hold the filter value (yes, it is a kludge)
VB_array = new ActiveXObject(" Scripting.Dicti onary");
VB_array.add("G roup", "");
VBGroupFilter = VB_array.Keys() ;

// Get the IADsContainer object for the domain
oDomain = GetObject("WinN T://" + sUserDomain);

//Filter the IADsContainer so that only objects that
//are groups show up when looking at it
oDomain.Filter = VBGroupFilter;

//Create an enumerator object so that we can step through all the groups
//in the domain
eDomain = new Enumerator(oDom ain)

i = 0; //Initialize counter to step through array
for (;!eDomain.atEn d();eDomain.mov eNext()){
//Since oDomain is filtered by group, each eDomain item is a group
oGroup = eDomain.item();
ShowStatus("Che cking membership in group " + oGroup.Name + "....");
//Use the IsMember() method to find out if user is in the group

if ( oGroup.IsMember ("WinNT://" + sUserDomain + "/" + sUserName) ){
//Store the group in the array, increment array counter
aGroups[i++] = oGroup;
//Show the groups as they come up
ShowGlobalGroup Data(aGroups);
}
}
ShowStatus("Don e getting global group membership");
return (aGroups);
}
// function Get_UserGlobalG roups(){

// Gets the local groups the user is a member of

function Get_UserLocalGr oups(sUserName, sUserDomain, sComputerName, aGlobalGroups){
ShowStatus("Get ting User Local Group Membership (may take a while)...");
var oDomain; //Will hold the NT local domain object
var eDomain; //an Enumerator that points to oDomain
var oGroup; //Will hold a group object
var i; //Counter variable

var VB_array; //a Dictionary object used to create a VBArray
var VBGroupFilter; //will hold the value "Group" in a VBArray

var aGroups = new Array(); //Holds the groups the user is a member of

// Create a VBarray to hold the filter value (yes, it is a kludge)
VB_array = new ActiveXObject(" Scripting.Dicti onary");
VB_array.add("G roup", "");
VBGroupFilter = VB_array.Keys() ;

// Get the IADsContainer object for the computer
oDomain = GetObject("WinN T://" + sComputerName);

//Filter the IADsContainer so that only objects that
//are groups show up when looking at it
oDomain.Filter = VBGroupFilter;

//Create an enumerator object so that we can step through all the groups
//in the local domain
eDomain = new Enumerator(oDom ain)

//Use a for loop to step through the enumerator and look at all the groups
i = 0; //Initialize counter to step through array
for (;!eDomain.atEn d();eDomain.mov eNext()){
//Since oDomain is filtered by group, each eDomain item is a group
oGroup = eDomain.item();
ShowStatus("Che cking membership in group " + oGroup.Name + "....");
//Use the IsMember() method to find out if user is in the group
if ( oGroup.IsMember ("WinNT://" + sUserDomain + "/" + sUserName) ){
//Add a new property to indicate where the membership comes from
gaMembershipFro m[i] = sUserName;
//Store the group in the array, increment array counter
aGroups[i++] = oGroup;
//Show the groups as they come up
ShowLocalGroupD ata(aGroups);
}
//Now loop through all global groups that the user is a member of
//and check to see if those global groups belong to the local group
//Necessary since the .IsMember method doesn't check to see if a
//a user is in the global groups that are members of the local group
for (j =0; j < aGlobalGroups.l ength; j++){
ShowStatus("Che cking membership in group " + oGroup.Name + "....");
if ( oGroup.IsMember ("WinNT://" + sUserDomain + "/" + aGlobalGroups[j].Name) ){
//Now check against the last local group added to list to see if
//the user is already a member to prevent adding duplicate names
//since (i) was incremented, need to use (i-1) to get current group
if (aGroups[i-1].Name != oGroup.Name){
gaMembershipFro m[i] = aGlobalGroups[j].Name;
aGroups[i++] = oGroup;
} else {
//Add current global group name to the MembershipFrom list
gaMembershipFro m[i-1] += "<br>" + aGlobalGroups[j].Name;
}
ShowLocalGroupD ata(aGroups);
}
}
}
ShowStatus("Don e getting local group membership");
return (aGroups);
} // End function Get_UserLocalGr oups(){

// IE and display Functions

// Creates the IE window
// Require the object ie.
function BuildOutputWind ow(){
var n = 0; //dummy variable while waiting for IE to start
var s = ""; //String that holds the HTML to build window

//Set window properties
ie.height = 480;
ie.width = 640;
ie.menubar = false;
ie.toolbar = false;
ie.statusbar = false;
ie.addressbar = false;
ie.resizable = true;
ie.navigate ("about:blank") ;

//Loop while IE is opening
while (ie.busy) {++n};

ie.document.bod y.innerHTML = "Building Document..." + "<br>load time= " + n;
ie.visible = true;

//Start building document. Each element is given an ID for DHTML use
//Single quotes are used to prevent having to escape double quotes
//Newlines are thrown in to make it easier to read if sent to a file

//The banner element
s += '<h3 id="Banner_id" onclick="tests( )">Group Membership</h3>\n';

//The status element, not to be confused with the status bar
s += '<p id="Status_id"> Building Document...</p>\n';

//The user data element (holds PC name, user name, domain)
s += '<p id="UserData_id ">No user data</p>\n';

//The global groups element
s += '<p id="GlobalGroup s_id">No global groups<p>\n';

//The local groups element
s += '<p id="LocalGroups _id">No local groups<p>\n';

//Show the HTML
ie.document.bod y.innerHTML = s;

}
//End function BuildOutputWind ow(){

//Shows HTML text in IE window in element labeled "Status_id"
function ShowStatus(sCur rStatus){
ie.document.all .item("Status_i d").innerHTM L = sCurrStatus;
}
//End function ShowStatus("sCu rrStatus")

Read this forum's guidelines and put you code between code, php or html tags,Read Posting Guidelines before you put code in forum!!! - Ronald
Nov 25 '06 #1
3 5621
sunbeam
3 New Member
//Shows HTML text in IE window in element labeled "UserData_i d"
function ShowUserData(){
var s = ""

//Puts it in a table
s += '<b>User Info</b> ';
s += '<table>\n';
s += '<tr><td width="33%" align=center><u >User Name</u></td>';
s += '<td width="33%" align=center><u >Domain Name</u></td>';
s += '<td align=center><u >Computer Name</u></td></tr>\n';
s += '<tr><td align=center>' + gsUserName + '</td>';
s += '<td align=center>' + gsUserDomain + '</td>';
s += '<td align=center>' + gsComputerName + '</td></tr>';
s += '</table>'
ie.document.all .item("UserData _id").innerHTM L = s;
}
//End function ShowUserData()

//Shows HTML text in IE window in element labeled "GlobalGroupDat a_id"
function ShowGlobalGroup Data(aGroups){
var s = ""; i = 0;

//Puts it in a table
s += '<b>Global Group Membership</b> ';
s += '<table cellspacing=10> \n'
s += '<tr><td width="25%"><u> Group Name</u></td>';
s += '<td><u>Descrip tion</u></td></tr>\n'
//Create each table row
for (i=0; i<aGroups.lengt h; i++){
s += '<tr><td>' + aGroups[i].Name + '</td>';
s += '<td>' + aGroups[i].Description + '</td></tr>\n'
}
s += '</table>'
ie.document.all .item("GlobalGr oups_id").inner HTML = s;
}
//End function ShowGlobalGroup Data(){

//Shows HTML text in IE window in element labeled "LocalGroupData _id"
function ShowLocalGroupD ata(aGroups){
var s = ""; i = 0;

//Puts it in a table
s += '<b>Local Group Membership</b><br>';
s += '<table cellspacing=10> \n'
s += '<tr><td width="25%" valign=top><u>G roup Name</u></td>';
s += '<td width="25%" valign=top><u>G ets Membership From</u></td>\n'
s += '<td valign=top><u>D escription</u></td></tr>\n'
//Create each table row
for (i=0; i<aGroups.lengt h; i++){
s += '<tr><td valign=top>' + aGroups[i].Name + '</td>';
s += '<td valign=top>' + gaMembershipFro m[i] + '</td>\n'
s += '<td valign=top>' + aGroups[i].Description + '</td></tr>\n'
}
s += '</table>'
ie.document.all .item("LocalGro ups_id").innerH TML = s;
}
//End function ShowLocalGroupD ata(){
[/code]

If you run (save it as script.js or something else) the script, u get the desired information, the question ist how sould we place this script into a php page, to get these 2 values, when the student registers ??

If you refuse to following this forum's guidelines and put you code between code, php or html tags, I have to edit your posts. Read the Posting Guidelines before you put any ncode into this forum!!! - Ronald :cool:any help would be appreciated

Ioannis E. Ntentopoulos
Nov 25 '06 #2
Atli
5,058 Recognized Expert Expert
I didn't get through all that javascript.. sry.

But... If I understand your problem correctly (wich is higly unlikely ;P ) you need a way to get your data from the java to the php?

Assuming this and that your users would have to log in using a html form, I think I have an idea.

You could have your javascript put the data into hidden form thingies and pass it along with the login info.. like so

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function setValue()
  3. {
  4.     // These vars you'd have to set
  5.     // using your javascript
  6.     var userName = "userName";
  7.     var compName = "compName";
  8.  
  9.     document.form1.hiddenUser.value = userName;
  10.     document.form1.hiddenComp.value = compName;
  11.  
  12.     document.form1.submit();
  13. }
  14. </script>
  15.  
  16. <form action="login.php" name="form1" method="post">
  17.     <input type="text" name="Username" />
  18.     <input type="text" name="Password" />
  19.     <input type="hidden" name="hiddenUser" />
  20.     <input type="hidden" name="hiddenComp" />
  21.  
  22.     <input type="button" value="What?" onClick="javascript:setValue()" />
  23. </form>
then all you'd have to do is maka a php to read the info and do whatever you want with it.

Hope this helps.
Nov 25 '06 #3
sunbeam
3 New Member
@ Roland: sorry about that, thought i had the
Expand|Select|Wrap|Line Numbers
  1. ...
tag in my post

@ Atli: the whole code i posted gets (only in Internet Explorer) the (real) COMPUTERNAME and the (real) LOGGED-IN USER (localy)

so this js gives you 2 values, and my question was, how can I take these 2 values from the js script and put them into my php file where i do the check, if a user has enough privileges, to c the modules (privileges = COMPUTERNAME, LOGGED-IN USER and then username, password of the e-Learning System)
Nov 26 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2607
by: S.Shaigany | last post by:
Hi everybody, Please help me. I have a problem with my login page, which worked fine during the last one month. I have'nt made any changes in it. but from yesterday on, it seems that my PHP code receives wrong POST variables. This is my HTML code piece which just produces login form: <form name="login" action="default.php" method="post"> UserName:<input type="text" name="username" size="15" maxlength="20"
2
12978
by: Andy Fish | last post by:
Hi, I am in the process of designing a UI which has to be fairly sophisticated. There will be a number of list boxes and other controls, with pop-up windows to edit certain properties. It's the kind of thing I would normally have done in VB but I want it to be browser-based. I've only used javascript for trivial things before so this would be my first serious javascript development. I would like it to run on all reasonably recent...
1
2524
by: Jenny | last post by:
Need urgent help for an unsolved problem. In our ASP web application, we creat a Back button and if user click on this button, it execute history.go(-1) to go back to the previous page. All our users use IE 6.0 and most of them don't have problem with this button. But one user reported everytime he click on this button, there is a pop-up window shows up and ask him refresh and reload the page, after he clicks OK, the previous page will be...
3
3361
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can cut/paste it into 2 files and run it to see what I mean. ###############menu.html############### <html> <body> <script type="text/javascript">
13
2478
by: vgame64 | last post by:
Hi, I have been struggling with writing a program for a few hours. The requirements are that: """You will be writing a program which will determine whether a date is valid in terms of days in that month. We are assuming that the year will be valid 4 digit integer. So you don't have to think much about that(in terms of validation) except for the month of February. If the month is February, then you have to check whether that year is Leap...
1
1579
by: david | last post by:
My question is how to keep the values of JavaScript variable unchanged when the page is posted back to the server? Problem: The JavaScript is used in HTML for computing in aspx web page (form) design. When the page is posted back to the server, the values of JavaScript variables are initialized again. So the computing result would be wrong after poatback. Thank you for any help and suggestion.
2
13153
by: ksr | last post by:
Hello, I have a HTML page, which loads an activeX control in the browser. In the <HEADsection, I have javascript similar to the following, <SCRIPT language="JavaScript"> var Index = ""; // do some processing which sets a value to variable Index </SCRIPT>
1
1590
by: Keithb | last post by:
I have some client-side javascript for that I use for dhtml stuff such as hiding div tags based on user menu selections, etc. I need a way to maintain the state of javascript variables across postback. Are there any server side controls that can be used as a container for client-side javascript variables? If not, how do other developers approach this issue? Thanks, Keiht
8
5504
by: Harch84 | last post by:
Hi I have a html page with javascript in it that assigns a set of coordinates to javascript variables. The question I have is how can I then send these variables to a Perl CGI script using a submit on a html form. An example of some of the code below: var map; var geocoder = null; var addressMarker;
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10751
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7914
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4153
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.