开发者

javascript, php, cookies

the appl开发者_开发问答ication returns a value "1" in the database instead of the mac address...

I'm able to document.write the output of the mac address, but not able to have it store in the database.

Is the program using the previous cookie? (but Ive deleted all the cookies from the pc)

but if i change the variable mac to string data, it keep refresh my webpage. Why is that so... (var mac="test data";)

Please help!

create_users.php

<script language="JavaScript">

function getMacAddress(){
document.macaddressapplet.setSep( "-" );
return (document.macaddressapplet.getMacAddress());
}

function setCookie(c_name,value) {
document.cookie = c_name + "=" +escape(value);
}

//var mac="test data";
var mac = getMacAddress();


setCookie('cookie_name',mac);
window.location = "checkAvailability.php";

</script> 

<script type="text/javascript">
document.write(getMacAddress());
</script>

checkAvailiability.php

$dbhost = 'localhost';
$dbuser = 'root';
$dbname = 'registration';
mysql_connect($dbhost, $dbuser) or die("Could not connect database");
mysql_select_db($dbname);
$javascript_cookie_value = isset($_COOKIE["cookie_name"]) ? $_COOKIE["cookie_name"] : 1;
mysql_query("INSERT INTO test (mac) VALUES ('$javascript_cookie_value')");


Why not:

window.location = "checkAvailability.php?mac=" + mac;

and eliminate cookie problems?

I presume you've checked that the applet is behaving as you expect?

C.


Assuming that code appears in checkAvailability.php, then it keeps refreshing because you have window.location = "checkAvailability.php"; with no logic to stop it running — so every time it loads the page, it gets redirected to that URI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜