I am a designer developing a fantasy adventure website and want to keep some typical variables such as the user's race, character class, and level. I am searching for an easy and popular php after sales which will

  1. let customers login, logout and recover passwords

  2. save javascript variables around the pages for their profile inside a database

  3. retrive values in the database and hang javascript variables on the page.

I do not think i am searching for a cms since the pages happen to be developed in HTML/css3 and that i have no need for the after sales to change the page content, just load the customers variables somewhere the page javascript can access them.

For instance, whenever a page loads, create a call towards the database and load the figures title,age and last location into the spotlight then possess the javascript take advantage of these. When the values are loaded I'm able to handle the javascript part.

I set this up in Drupal before however it feels as though overkill because I just have the above mentioned 3 functions. However I seem like i want some thing robust than simply a PHP login script because I would like some hands-holding creating the database. I'm looking into CakePHP.

What shall we be held searching for?

You are able to "pass" data from PHP to javascript by writing a javascript resist the page:

var user_object = {
"id": <?php echo user->id ?>,
"role": <?php echo user->role ?>

This object has become obtainable in the page via Javascript.


The easiest way, for me, would be to create some route like /js/storage.js, that will handle PHP. In PHP you are able to securely connect and gather all that's necessary from database, and store in JSON objects (to call qualities as user.race, user.stats.intuition) pretty simple.

I'd counsel you To not use any frameworks, if you will see fundamentals procedures, but when you believe the application will developed, then you definitely need to look, maybe to Symfony2 (easy model creation, easy route handling, things are pretty easy, and many for you personally - is everything could be disabled because of namespace loaders, so that you can only use the thing you need).

There within this handler use something similar to:

$i18n = array(
    'some' => 'что-то',
$user = array(
    'culture' => 'ru',
    'authenticated' => false, // or true, whatever you have

render_js.php could be:

<script type="text/javascript">
    var i18n = <?php echo json_encode($i18n); ?>;
    var user = <?php echo json_encode($user); ?>;

After which inside your HTML mind tag just include this JS:

      <script type="text/javascript" src="/js/storage.js"></script>

Primary feature for you personally is the fact that everything is going to be loaded right now when browser will request for /js/storage.js.

For me, it had been the very best practivce because I can not realize something simpler to change. Hope that can help.

I believe you should utilize AJAX for your.

On window load you have to call AJAX script that you have to fire a question to retrieve all of the needed records in the database and can utilize it inside your page.