i am just setting up the general template for my website and the little bit of php that i am doing is to just get the users id from page to page, in other words i want the user while logged in to go from page to page, without using the sub id in the header of user_id=3 for example, and then using the get function to get it and display their information, i want to be able to do it without that.
Here is my code but i keep getting the error
Notice: Undefined index: user_id in C:\xampp\htdocs\Arken\profile.php on line 7
LOGIN CODE (not all of it of course, just the bit for setting the sessions tuff)
// Create session var for their raw id
$user_id = $row["user_id"];
$_SESSION['user_id'] = $user_id;
// Create the idx session var
$_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id");
// Create session var for their username
$login_username = $row["login_username"];
$_SESSION['login_username'] = $login_username;
// Create session var for their password
$login_userpass = $row["login_password"];
$_SESSION['login_userpass'] = $login_userpass;
PHP for each page
session_start();
$user_id = "";
if ($_GET['user_id']) {
$user_id = $_GET['user_id'];
} else if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
} else {
include_once "index.php";
exit();
}
include 'connect_to_mysql.php';
Thanks for your help
I am assuming line 7 is
if ($_GET['user_id']) {
Try making sure it's set before using it:
if (isset($_GET['user_id'])) {
This error is caused by the warning level E_NOTICE
and this line:
if ($_GET['user_id'])
If the value for user_id
is not set, this creates an error. If you only want to check whether or not the value is present, you should therefore use:
if (isset($_GET['user_id']))