0

I am using Angular routing and want to access a php session variable in the view.

<?php
session_start();
//print_r($_SESSION['query']); the variable is available and will print here
?>

<script>
    var x = <?$_SESSION['query']?>
    console.log("x: " , x) //this returns undefined
</script>

I'm trying to pass the session variable as a parameter in function, but it is not available here either.

ng-init="mc.makeQuery(<?($_SESSION['query'])?>)"
1
  • 1
    use <?= to echo value into output Commented Oct 10, 2016 at 7:06

1 Answer 1

1

You can start session on your page like and create hidden field for session like this

<input type="hidden" name="mysession" id="mysession">

and write javascript function some thing like this

function Result(){
  var marks = 55;
  document.getElementById("mysession").innerHTML= <?php echo session_id();?>; 
  document.getElementById("hdnmarks").innerHTML= marks; 
  document.getElementById('Form').submit();
}

change the Form name with your form name.

Sign up to request clarification or add additional context in comments.

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.