I have login.php
and mainpage.php
files and I want to access login.php
's user's data from mainpage.php
.
Should I use require
or include
? How to connect those files?
require login.php;
include login.php;
I have login.php
and mainpage.php
files and I want to access login.php
's user's data from mainpage.php
.
Should I use require
or include
? How to connect those files?
require login.php;
include login.php;
Best would be to write object-oriented codes, i.e. mainpage.php
would
require('login.php');
just to get definition of let's say class LoginForm
and then in mainpage.php
you would do:
$loginForm = new LoginForm();
Alternatively you could place your logic into functions and let mainpage.php
call something like handleLogin()
defined in login.php
. In both of mentioned cases mainpage.php
just needs to know the definition of function/class, therefore you should use require
or require_once
.
You can put all your data into $GLOBALS.
You can check great examples here How to declare a global variable in php?