Jump to content

Recommended Posts

<?php
session_start();
if(empty($_SESSION['user_id'])){
header('location: index.php');
        }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Main Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600"
        rel="stylesheet">
<link href="css/font-awesome.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/pages/dashboard.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body>
<?php
        $userid=$_SESSION['user_id'];
        echo $userid;
?>

I have the above code. I am curious why I can not print out the userid on the page. I am using this as a roadmap as I want to include the username, first and last name in the session variables so I can use it throughout the current session to write out something like

 

"Welcome First_Name Last_Name"

 

Thanks for the help!

 

Mike

Link to comment
https://forums.phpfreaks.com/topic/303106-session-variables/
Share on other sites

technically, there's nothing that would prevent your code from working. however, i can name at least a half-dozen things that could make it 'appear' like it isn't working.

 

do you have php's error_reporting set to E_ALL and display_errors set to ON, so that php would help you by reporting and displaying all the errors it detects. i'm betting you would be getting php errors that would help pin down the problem.

 

next, what is the user_id value supposed to be? one of the possibilities for why it may not be 'appearing' is if it happened to intentionally or accidentally be in the form of a html tag, in which case it would appear in the 'view source' of the page and not be displayed.

 

lastly, you need an exit; statement after the header() redirect to stop program execution. the current code allows a non-logged in user to access the page since all the code still runs.

Link to comment
https://forums.phpfreaks.com/topic/303106-session-variables/#findComment-1542318
Share on other sites

technically, there's nothing that would prevent your code from working. however, i can name at least a half-dozen things that could make it 'appear' like it isn't working.

 

do you have php's error_reporting set to E_ALL and display_errors set to ON, so that php would help you by reporting and displaying all the errors it detects. i'm betting you would be getting php errors that would help pin down the problem.

 

next, what is the user_id value supposed to be? one of the possibilities for why it may not be 'appearing' is if it happened to intentionally or accidentally be in the form of a html tag, in which case it would appear in the 'view source' of the page and not be displayed.

 

lastly, you need an exit; statement after the header() redirect to stop program execution. the current code allows a non-logged in user to access the page since all the code still runs.

 

The user_id is a integer. 

 

ERROR REPORTING set to all

 

DISPLAY ERRORS is enabled

 

I am seeing it now. Not sure why it did not show up before. 

 

Thanks for the reminder about error reporting and display errors. That will help me out alot in the future in development.

Link to comment
https://forums.phpfreaks.com/topic/303106-session-variables/#findComment-1542326
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.