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
US4 Include Classes
#6
The token is regenerated every time the page loads/refreshes.

I don't have a problem with loading classes manually. I do it all the time when I need to. The reason I suggested the core/init.php file is because that's where the database connection info, the cookie info, and the token info are stored. Plus it autoloads the classes to boot.... That might actually be the bulk of your problem.

The way it works (if I remember correctly is:
1. core/init.php defines the core information needed (connections, cookies, etc) and then autoloads the classes.
2. The config class parses all this stuff into a format the other classes can use.
3. The other classes do their thing.

So, about the token. It can be checked at any point during the process, it just needs to know where to look for the token. The default area is $_POST['csrf']

I do this check somewhere at the top of any time I post user input
Code:
$token = $_POST['csrf'];
Code:
if(!Token::check($token)){
Code:
die('Token doesn\'t match!');
Code:
}else {
Code:
//The rest of my code including jQ and AJAX.


I wrote some code for the join.php file that I wound up pulling out. Let me go back to github and see if I can find what I did to use the token during an AJAX call which should be similar.

One more note. You can always echo out the token at all times to see what the system thinks it is.

Instead of doing something like
Code:
<input type="hidden" name="csrf" value="<?=Token::generate();?>" >
You can (at the top of your page do
Code:
$csrf = Token::generate();
Code:
bold($csrf); //Just echoes out your token in a bold font with a white background

Then on the form you just do
Code:
<input type="hidden" name="csrf" value="<?=$csrf?>" >

Then, to see what's going on, you can do something like
Code:
$token = $_POST['csrf'];
Code:
bold($token);
//see what token was sent to the parser
Code:
if(!Token::check($token)){
Code:
die('Token doesn\'t match!');
Code:
}else {
Code:
//die('Token matches');


Something like that. Anyway, the point is that the token doesn't need to be a secret to you.
  Reply


Messages In This Thread
US4 Include Classes - by brian - 02-24-2016, 09:44 PM
US4 Include Classes - by brian - 02-24-2016, 10:10 PM
US4 Include Classes - by mudmin - 02-24-2016, 11:09 PM
US4 Include Classes - by brian - 02-25-2016, 01:23 PM
US4 Include Classes - by brian - 02-25-2016, 01:27 PM
US4 Include Classes - by mudmin - 02-25-2016, 02:13 PM
US4 Include Classes - by brian - 02-25-2016, 02:43 PM
US4 Include Classes - by mudmin - 02-25-2016, 04:02 PM
US4 Include Classes - by brian - 02-25-2016, 04:22 PM
US4 Include Classes - by mudmin - 02-25-2016, 04:56 PM
US4 Include Classes - by mudmin - 02-25-2016, 05:27 PM
US4 Include Classes - by brian - 02-25-2016, 05:58 PM
US4 Include Classes - by mudmin - 02-25-2016, 06:14 PM
US4 Include Classes - by mudmin - 02-25-2016, 11:09 PM
US4 Include Classes - by brian - 02-26-2016, 01:20 PM
US4 Include Classes - by brian - 02-26-2016, 01:41 PM
US4 Include Classes - by mudmin - 02-26-2016, 01:57 PM
US4 Include Classes - by brian - 02-26-2016, 02:05 PM
US4 Include Classes - by brian - 02-26-2016, 02:12 PM
US4 Include Classes - by mudmin - 02-26-2016, 05:54 PM
US4 Include Classes - by brian - 02-26-2016, 05:56 PM
US4 Include Classes - by mudmin - 02-26-2016, 06:42 PM
US4 Include Classes - by brian - 02-26-2016, 06:48 PM
US4 Include Classes - by Popkultur - 04-22-2017, 11:17 AM
US4 Include Classes - by mudmin - 04-23-2017, 01:53 PM
US4 Include Classes - by bladerunner - 12-14-2017, 11:57 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)