Http://stackoverflow.com/questions/22085068/angularjs-ngroute-and-php-session-variables
I I am I might the where your problem is. You are try to access PHP sessions in your single page angularjs HTML templates am I right? Like
<div ng-repeat= "N in <?php $_session[' Somesessionarray ']?>" >
It works. Your $_session would never be available in Your templates. What can do, are use an AJAX request for your login authentication and have that request give your a session ID. Then Use this session ID when starting your sessions in further AJAX requests (as already mentioned).
Then, when you are want to store something to the PHP session, access the data via AJAX request and PHP service.
A VERY, VERY, VERY, simple example:inside getfromsession.php
Session_Start ($_get[' session_id '));
$key = $_get[' key ']
echo json_encode ($_session[$key]);
Inside storetosession.php
Session_Start ($_get[' session_id '));
$key = $_get[' key '];
$value = $_get[' value '];
$_session[$key] = $value;
Inside your login.php
$user = yourauthmechanism ($_get[' username '],$_get[' password '));
if ($user) {
session_start ();
echo json_decode (' status ' => ' success ', ' Sid ' => session_id ());
}
else {... error handling
Inside anywhere in your angular where your need to access session data:
$promise = $http. Get (' Pathtoyourphp/getfromsession.php?key=foo ');
$http. Set (' pathtoyourphp/getfromsession.php?key=bar&value=4 ');
Now use promise to acces the data for your got from your service
+++++++++++++++++++++++++
I don ' t have to do you ' re looking for angularjs.i to have a ' re looking for the something more like this.
index.php:
login.php
<?php
session_start ();
if (empty ($_post)) {
die ("you don t have permission to is here");} elseif (Empty ($_post['
username ')) or empty ($_ post[' password ']) {
die ("All fields are required.");
}
$username = "admin";
$password = "password";
if ($_post[' password '] = = $password && $_post[' username '] = = = $username) {
$_session[' loggedIn '] = = "true"; C10/>header ("Location:show.php");
} else {
die ("Invalid login");
>
show.php
<?php
if ($_session[' loggedIn '] = = "true") {
echo "You are logged in";
} else {
die ("Don" t have Permission to is here. ");
>