0
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.

5
  • 2
    Look up how to use Ajax :) Commented Feb 17, 2017 at 8:20
  • what error do you get when you login via your login system? Commented Feb 17, 2017 at 8:20
  • This is fundamentally wrong: you cannot use php on the client side, so inside javascript! Commented Feb 17, 2017 at 8:22
  • I was gonna say that. Do your session checks via php not javascript Commented Feb 17, 2017 at 8:24
  • PhpDev yeah if login with my own system it have error , i wanted to check on php , but it delay alot time. is thing wont show. Commented Feb 17, 2017 at 8:26

2 Answers 2

1

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;?>
Sign up to request clarification or add additional context in comments.

Comments

0
<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.