I’m sure the answer to this is stunningly simple – but I can’t find it!
I have a javascript embedded in a PHP (which will return a string value to my android app) and for some reason it will only read the PHP echo’d variable when it contains all integers!
I need it to read characters and integers since usernames consist of that.
Looking forward to tips – embarassed I couldn’t figure this one out on my own;
Notes on my code: I deactivated the Android function at the end, since the problem occurs before that gets implemented; also set up $myvar = ’20’ so you can see it works for all integers;
<?php
if (!isset($_SERVER['WEBAUTH_USER'])){
$login = 'Wrong username';
}else{
$login = $_SERVER['WEBAUTH_USER'];
//$myvar = 'Hello, world';
}
$myvar = $login;
//$myvar = '20';
//echo $myvar;
?>
<script type = "text/javascript">
jsvar = <?php echo $myvar;?>;
document.write(jsvar);
//Android.getValue(jsvar);
</script>
You’re leaving out quotes:
Of course, there’ll be problems if the string contains quotes, so a better solution is to use something like a JSON utility to sanitize the string.
It worked with numeric strings because JavaScript understood those as numeric constants.