i use php code in javascript. However, there is an error.
I don't know what went wrong with my code. Can you take a look?
function wp_auth_javascript() {
if (is_page('login')) {
?>
<script type="text/javascript">
function auth_adult(){
IMP.certification({ // param
merchant_uid:'merchant_' + new Date().getTime(),
min_age: 19
}, function (rsp) { // callback
if (rsp.success) {
alert('success');
<?php $_SESSION['adult'] = 'y'; wp_redirect(home_url()); exit; ?>
}else{
alert('fail');
}
});
}
</script>
<?php
}
}
add_action('wp_head', 'wp_auth_javascript');
When I use this code, When I go to the login page, It is automatically redirected to home url. I thought I would be redirected when I succeed in the callback, but it doesn't work that way at all. What is the problem?