trq Posted December 15, 2009 Share Posted December 15, 2009 Post your current code. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 All the code between the tags are the FULL code, so every line, none spared MAC.PHP <!--[if !IE]> Firefox and others will use outer object --> <embed type="application/x-java-applet" name="macaddressapplet" width="0" height="0" code="MacAddressApplet" archive="macaddressapplet.jar" pluginspage="http://java.sun.com/javase/downloads/index.jsp" style="position:absolute; top:-1000px; left:-1000px;"> <noembed> <!--<![endif]--> <!----> <object classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA" type="application/x-java-applet" name="macaddressapplet" style="position:absolute; top:-1000px; left:-1000px;" > <param name="code" value="MacAddressApplet"> <param name="archive" value="macaddressapplet.jar" > <param name="mayscript" value="true"> <param name="scriptable" value="true"> <param name="width" value="0"> <param name="height" value="0"> </object> <!--[if !IE]> Firefox and others will use outer object --> </noembed> </embed> <!--<![endif]--> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> var macs = { getMacAddressesJSON : function() { document.macaddressapplet.setSep( ":" ); document.macaddressapplet.setFormat( "%02x" ); var macs = eval( String( document.macaddressapplet.getMacAddressesJSON() ) ); var mac_string = ""; for(var idx = 0; idx < macs.length; idx ++ ) { mac_string += "\t" + macs[ idx ] + "\n "; } return mac_string } } $(document).ready(function() { $.ajax({ type: "POST", url: "process.php", dataType: "json", data: { mac: macs.getMacAddressesJSON(); }; success: function(d) { console.log(d) } }); }); </script> PROCESS.PHP <?php $mac = $_POST['mac']; $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $mac); fclose($fh); ?> I manually created testFile.txt so ist does exist ERRORS ARE: missing } after property list http://10.0.0.1/apps/mac/mac2.php Line 50 which is mac: macs.getMacAddressesJSON(); and a range for jquery.js (I presume that is normal as it is a straight download from their site and they are only warnings not errors) thorpe thanks for all your help your #1 Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 So that is my current code (thanks to you thorpe) Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2009 Share Posted December 15, 2009 Your declaring macs twice for starters. This will break things. All this embbeding code? Where is it within your document? You might want to simply try sending a simple string via ajax so we can at least eliminate that as a problem. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 Here is my simpler test code: mac9.php <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> var macs = { getMacAddressesJSON : function() { var mac_string = "aaaaaaaaaaaaaaa"; return mac_string } } $(document).ready(function() { $.ajax({ type: "POST", url: "process.php", dataType: "json", data: { 'mac': macs.getMacAddressesJSON() } }); }); </script> process.php <?php $mac = $_POST['mac']; $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $mac); fclose($fh); ?> Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 The code in the above post after somemodification now works :-) Now to get the other to work Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 IT WORKS :-) mac.php <!--[if !IE]> Firefox and others will use outer object --> <embed type="application/x-java-applet" name="macaddressapplet" width="0" height="0" code="MacAddressApplet" archive="macaddressapplet.jar" pluginspage="http://java.sun.com/javase/downloads/index.jsp" style="position:absolute; top:-1000px; left:-1000px;"> <noembed> <!--<![endif]--> <!----> <object classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA" type="application/x-java-applet" name="macaddressapplet" style="position:absolute; top:-1000px; left:-1000px;" > <param name="code" value="MacAddressApplet"> <param name="archive" value="macaddressapplet.jar" > <param name="mayscript" value="true"> <param name="scriptable" value="true"> <param name="width" value="0"> <param name="height" value="0"> </object> <!--[if !IE]> Firefox and others will use outer object --> </noembed> </embed> <!--<![endif]--> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> var macs = { getMacAddressesJSON : function() { document.macaddressapplet.setSep( ":" ); document.macaddressapplet.setFormat( "%02x" ); var macs = eval( String( document.macaddressapplet.getMacAddressesJSON() ) ); var mac_string = ""; for(var idx = 0; idx < macs.length; idx ++ ) { mac_string += "\t" + macs[ idx ] + "\n "; } return mac_string } } $(document).ready(function() { $.ajax({ type: "POST", url: "process.php", dataType: "json", data: { mac: macs.getMacAddressesJSON() } }); }); </script> Process.php <?php $mac = $_POST['mac']; $myFile = "testtextfile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $mac); fclose($fh); ?> Thanks a billion thorpe, I dont know what I did but I (thanks to you) got it working, had to remove some of your lines of code i.e. success: function(d) { console.log(d) } which seemed to make it work with some other stuff So thanks a million, this is now sorted, finally :-) Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2009 Share Posted December 15, 2009 console.log() is simply there to aid in the debugging. Glad its working. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 as I said, thanks so much for all of your help thorpe, I really appreciate it Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 Okay now I dont know why I am getting this error document.macaddressapplet.setSep is not a function http://10.0.0.1/apps/mac/index.php Line 33 which is document.macaddressapplet.setSep( ":" ); Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 SOLVED again Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 okay now another problem with it, If i visit mysite.com it will not display the MAC but if I first visit mysite.com/apps/mac/index.php then go back to mysite.com the mac works any thoughts on this. from mysite.com/index.php I call it like this <?php $require_once = 'apps/mac/index.php'; require_once($require_once); ?> in the body of the page <body> Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2009 Share Posted December 15, 2009 You need to post your current code. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 root/apps/mac/index.php <!--[if !IE]> Firefox and others will use outer object --> <embed type="application/x-java-applet" name="macaddressapplet" width="0" height="0" code="MacAddressApplet" archive="macaddressapplet.jar" pluginspage="http://java.sun.com/javase/downloads/index.jsp" style="position:absolute; top:-1000px; left:-1000px;"> <noembed> <!--<![endif]--> <!----> <object classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA" type="application/x-java-applet" name="macaddressapplet" style="position:absolute; top:-1000px; left:-1000px;" > <param name="code" value="MacAddressApplet"> <param name="archive" value="macaddressapplet.jar" > <param name="mayscript" value="true"> <param name="scriptable" value="true"> <param name="width" value="0"> <param name="height" value="0"> </object> <!--[if !IE]> Firefox and others will use outer object --> </noembed> </embed> <!--<![endif]--> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> var macs = { getMacAddressesJSON : function() { document.macaddressapplet.setSep( ":" ); document.macaddressapplet.setFormat( "%02x" ); var macs = eval( String( document.macaddressapplet.getMacAddressesJSON() ) ); var mac_string = ""; for(var idx = 0; idx < macs.length; idx ++ ) { mac_string += "\t" + macs[ idx ] + "\n "; } return mac_string } } $(document).ready(function() { $.ajax({ type: "POST", url: "process.php", dataType: "json", data: { mac: macs.getMacAddressesJSON() } }); }); </script> root/apps/mac/process.php <?php session_start(); $mac = $_POST['mac']; $input = $mac; $i = explode('00:00:00:00:00:00:00:e0',$input); $str = '';foreach ($i as $value) { $str .= trim($value); } $array = explode(' ',$str); $_SESSION['clientmac'] = $array[0]; ?> root/index.php <?php ob_start(); session_start(); $require_once = '_inc/php/functions.php'; require_once($require_once); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Rhodry Korb</title> <link rel="stylesheet" type="text/css" href="/css/screen.css" /> <script type="text/javascript" src="/js/jquery.js"></script> </head> <body> <?php $require_once = 'apps/mac/index.php'; require_once($require_once); ?> <?php echo $_SESSION['clientmac'];?> </body> </html> Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2009 Share Posted December 15, 2009 You need to think about the process. You have a page that echos an unset $_SESSION variable when it is executed. Once this script is executed it gets sent to the client. Once on the client you have some javascript which executes and makes another request back to the server and sets the $_SESSION variable you attempted to echo within the last request. Thats it, the whole process. The only way the page which is still sitting on the client can get to echo this $_SESSION variable is if you refresh it and make another request or to let Javascript update the current page. If all you want to do is display a user mac address why are you sending it back to the server just to try and retrieve it again when it already exists on the client? Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 It is going to a logging database and a range of other stuff happens to it Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 If I refresh my page the MAC still does not come up?!?!?!? Quote Link to comment Share on other sites More sharing options...
trq Posted December 15, 2009 Share Posted December 15, 2009 Try debugging your code then. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 15, 2009 Author Share Posted December 15, 2009 found a/the errror document.macaddressapplet.setSep is not a function http://10.0.0.1/ Line 43 which is document.macaddressapplet.setSep( ":" ); why would I get this? This is the code required from the mac/index.php which works well by itself Actually the error only disappears after two refreshes (at least on apps/mac/index.php) so why would I get it? Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 16, 2009 Author Share Posted December 16, 2009 I find it interesting how this error is fixed after refresh but not fixed after refresh of the main index.php Quote Link to comment Share on other sites More sharing options...
trq Posted December 16, 2009 Share Posted December 16, 2009 No doubt your logic is screwed up somewhere. Its likely that your embed tags need to actually go within your actual document somewhere. hence attaching it to the document object. I'm not real sure as I haven't and wouldn't use embed tags. They are not part of xhtml, and are only officially supported in the brand new html5. Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 16, 2009 Author Share Posted December 16, 2009 How do you suggest I get the .jar in then or the .java??? Quote Link to comment Share on other sites More sharing options...
canadabeeau Posted December 18, 2009 Author Share Posted December 18, 2009 This is starting to really bug me, I have no idea why this only works when I got the the real location not the page which is requiring it, and if I got to the actual page I need to do a refesh about 2 time for it to work. Any ideas? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.