Buenas,
Adjunto ejemplo de como podriais facilmente usar sesiones para poder autenticar y dar acceso a vuestros modulos.
Escenario: App con menu y acceso a 2 modulos. Si no estas autenticado vas a la pantalla de login. Si no te autenticas, no entras. Facil
Cread dentro de HIX una carpeta, p.e. /sessions y poned todos los ejemplos tal cual estan nombrados
index.html
Code: Select all | Expand
<?prg
if ! USessionReady()
URedirect( 'login.html' )
retu nil
endif
retu ''
?>
<!DOCTYPE html>
<html>
<body>
<h3>My App</h3><hr>
<h4>Menu</h4>
<ul>
<li><a href="module_a.html">Module A</a>
<li><a href="module_b.html">Module B</a>
</ul>
<br><br>
<a href='logout.prg'>Logout</a>
</body>
</html>
login.html
Code: Select all | Expand
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="auth.prg" method="post">
<label for="user">User (demo)</label><br>
<input type="text" name="user" value="demo"><br>
<label for="psw">Password (1234)</label><br>
<input type="text" name="psw" value="1234"><br><br>
<input type="submit" value="Login">
</form>
<p>If you click the "Login" button, the form-data will be sent to a page called "auth.prg"</p>
</body>
</html>
auth.prg
Code: Select all | Expand
function Auth()
local cName := UPost( 'user' )
local cPsw := UPost( 'psw' )
local hData := {=>}
if cName == 'demo' .and. cPsw == '1234'
USessionStart()
hData[ 'user' ] := 'demo'
hData[ 'name' ] := 'Mr. Demo'
hData[ 'rol' ] := 'admin'
Usession( 'credentials', hData )
URedirect( 'index.html' )
else
URedirect( 'login.html' )
endif
return nil
logout.prg
Code: Select all | Expand
function Auth()
if USessionReady()
USessionEnd()
endif
URedirect( 'login.html' )
return nil
module_a.html
Code: Select all | Expand
<?prg
if ! USessionReady()
URedirect( 'login.html' )
retu nil
endif
retu ''
?>
<!DOCTYPE html>
<html>
<body>
<h3>Module A...</h3><hr>
Welcome <?prg return USession( 'credentials' )[ 'name' ] ?>
<br><br><a href='index.html'>Main menu</a>
module_b.html
Code: Select all | Expand
<?prg
if ! USessionReady()
URedirect( 'login.html' )
retu nil
endif
retu ''
?>
<!DOCTYPE html>
<html>
<body>
<h3>Module B...</h3><hr>
Welcome <?prg return USession( 'credentials' )[ 'name' ] ?>
<br><br><a href='index.html'>Main menu</a>
Esta es la base para poder autenticar y trabajar con sesiones
Ya solo te te toca escribir en la url -> /sessions/index.html
C.