Dreamweaver Dreamweaver Server Side Web Development

Dreamweaver is a proprietary web development tool developed by Adobe Systems. It supports many web technologies including HTML, CSS, JavaScript, and PHP. Dreamweaver provides syntax highlighting and real-time syntax checking for many web languages. A new feature in CS6 is support for "fluid grid layouts" which is used to automatically adjust the elements on a web page to accommodate the screen size of the viewing device. Adobe maintains a development site called Dreamweaver Developer Center.

Note: This page covers using Dreamweaver on the server side. That is developing PHP using a PHP test server. The Dreamweaver Client Side page covers using Dreamweaver with client technologies such as HTML, CSS, and JavaScript. See the client side pages for setting up a web root directory and configuring for a remote hosting server.

PHP Test Server Configuring a PHP Server in Dreamweaver

This method of setting up a PHP server in Dreamweaver uses a virtual host. See the Apache page for creating a virtual host.

The steps for configuring a PHP test server in Dreamweaver are:

  1. <Site><Manage Sites>
  2. Double click on the site name to edit.
  3. Go to <Servers>. Note the remote host site is already defined.
  4. Click "+" to add a new server. Enter values:
  5. Server Name: kcshadow test server
  6. Connect using: Local/Network
  7. Server Folder: c:/www/kcshadow
  8. Web URL: http://kcshadow/
  9. <Save>
    dream weaver
  10. Click the <Advanced> button.
  11. Under Test Server, Set the Server Model: PHP/MySQL
  12. <Save>
    dreamweaver

When you finish there should be two servers defined. One for the remote site and a local test server for PHP testing, as shown below:

Dreamweaver Server Configurations


Test PHP Script phpinfo()

Create and run a test file to ensure the PHP test server is working correctly:

  1. <File><New>
  2. Select Blank Page, Page Type = PHP, Layout=None, press <Create> Button
  3. Delete all the HTML from the file just created.
  4. <Insert><PHP Object><Code Block>
  5. Type phpi then <Ctrl><Space> for code hinting. Find phpinfo and select.
  6. Save file, make sure servers are running, then click on the <Live> button to see the PHP information screen.



Note: To configure PHP, check the location of the "Loaded Configuration File" from the PHP (phpinfo) installation page to be sure you are modifying the correct version of the file. My PHP configuration file is located at C:\wamp\bin\apache\apache2.2.22\bin\php.ini. See the PHP webpage for instructions on configuring the php.ini file.


Zend Framework Libraries Adding Zend Framework Libraries to Dreamweaver

Zend Framework libraries can be added to Dreamweaver. Here is the location of the Zend Frameworks API documentation. Below is the process for adding Zend Framework libraries to Dreamweaver:

  1. Create a directory on the local drive to store the Zend Framework files (c:\phpincludes\ZendFramework).
  2. Download the Zend Framework Minimal Package ( Zend Framework minimal 2.1 filename=ZendFramework-minimal-2.1.5.zip).
  3. Extract the zip file and move contents under the ZendFramework directory. Directory structure should be:

    zend framework minimal
  4. Edit the php.ini file to include the path for the Zend Framework libraries:
    • Open php.ini file.
    • Change the code (enable include_path for Zend) from:
      zend include before
      to:
      zend config after
    • Restart the servers.

Zend Framework Code Hinting Adding Zend Framework Code Hinting to Dreamweaver

Zend Framework code hinting can also be set up for the classes in Zend Framework. Below is the process for adding Zend Framework code hinting to Dreamweaver:

  1. Go to <Site><Site-Specific Code Hints>.
  2. Change Sub-root field by browsing to path of zend library (C:\phpincludes\ZendFramework\library).
  3. Add references to the files to be used in code hinting by pressing the <+> button. Then browse select the Zend folder (C:\phpincludes\ZendFramework\library\Zend). Do not check the Recursive option for this folder. Press the <+> button and add ".php" as the current extension. Click <Add> button.

    zend

  4. Include the folders containing the classes you wish to use. If using the Db class
    press the file <+> button. Browse to the Db folder (C:\phpincludes\ZendFramework\library\Zend\Db) and select it.
    For the class folders, do check the Recursive option for this folder. Press the <+> button and add ".php" as the current extension. Click <Add> button.
  5. Click <OK>. Give the structure as a preset name (Zend Framework).

    zend
Note: The location of the Zend Frameworks API documentation. Note: Zend code hinting is preconfigured for three CMS frameworks: Drupal, Joomla, and WordPress.


Server Side Includes SSI - Copy Code into Scripts

Below is the process for creating an "include" directory, creating include files, and coding the include commands in a PHP script.

  1. Set Dreamweaver to the "App Developer Plus" perspective.
  2. Set file view to "Local", then create a new folder called "_include".
  3. Create a PHP file (header.php) inside the _include directory.
  4. Put the desired code into the include PHP file (All the code in the HEADER section of page, including header tags.
  5. In the target PHP file, insert a "include" code block<Insert><PHP Object><Include>.
  6. Inside the include code block, code the path and name of the include file inside quotes, such as:

         <?php include("_include/header.php"); ?>
           
    Note: Include will continue processing if an error is found in the included code. Require will not continue processing if an error is found in the included code.
PHP Server Behaviors Generated PHP Code

Dreamweaver's built-in server behaviors can generate PHP code necessary for the basic database operations. However, server behaviors have limitations and only provide basic functionality. Adobe regards server behaviors as more of a learning tool than as a production-level feature.

Create PHP Connection File

The following procedure will create a PHP connection file that can be included in PHP code to provide a database connection. The connection file also allows Dreamweaver to display information about the database.

  1. Open any file with a .php extension in the editor. Make sure Live View is turned off.
  2. Go to <Windows><Databases> or click on the Databases icon.
  3. Click on the <+> button and select <MySQL Connection> (only selection available).
  4. Populate the fields needed for a database connection.

    Dreamweaver

  5. Click <Test> to verify connection was successful. Click <OK>

In the web site root directory, in the connections folder, a .php connection file is created with the name that was entered in the "Connection Name" field. Below is the contents of the photodb.php connection file:

<?php
  # FileName="Connection_php_mysql.htm"
  # Type="MYSQL"
  # HTTP="true"
  $hostname_photodb = "localhost";
  $database_photodb = "1218369_photos";
  $username_photodb = "root";
  $password_photodb = "";
  $photodb = mysql_pconnect($hostname_photodb,$username_photodb, $password_photodb)
      or trigger_error (mysql_error(),E_USER_ERROR); 
?>

Note: The above generated connection file only works on the local host. I modified the photodb.php file so it will work on both the local and remote hosts:

<?php
  # FileName="Connection_php_mysql.htm"
  # Type="MYSQL"
  # HTTP="true"
  $database_photodb = "1218369_photos";

  $sys = strtoupper(PHP_OS);
  if(substr($sys,0,3) == "WIN") {
     $hostname_photodb = "localhost";
     $username_photodb = "root";
     $password_photodb = "";
  } else {
     $hostname_photodb = "pdb3.your-hosting.net";
     $username_photodb = "1218369_photos";
     $password_photodb = "password"; 
  }
  $photodb = mysql_pconnect($hostname_photodb, $username_photodb, 
             $password_photodb) or trigger_error(mysql_error(),E_USER_ERROR); 
  ?>


Once a connection file exists, you will be able to see the database in Dreamweaver. The database tables and columns will be visible in the database window.

Dreamweaver

Create Single Table Record Set

Dreamweaver can create definitions of dynamic data called bindings. The bindings are used to create code for retrieving specified data from the database. Dreamweaver refers to this retrieved data as record sets. The procedure for creating a record set using only one table:

  1. Create and open a new *.php file ("rsPhotos.php") in the editor. This file will receive the generated record set code. Make sure live view is turned off.
  2. Go to <database><bindings>
  3. Click on the <+> icon and select <Recordset (Query)>
  4. Use the Simple mode. Prefix name of record set with "rs" ("rsPhotos").
  5. Select name of the DB connection file, the table, columns, filter, and sorting.

    Dreamweaver

  6. Click on <Test> to preview the resulting record set.
  7. Click on <OK> and the recordset code will be inserted into the file, such as:
<?php require_once('Connections/photodb.php'); ?>

<?php
if (!function_exists("GetSQLValueString")) {
   function GetSQLValueString($theValue, $theType, 
                              $theDefinedValue = "", $theNotDefinedValue = "") 
{
if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}  
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : 
  
mysql_escape_string($theValue);
   switch ($theType) {
      case "text":
         $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
         break; 
      case "long":
      case "int":
         $theValue = ($theValue != "") ? intval($theValue) : "NULL";
         break;
      case "double":
         $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
         break;
      case "date":
         $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
         break;
      case "defined":
         $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
         break;
   }
   return $theValue;
  }
}
mysql_select_db($database_photodb, $photodb);
$query_rsPhotos = "SELECT * FROM photos ORDER BY PhotoId ASC";
$rsPhotos = mysql_query($query_rsPhotos, $photodb) or die(mysql_error());
$row_rsPhotos = mysql_fetch_assoc($rsPhotos);
$totalRows_rsPhotos = mysql_num_rows($rsPhotos);

mysql_free_result($rsPhotos);
?>
  
The generated code requires the include file containing the DB connection code. It defines the SQL query in a variable and then runs the SQL (mysql_query). It stores the returned data in an array (mysql_fetch_assoc). It stores the number of rows retrieved in a variable (mysql_num_rows). These variables containing the database data can then be used by the PHP program. Note the very last line contains mysql_free_result() which releases the memory used to store the data retrieved from the database.


Create Multi-Table Record Set

Dreamweaver can create record sets that retrieve data from more than one table. The procedure is similar to the above procedure for creating a single table record set, except you use the Advanced mode.

  1. Create and open a new *.php file ("rsLanguages.php") in the editor. This file will receive the generated record set code. Make sure live view is turned off.
  2. Go to <database><bindings>
  3. Click on the <+> icon and select <Recordset (Query)>
  4. Use the Advanced mode. Prefix name of record set with "rs" ("rsLanguages").
  5. Select name of the DB connection file, and insert the SQL desired.

    Dreamweaver

  6. Click on <Test> to preview the resulting record set. Note: You may wish to test the SQL in MySQL before saving the results.
  7. Click on <OK> and the recordset code will be inserted into the file.
Repeating Regions Dynamic Data Display

Dreamweaver record sets can be used to dynamically display data from the database. Multiple rows of data can be displayed on a web page by using Repeating Regions. Below is the procedure for creating a web page that displays multiple rows from a database by using Repeating Regions.

  1. Create and open a new *.php file ("photos_dmp.php") in the editor. Make sure live view is turned off.
  2. Hard code the HTML to display one row of database data inside a division, along with a header row, as shown below:

    <body>
    <p>Below is the contents of the 1218369_photos database.</p>
    
    <div>
      <span>PhotoId</span>
      <span>Title</span>
      <span>Description</span>
      <span>Comment</span>
      <span>Comment2</span>
    <span>Location</span>
    <span>Keywords</span>
    <span>Path</span><br> <span>PhotoId</span>
    <span>Title</span>
    <span>Description</span>
    <span>Comment</span>
    <span>Comment2</span>
    <span>Location</span>
    <span>Keywords</span>
    <span>Path</span><br>
    </div>
    </body>
  3. Create a record set to be used on the page (see procedures above).
  4. Display the web page in Design view and select the first column (PhotoID). Use the tag selector to select entire element.
  5. Open the record set just created. Select the desired field and drag and drop on the selected element in Design view. Notice the column data was replaced by the dynamic field name inside braces {rsPhotoDmp.PhotoId}. You can see this in the Design view and in Code view.

    Dreamweaver
    <div>
    <span><?php echo $row_rsPhotoDmp['PhotoId']; ?></span>
    <span>Title</span>
    <span>Description</span>
    <span>Comment</span>
    <span>Comment2</span>
    <span>Location</span>
    <span>Keywords</span>
    <span>Path</span><br>
  6. Repeat the drag and drop for each field then open Live view. You should see the first row of data from the database.
  7. Next a Repeating Regions is added. Go to Design View and click anywhere inside the dynamic variables. Click on the <Div> tag in the tag selector. Then go to <Insert><DataObject> and select <Repeat Region>. Pick the region, change radio button to <All Records>, and select <OK>. A "Repeat" tag is displayed in Design view to indicate a repeating region:
    Dreamweaver

  8. In Live view you should see all the database rows displayed. The generated code is:
<?php do { ?>
<div>
<span><?php echo $row_rsPhotoDmp['PhotoId']; ?></span>
<span><?php echo $row_rsPhotoDmp['Title']; ?></span>
<span><?php echo $row_rsPhotoDmp['Description']; ?></span>
<span><?php echo $row_rsPhotoDmp['Comment']; ?></span>
<span><?php echo $row_rsPhotoDmp['Comment2']; ?></span>
<span><?php echo $row_rsPhotoDmp['Location']; ?></span>
<span><?php echo $row_rsPhotoDmp['KeyWords']; ?></span>
<span><?php echo $row_rsPhotoDmp['Path']; ?></span><br>
</div>
<?php } while ($row_rsPhotoDmp = mysql_fetch_assoc($rsPhotoDmp)); ?>

Dynamic Tables Dynamic Data Display

Another approach to displaying database data on a web page is with a Dynamic Table. The procedure is similar to using Repeating Regions, but is a litter faster as the less HTML coding is required.

  1. Create and open a new *.php file ("photos_dmp2.php") in the editor. Make sure live view is turned off.
  2. Create a record set to be used on the page.
  3. In Code view, go to insertion point in page and add paragraphs tags. Place cusor inside the paragraph tags and go to Design View.
  4. Then go to <Insert><Data Objects><Dynamic Data> and select <Dynamic Table>.
  5. Select the desired record set, change the radio button to All Records, and select <OK>.

    Dreamweaver

  6. Format the table as desired. You can highlight the top row and select Header in the properties panel to change the first row to a header row.

Paging Controls Add Paging Controls to Repeating Reginons

Repeating regions can be set to display a limited number of rows and then paging controls can be added to page thru the data. To add paging controls:

  1. In document that has a repeating region, set the number of rows to set the page size in the repeating region definition.
  2. Add Hyperlinks that allow for paging. Goto <Database><Server Behaviors><+><Recordset Paging>.
  3. Add the four links: Move To (First, Previous, Next, Last) pages. Specify in the link field to "Create a new link" for each link.
  4. Test the paging using an external browser.

Paging Controls Add Paging Controls to Repeating Reginons

Repeating regions can be set to display a limited number of rows and then paging controls can be added to page thru the data. To add paging controls:

  1. In document that has a repeating region, set the number of rows to set the page size in the repeating region definition.
  2. Add Hyperlinks that allow for paging. Goto <Database><Server Behaviors><+><Recordset Paging>.
  3. Add the four links: Move To (First, Previous, Next, Last) pages. Specify in the link field to "Create a new link" for each link.
  4. Test the paging using an external browser.

Paging Controls Add Paging Controls to Repeating Regions

Repeating regions can be set to display a limited number of rows and then paging controls can be added to page thru the data. To add paging controls:

  1. In document that has a repeating region, set the number of rows to set the page size in the repeating region definition.
  2. Add Hyper links that allow for paging. Go to <Database><Server Behaviors><+><Recordset Paging>.
  3. Add the four links: Move To (First, Previous, Next, Last) pages. Specify in the link field to "Create a new link" for each link.
  4. Test the paging using an external browser.

Paging Control Conditions Make Appropriate Page Controls Display

When on the first and last pages, it does not make sense to display all four of the page links. If you are on the last page, the links for "Last Page" and "Next Page" should not display. The procedure below modifies the logic to make the page links display appropriately.

  1. In Design view, click and drag the First and Previous links. Go to the Server Behaviors panel, click <+>, and go to <Show Region>. Select the options:
    • Show if not first page

  2. Next, click and drag the Next and Last links. Go to the Server Behaviors panel, click <+>, and go to <Show Region>. Select the options:
    • Show if not last page

Creating Input Forms Form with Input Controls in Table to be Posted

Typically a data entry form in PHP uses the POST method (as opposed to GET). In this example the action parameter on the form is set to blank ("") which caused the form to by posted by the same page that submitted it. Input tags are created that contain a "name" attribute which will correspond to the PHP variable name. The input tags also have an "id" attribute which can be used by JavaScript for such functions as validation. The procedure to create an input form is:

  1. Create a new .php file (phadd.php) to be used as the input screen.
  2. Create a table with as many rows as input fields and two columns. Put the name of the input fields in the first column.
  3. In Design view, to the right of the table, add a form <Insert><Form><Form>.

    Note: The form tag created contains a method of POST (as opposed to GET). Typically a data entry form in PHP uses the POST method. Also the action is set to blank ("") this causes the form to be posted by the same page that submitted it.

  4. Select the entire table (use tag selector) and cut the table. Then paste the table inside the form.
  5. Click inside the second column of the first row. Add a text field to the column by going to <Insert><Form><Text Field>. Enter the ID and no label. Click on <OK>.

    Note: An input tag is created in the code. The input tag contains a "name" field which will be the name of the PHP value when the form is submitted. The input tag also contains an "id" field which can be used by JavaScript.

    Dreamweaver

  6. Repeat the procedure for each input field in the table.
  7. Add a row at the bottom of the table and add a button in the right-most column. <Insert><Form><Button> and name the id "Submit".

    Dreamweaver.

Form Submission Handling Form Submission with PHP

PHP code is used to handle the form submission. The first time the form is submitted, the page only needs to display the input form. On subsequent submissions the form will also need to process the data from the input fields. So code is needed to see if the form variables are set and then process the data in the form variables.

  1. Use the binding panel to create a form variable <Database><Bindings><+><Form Variable>. Name the variable the same as the "name" attribute in the <input> tag (title) and click <OK>. Repeat the process for all the input fields.
    Dreamweaver

  2. In code view, just after the <body> tag add conditional logic for processing the data submitted in the form:
    • Position cursor just after the <body> tag.
    • Insert a PHP code block.
    • Code: if (isset() ) the refresh the page to get the new context.
    • Go to the bindinings panel, find the variable and drag and drop to the innermost set of parenthesis.
    • Put logic inside If statement to process the form data.

      <body>
      <?php if (isset($_POST['title'])) { echo "Title: " . $_POST['title'] . "<br>"; } ?>

Form Validation Using Spry to Validate Fields on Form

Portion of Adobe's Spry are integrated into Dreamweaver. Spry is a JavaScript/AJAX framework. The process below uses Spry to add the "required" validation to fields on a form.

  1. In Design view, click on the control that needs validation. Then go to <Insert><Spry><Spry Validation Text Field>(or appropriate control) and click once.
  2. Go to the properties panel for the Spry Textfield. Change the field name as desired (spryTitle), set the data type required (if needed). Note: The "custom" selection on data type allows the use of regular expressions to validate data. Enter the Min and Max number of characters, as desired. Modify the "Preview States" screen validation messages if desired. Change the validation to be on "Blur". Leave the "Required check box checked.
  3. When you save your changes a message indicates two new files are created:
    • SpryAssets/SpryValidationTextField.css
    • SpryAssets/SpryValidationTextField.js
      Save the files and deploy them to production server with updated code.
  4. Test the validation on an external browser.

Insert Form Behavior Configuring the Insert Behavior to Insert a Row into Database

Once the Add form has been created, the Insert form behavior can be added to the program. The Insert form behavior contains all the logic to get the data from the form and send it to the database for insertion.

  1. Open the program which contains the add form with all the validation already coded (phadd.php).
  2. Go to <Server Behaviors><+> and select "Insert Record". Populate the Insert Record form and click on <OK>.

    Dreamweaver
  3. Save the program and test in an external browser.

Delete Form Behavior Configuring the Delete Behavior to Delete a Row into Database

A link is created on the list table for both Deleting and Editing a record. Then the programs are created and the behaviors added. The Delete program is the easiest to create:

  1. In the list program (phlist.php) select the entire last column and go to <Table><Insert Rows or Columns>. Insert two columns after the current column. Then in the first new column type "Edit" and in the second new column type "Delete".
  2. Next, create a new PHP program (phdelete.add) and remove all the HTML so it is an empty file.
  3. Go to <Server Behaviors><+> and select "Delete Record". Populate the Delete Record form and click on <OK>.

    Dreamweaver

  4. Save the program and run. It will not display anything on the screen. Move the six lines at the bottom of the file (phdelete.php) to the other side of the end brace. This will cause it to display the list instead of an empty screen when it is called with no parameter. The code should look like this:
       
    if ((isset($_GET['PhotoId'])) && ($_GET['PhotoId'] != "")) {
       $deleteSQL = sprintf("DELETE FROM photos WHERE PhotoId=%s",
       GetSQLValueString($_GET['PhotoId'], "int"));
       mysql_select_db($database_photodb, $photodb);
    
       $Result1 = mysql_query($deleteSQL, $photodb) or die(mysql_error());
    }
    
    $deleteGoTo = "phlist.php";
    if (isset($_SERVER['QUERY_STRING'])) {
       $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
       $deleteGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $deleteGoTo));
    ?>
  5. On the list program (phlist.php) and select the newly added "Delete" column. Go to the Properties menu (HTML) and add a link by browsing and selecting the delete program (phdelete.php). Click on <OK>.
  6. The delete will not work yet because the primary key is not getting passed in. This needs to be added manually. So open the list program (phlist.php) in Code view and add the primary key parameter on the link to the delete program. Make sure the spelling and case of the variable name (PhotoId) is correct or else the delete will not work

    Dreamweaver

Log In Behavior Authenticating Users

Login validates the user name and password against the values stored in the database table (photos.admin).

  1. Create .php file containing the login form with input validation (login.php).
  2. Create database table for login(photo.admin) with fields: PhotoId(INT,Unsigned,PK), UserName(VARCHAR 30), and Password (VARCHAR 15).
  3. Test connection to database (photos). Then insert User Authentication behavior by going to <Insert><Data Objects><User Authentication><Log In User>. Fill in the field values and click<OK>.

    Dreamweaver


    The following PHP code is inserted at the top of the file:

    <?php require_once('Connections/photodb.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
    if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    }
    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }
    ?>
    <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['user_name'])) { $loginUsername=$_POST['user_name']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "resume.php"; $MM_redirectLoginFailed = "login.php"; $MM_redirecttoReferrer = true; mysql_select_db($database_photodb, $photodb); $LoginRS__query=sprintf("SELECT UserName, Password FROM `admin` WHERE UserName=%s AND Password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
    $LoginRS = mysql_query($LoginRS__query, $photodb) or die(mysql_error());
    $loginFoundUser = mysql_num_rows($LoginRS);
    if ($loginFoundUser) { $loginStrGroup = ""; if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();} //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;
    if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
    }
    else {
    header("Location: ". $MM_redirectLoginFailed );
    }
    }
    ?>
  4. Test the login on an external browser.

Protecting Page Access Require Authentication to View Page

PHP code needs to be included on each page that is to be protected by requiring usering authentication. The PHP code creates a session ($_SESSION) which remains active as long as the browser is open. Any page which needs to be protected must either obtain the active session or call the session_start() function. The session will indicate if the user has logged in. I created an include file called auth.php which includes this code and is included in the program for all pages needing authentication protection. Note: Access Level can be included if a more granular security model is desired.

The procedure for creating the page restriction code is:

  1. Open the .php file that is to be restricted.
  2. Test connection to database (photos). Then insert Restrict Access to Page behavior by going to <Insert><Data Objects><User Authentication><Restrict Access To Page>. Fill in the field values and click<OK>.

    Dreamweaver

  3. Now run the page in an external browser. Instead of the page displaying, you should go to the login form.
  4. Each page needing protection should contain the include file:

        <?php require_once('auth.php'); ?>
        
    The PHP code inside this program is:

        <?php
    if (!isset($_SESSION)) { session_start(); }
    $MM_authorizedUsers = "";
    $MM_donotCheckaccess = "true"; // *** 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 == "") && true) {
    $isValid = true;
    }
    }
    return $isValid;
    } $MM_restrictGoTo = "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($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
    $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
    $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit;
    }
    ?>

Logging Out Log Out User Behavior

The log out clears the session variables and returns to the log in page. The procedure for creating a log out page is:

  1. Create .php file to contain the log out behavior (logout.php).
  2. Insert User Authentication behavior by going to <Insert><Data Objects><User Authentication><Log Out User>. Fill in the field values and click<OK>.

    Dreamweaver


    The following PHP code is inserted at the top of the file:

    <?php
    // *** Logout the current user.
    $logoutGoTo = "login.php";
    if (!isset($_SESSION)) {
    session_start();
    }
    $_SESSION['MM_Username'] = NULL;
    $_SESSION['MM_UserGroup'] = NULL;
    unset($_SESSION['MM_Username']);
    unset($_SESSION['MM_UserGroup']);
    if ($logoutGoTo != "") {header("Location: $logoutGoTo");
    exit;
    }
    ?>

  3. Test the log out with an external browser.




Update Form Behavior Configuring the Update Behavior to Update a Row into Database
  1. Copy the add program to make a delete program (phadd.php copied to phupdate.php.
  2. Open the update program (phupdate.php) and remove ALL the PHP code. There is PHP code at the top and embedded in the HTML. Then run in live view to verify the field validations are still working.
  3. Add a recordset to the program. Go to <Binding><Recordset> and fill in the record set field. Chose to filter on the primary key. As successful test, click <OK> to save.

    Dreamweaver

  4. Bind the dynamic data to the form fields. In Design view, position the cursor on the first field, then using the bindings (lightning bolt) to drag and drop the corresponding field from the recordset. Repeat this until all the fields have been bound to the dynamic data.

    Dreamweaver

  5. You must pass the primary key value from the form to the page that will do the action. This is done with a hidden field. The hidden field must be inside the form tags inorder to be passed from the form to the action page. Find the place to put the hidden field, then from Code view go to <Insert><Form><Hidden Field>. The tag editor will appear. Do not populate any of the fields, just hit <OK>.

    Dreamweaver

  6. In Design view, click on the hidden field icon for the hidden field you just created. Go to properties panel and use the primary key field (as is defined in the database table) as the Hidden Field name. Then for the value, use the bindings to bind the primary key value in the recordset.

    Dreamweaver


  7. In Code view find the code where the $colname variable is set to -1. Change it to be set to 1. That is change:

    $colname_rsPhoto = "-1";
    
    to
    $colname_rsPhoto = "1";
    

    This will allow you to use Live view to see the record in the update form which has a primary key value of 1.
  8. Next add the Update Record form behavior. From Design view go to <Server Behaviors><+> and select <Update Record>. Fill in the fields in the Update Record and save with <OK>.

    Dreamweaver

  9. Save the program and test in an external browser, starting from the list program.
Working Faster with Dreamweaver Shortcuts and Tips

The keyboard shortcuts for Dreamweaver are defined in <Edit><Keyboard Shortcuts>. Below are a few of the useful default definitions:

Dreamweaver Keyboard Short Cut Keys
Short Cut Keys
Keys Short Cut Description
<Ctrl><Space> Content Assist Context Auto Completion.
<Ctrl><Click> Follow Link Use in Live view. Supports local links only.


Tips
  1. Use Split Code view to same document in two editor windows.
    • <View>
    • <Split Code>

  2. Collapse sections of code in document.
    • Select the code you wish to collapse.
    • Select the "-" icon to collapse and the "+" icon to restore.

  3. Define macros to execute a series of commands.
    • <Commands>
    • <Start Recording>
    • Enter command you wish in macro.
    • <Play Recorded Command>



Top | PHP Test Server | phpinfo | Zend Libraries | Zend Code Hinting | Working with Dreamweaver