I have been trying to manage users using jQuery+phpjQuery+PHP instead using full phpPHP because I think it is more comfortable to use jQuery+phpjQuery+PHP but using full php is easier at my personal point but organized.
Since I'm not an expert using jQuery I would like to know if the way I'm managing my users is optimal or should I return to full phpPHP?
LetsLet's take an example of how I work with jQuery+phpjQuery+PHP.
I will start with my Login.php which code I will skip because I think is irrelevant.
Login.php will start my $_SESSION
'ss.
Session_handler.php
This
This helps me to focus which type of users is logged at the moment:
session_start();
if(isset($_SESSION['Usuario']))
{
if( $_SESSION['estado'] == 'User'){
$send = array('ID' => $_SESSION['ID'], 'user' => $_SESSION['Usuario'], 'estado' => 'usuario' );
echo json_encode($send);
}
if( $_SESSION['estado'] == 'Admin'){
$send = array('ID' => $_SESSION['ID'], 'user' => $_SESSION['Usuario'], 'estado' => 'admin' );
echo json_encode($send);
}
}
else{
$send = array('estado' => 'invitado' );
echo json_encode($send);
}
Sessions.js
Now
Now I will manage my users menu depending on which type of user is logged:
$(document).ready(function(){
$.ajax({
url:'js/Session_handler.php',
success:function(data) {
var result = $.parseJSON(data);
var i = 0;
var carrito = '<li><a href="Carrito.html"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span></a></li>';
var admin = '<li><a href="Cuenta_admin.html">[Admin] '+result.user+'</a></li>';
var cuenta = '<li><a href="Cuenta_us.html">'+result.user+'</a></li>';
var navegacion = '<li><a href="Navegacion/Entrar.html">Entrar</a></li>';
var registrase = '<li><a href="Navegacion/Registrarse.html">Registrarse</a></li>';
var salir = '<li><a href="Navegacion/Php/logout.php">Salir</a></li>';
if(result.estado == 'invitado'){
$('#snipuser').append(navegacion,registrase);
}
if(result.estado == 'usuario'){
$('#snipuser').append(carrito,cuenta,salir);
}
if(result.estado == 'admin'){
$('#snipuser').append(carrito,admin,salir);
}
}
});
});
Then I just need to call my id to show the menu depending on which user is logged
:
Index.html
OK, now I will ask again in case my doubt was not clear.
Is it more effective to work this way (JQuery+php) than working with full PHP?
Is it more effective to work this way (JQuery+PHP) than working with full PHP? What does it meansmean to work with full phpPHP?. I will show an example.
Login.php that will start my $_SESSION 's$_SESSIONs.
JQuery+PHP or FULL PHP? jQuery+PHP or full PHP?