The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
static html
#1
hello!

Thank you for writing this cool user management software.

I'm not entirely sure if this is free from bugs, maybe you see something wrong with it but here goes:

In users/includes/navigation.php I've added

Code:
<?php if($user->isLoggedIn()){     //anyone is logged in?>
Code:
<script>document.cookie="loggedin=1;path=/;example.com"</script>


And:

Code:
<?php }else{ // no one is logged in so display default items ?>
Code:
<script>document.cookie="loggedin=0;path=/;host=example.com"</script>



(you have to put your domain name where it says example.com)

In users/logout.php at the top:

Code:
setcookie("loggedin","0",time()+500,"/");

and a bit lower:

Code:
$user->logout();
Code:
session_destroy();



On other pages (in the body) I've added:

Code:
<script>
Code:
var sheet = document.createElement('style');
Code:
sheet.innerHTML = document.cookie.indexOf('loggedin=1')!=-1?".out{display:none}":".in{display:none}";
Code:
document.head.appendChild(sheet);
Code:
</script>
Code:
<a href="/">home</a> &nbsp; &nbsp;
Code:
<a href="users/logout.php" class="in">logout</a>
Code:
<span class="out">
Code:
<a href="users/login.php">login</a> &nbsp; &nbsp;
Code:
<a href="users/join.php">register</a> &nbsp; &nbsp;
Code:
<a href="users/forgot_password.php">forgot password</a>
Code:
</span>



The advantage of doing it like this is that beyond logging in and out it doesn't require any php.

One can have completely static html documents that, when logged out displays:

home | login | register | forgot password

While when logged in you get:

home | logout

(The admin page I keep on the bookmarks toolbar)

The point of using static html:

1) you can have a lot of traffic with the server doing very little work.
2) php can beak in countless different ways.
2.1) I hardly ever write php without any mistakes. The html continues to work.
2.2) php is frequently updated, webhosts tend to wait for you to go on vacation then break everything.
2.3) usespice might have a bug in it. (I'm not counting on it but I'd say a non zero chance)
2.4) your database might get corrupted.
2.5) someone might hack your site.
3) static html is amazingly fast

I like to keep things as simple as possible partially because I'm not very good at php, I haven't really looked into all the userspice helper functions and I don't know how to use bootstrap. I could include all that in pages that use only the isloggedin thingy but that, with much love and respect, seems rather silly.

Hope this is useful Smile
  Reply
#2
I like this. I've added it to my list and I'll give it a shot in some of my own code. Thanks!
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)