var secret_photo
var secret_name
if (!<?php echo isset($_SESSION['fb_item'])?'true':'false'; ?>) {
if($.cookie("domain[user]")){
secret_photo = 'noavatar.png';
secret_name = 'admin';
}
} else {
secret_photo = <?php echo json_encode($_SESSION['fb_item']['url']); ?>;
secret_name = <?php echo json_encode($_SESSION['fb_item']['name']); ?>;
}
I need to set php
session to html
using JavaScript
.There is 2 logins , one is the facebook
and the other is my own login system, facebook
uses session and my own login sets cookie.
When I login by facebook
, things are good , but if I login using my own login system , that echo check is going to cause problem , so how am I going to fix it ? Check if the session is available or not even if it doesn't exist it wont cause any problem.
You are probably encounter an error at the bottom of your code. You can't access $_SESSION['fb_item']
if it doesn't exist, it either shows a Notice
or generate wrong js code secret_photo = ;
. Just move condition to php
side:
var secret_photo
var secret_name
<?php if(!isset($_SESSION['fb_item'])):?>
if($.cookie("domain[user]")){
secret_photo = 'noavatar.png';
secret_name = 'admin';
}
<?php else:?>
secret_photo = <?php echo json_encode($_SESSION['fb_item']['url']); ?>;
secret_name = <?php echo json_encode($_SESSION['fb_item']['name']); ?>;
<?php endif;?>
<script type="text/javascript">
var secret_photo
var secret_name
<?php if(!isset($_SESSION['fb_item'])){?>
if($.cookie('user')){
secret_photo = 'noavatar.png';
secret_name = 'admin';
}
<?php }else{?>
secret_photo = <?php echo json_encode($_SESSION['fb_item']['url']); ?>;
secret_name = <?php echo json_encode($_SESSION['fb_item']['name']); ?>;
<?php }?>
</script>