I'm fairly new using PHP classes, I have done some PHP using the procedural method for a while but never fully done proper object oriented programming on php. Which brings me to my question:
I have one file called classes.php where I intend to define all my php classes. Inside that file I have created a class as follows:
require_once("connection.php");
class User
{
public function getUserInfo() {
$userinfo = mysqli_query($con,"SELECT * FROM users WHERE username='". $_SESSION['username'] ."'");
while($row = mysqli_fetch_assoc($userinfo)) {
// USER DETAILS:
$userid = $row['id'];
$username = $row['username'];
$userfirstname = $row['first_name'];
$userlastname = $row['last_name'];
$useremail = $row['email'];
$useraddress1 = $row['address_line_1'];
$useraddress2 = $row['address_line_2'];
$userpostcode = $row['postcode'];
$userphone = $row['phone'];
$usermobile = $row['mobile'];
$usercreated = $row['created'];
$usermodified = $row['modified'];
$useraccess = $row['access_level'];
}
}
} // end of User
Now I want to use the values of the variables defined in that class in another page. But how can I access those values?
So far I'm trying this (unsuccessfully):
<?php
include "php_includes/classes.php";
$user = new User();
?>
<div class="somediv">
<?php echo $user->getUserInfo($username) ?>
</div>
I have also tried:
<?php
include "php_includes/classes.php";
$user = new User();
?>
<div class="somediv">
<?php echo $user->$username ?>
</div>
Is there any way to echo those variables in another page so I can use the user information in, for example, profile pages?
Thanks in advance.