Question
PHP includes and session management
Hello,
I have been following the Dreamweaver 8 Dynamic Development from Lynda.com. He builds an Admin system in ColdFusion. I'm using PHP.
2 issues I have been struggling with.
First Question) The pages will ask for the password, and take me to the requested page. After that, the session appears to be destroyed. It goes back to the login screen after each page. I know that the trainer had to Enable sessions for ColdFusion to allow the session to work. What do I have to do in Dreamweaver to allow the session to keep moving forward. I have included some code from my main index.php page to see what I am missing.
Code:
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "1";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "/admin/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
Second Question) I am getting header errors, and I know where from. I want to know what I may be doing wrong in Dreamweaver that is causing this to happen. The problem is this code at the beginning:
Code:
<?php virtual('/Connections/Hostgator_Highwade.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
When I put the contents of the Hostgator_Highwade.php file there instead of the virtual, the issue goes away. However, Dreamweaver changes that back anytime I make an edit of anything in Server Behaviors. I have also tried the ob_start() band-aid. It did not work for me.
I want to be able to fix this issue, so Dreamweaver puts the code in right. Any suggestions?
Thanks!
Brian Hightower
I have been following the Dreamweaver 8 Dynamic Development from Lynda.com. He builds an Admin system in ColdFusion. I'm using PHP.
2 issues I have been struggling with.
First Question) The pages will ask for the password, and take me to the requested page. After that, the session appears to be destroyed. It goes back to the login screen after each page. I know that the trainer had to Enable sessions for ColdFusion to allow the session to work. What do I have to do in Dreamweaver to allow the session to keep moving forward. I have included some code from my main index.php page to see what I am missing.
Code:
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "1";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "/admin/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
Second Question) I am getting header errors, and I know where from. I want to know what I may be doing wrong in Dreamweaver that is causing this to happen. The problem is this code at the beginning:
Code:
<?php virtual('/Connections/Hostgator_Highwade.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
When I put the contents of the Hostgator_Highwade.php file there instead of the virtual, the issue goes away. However, Dreamweaver changes that back anytime I make an edit of anything in Server Behaviors. I have also tried the ob_start() band-aid. It did not work for me.
I want to be able to fix this issue, so Dreamweaver puts the code in right. Any suggestions?
Thanks!
Brian Hightower
