Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP includes and session management

New Here ,
Feb 13, 2007 Feb 13, 2007
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
TOPICS
Server side applications
681
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2007 Feb 13, 2007
BrianJHightower wrote:
> Hello,
> I have been following the Dreamweaver 8 Dynamic Development from Lynda.com.
> He builds an Admin system in ColdFusion. I'm using PHP.

I'm not familiar with that Lynda.com course, but trying to learn how to
build a PHP site with a course written for ColdFusion is like trying to
read Italian with only a knowledge of French - doable, but not advisable.

> 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.

> Second Question) I am getting header errors, and I know where from.

Both questions are related. If you get header errors, you won't be able
to access session variables on the page.

> The problem is this code at the beginning:
> Code:
>
> <?php virtual('/Connections/Hostgator_Highwade.php'); ?>
> <?php
> if (!isset($_SESSION)) {
> session_start();
> }

There are several possible reasons for getting header errors. First of
all, I should point out that Dreamweaver uses virtual() because you have
set your site definition to use links relative to the site root. This
works only on Apache, and will fail on all other servers. If you're
using Apache, you're OK, but if you're using any other server, you
should switch your site definition to use links relative to the
document. This uses include(), which is universally supported by PHP
servers.

What causes header problems is any output to the browser before the call
to session_start(). If you're getting any error messages, that will be
the cause of your problem. Other causes are whitespace at the top of the
page (before the opening PHP tag) and any whitespace before the opening
PHP tag or after the closing one in your connections file. There must be
nothing outside the tags - not even a new line.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 13, 2007 Feb 13, 2007
Hey David,
Thank you for your response. I did change the site reference to 'Relative to Document'. Dreamweaver is now using require_once, and it is not giving me the header error anymore.
Any thoughts on why I'm not able to maintain a session?
If I attempt to goto my 'Users' page, it will take me to the login, and then to Users once I successfully log in. If I try to edit a User, it takes me back to a login screen. It's the same for all of my restricted pages.
The Lynda.com training was very helpful in using the Dreamweaver features. I would have been lost without it. I haven't found any good training for doing this in Dreamweaver with PHP yet.
Thanks again!
Brian Hightower
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 13, 2007 Feb 13, 2007
Hey David,
I have narrowed the issue down the the Restrict Access to Page behavior. When doing a google search for this issue, I found that you had answered somebody who had an identical issue.
http://forums.apress.com/showthreaded.php?Cat=&Number=2698&page=&view=&sb=5&o=&vc=1
Unfortunately, it referenced your book, which I do not have. Can you tell me what I am missing that is discussed on page 414 to 417?
Thanks!
Brian Hightower
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2007 Feb 14, 2007
BrianJHightower wrote:
> Unfortunately, it referenced your book, which I do not have. Can you tell me
> what I am missing that is discussed on page 414 to 417?

It affects MX 2004 only. The details are here:

http://friendsofed.infopop.net/2/OpenTopic?a=tpc&s=989094322&f=8033053165&m=324102421

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2007 Feb 14, 2007
BrianJHightower wrote:
> I haven't found any good training for doing
> this in Dreamweaver with PHP yet.

http://foundationphp.com/dreamweaver8/

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 14, 2007 Feb 14, 2007
I'm guessing at this point, that I have a misconfiguration in both my local testing server setup, and my hosting servers setup.
Do you have any books that discuss Dreamweaver 8 and PHP?
Thanks for your help!
Brian Hightower
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2007 Feb 14, 2007
BrianJHightower wrote:
> I'm guessing at this point, that I have a misconfiguration in both my local
> testing server setup, and my hosting servers setup.
> Do you have any books that discuss Dreamweaver 8 and PHP?

Yes, it's in my sig: "Foundation PHP for Dreamweaver 8". Direct link to
the site that describes what the book covers:

http://foundationphp.com/dreamweaver8/

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 14, 2007 Feb 14, 2007
Amazing! I didn't even see it there. I guess I've stopped reading Signatures. :)
I'm ordering it right now on Amazon.
Thanks David!
Brian Hightower
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2007 Feb 14, 2007
LATEST
BrianJHightower wrote:
> Amazing! I didn't even see it there. I guess I've stopped reading Signatures. :)
> I'm ordering it right now on Amazon.

Hope it comes up to your expectations. Please make sure you read the
book's updates and corrections here:

http://www.friendsofed.com/errata.html?isbn=1590595696

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines