Jump to content

Variable


canadabeeau

Recommended Posts

Hi I have some javascript that I want the output of, placed in a PHP variable, ie <?php $VAR = ?>js_variable<?php ;?>;

 

Here is my JS

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 ";
document.write(mac_string);

 

Instead of document.write I want the JS variable to be the value of the PHP variable $VAR.

 

Thankyou in advance, any help is welcomed as always :-)

Link to comment
Share on other sites

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 ";

document.write(mac_string);

location.href="some_page.php?macaddy=" + mac_string;

 

Now the somepage you use could even be the same page you have the js on if you block it out like a form using the same page for the action. Thats the only way I know that does not involve using a form. But eother way you need to send the data back to the server.

Link to comment
Share on other sites

PHP to a Js variable is very commonly used. But yeah the only real way to send a JS var to PHP is to either use a form or reload the browser with the var tacked onto the URL..

 

What do you want to do with the JS var in PHP.. Is Ajax an option for your program?

Link to comment
Share on other sites

Okay my Java applet (& JavaScript) obtains a MAC address string

00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0

I need to get that JavaScript variable into a PHP variable so I can run this

<?php
$input = '00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0';
$i = explode('00:00:00:00:00:00:00:e0',$input);
$str = '';foreach ($i as $value) {	
$str .= trim($value);
}
$array = explode(' ',$str); 
echo sizeof($array);
?>

Link to comment
Share on other sites

Okay I'll explain better.

 

1. Person visits mysite.com

2. Javascript gets MAC address as JS variable mac_string

3. Make PHP variable $macstringP equal JS variable mac_string

4. Run PHP code described in http://www.phpfreaks.com/forums/index.php/topic,280485.0.html with input being the PHP variable $macstringP

 

The part I want to do is step 3, I need to make a PHP variable equal the JS variable, so if I echo the PHP variable it will echo the same as the JS variable. Does this make more sense?? Thanks for all the help again

 

Can I use AJAX? or another way?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.