PHP includes and session management


hello,
i have been following dreamweaver 8 dynamic development lynda.com. builds admin system in coldfusion. i'm using php.
2 issues have been struggling with.

first question) pages ask password, , take me requested page. after that, session appears destroyed. goes login screen after each page. know trainer had enable sessions coldfusion allow session work. have in dreamweaver allow session keep moving forward. have included code main index.php page see missing.

code:

<?php
if (!isset($_session)) {
session_start();
}
$mm_authorizedusers = "1";
$mm_donotcheckaccess = "false";

// *** restrict access page: grant or deny access page
function isauthorized($strusers, $strgroups, $username, $usergroup) {
// security, start assuming visitor not authorized.
$isvalid = false;

// when visitor has logged site, session variable mm_username set equal username.
// therefore, know user not logged in if session variable blank.
if (!empty($username)) {
// besides being logged in, may restrict access users based on id established when login.
// parse strings arrays.
$arrusers = explode(",", $strusers);
$arrgroups = explode(",", $strgroups);
if (in_array($username, $arrusers)) {
$isvalid = true;
}
// or, may restrict access users based on 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) getting header errors, , know from. want know may doing wrong in dreamweaver causing happen. problem code @ beginning:
code:

<?php virtual('/connections/hostgator_highwade.php'); ?>
<?php
if (!isset($_session)) {
session_start();
}


when put contents of hostgator_highwade.php file there instead of virtual, issue goes away. however, dreamweaver changes anytime make edit of in server behaviors. have tried ob_start() band-aid. did not work me.
i want able fix issue, dreamweaver puts code in right. suggestions?
thanks!
brian hightower

brianjhightower wrote:
> hello,
> have been following dreamweaver 8 dynamic development lynda.com.
> builds admin system in coldfusion. i'm using php.

i'm not familiar lynda.com course, trying learn how
build php site course written coldfusion trying
read italian knowledge of french - doable, not advisable.

> 2 issues have been struggling with.
>
> first question) pages ask password, , take me
> requested page. after that, session appears destroyed.

> second question) getting header errors, , know from.

both questions related. if header errors, won't able
to access session variables on page.

> problem code @ beginning:
> code:
>
> <?php virtual('/connections/hostgator_highwade.php'); ?>
> <?php
> if (!isset($_session)) {
> session_start();
> }

there several possible reasons getting header errors. first of
all, should point out dreamweaver uses virtual() because have
set site definition use links relative site root.
works on apache, , fail on other servers. if you're
using apache, you're ok, if you're using other server,
should switch site definition use links relative
document. uses include(), universally supported php
servers.

what causes header problems output browser before call
to session_start(). if you're getting error messages,
the cause of problem. other causes whitespace @ top of
page (before opening php tag) , whitespace before opening
php tag or after closing 1 in connections file. there must
nothing outside tags - not new line.

--
david powers, adobe community expert
author, "foundation php dreamweaver 8" (friends of ed)
author, "php solutions" (friends of ed)
http://foundationphp.com/


More discussions in Develop server-side applications in Dreamweaver


adobe

Comments

Popular posts from this blog

Joomla site hacked, cant see front and - Joomla! Forum - community, help and support

Christian Home School Programs - Joomla! Forum - community, help and support

Trouble with PF_OutFlag_I_USE_AUDIO and PF_CHECKOUT_LAYER_AUDIO