Free Programming Books
Free download ebooks on computer and programming

Free Web Design/Develpoment ebook "The Dreamweaver Developer's Instant Troubleshooter" Sample Chapter

The Dreamweaver Developer's..
Free download Ch 11, focuses on the most common PHP dev. problems,
Download chapter

The Dreamweaver Developer's Instant Troubleshooter focuses on the problems common to complex areas of Dreamweaver web development. This book also functions as a grounding and installation reference for additional technologies like PHP, ASP, MySQL, and CSS.

Inside the covers of this book, await top-notch solutions to your web development problems. You'll want to keep this tool by your side as you explore and create with Dreamweaver MX, because this complex tool sets possible traps for the unwary. Complexities include new features for building web sites with server-side scripting, standards-compliant code, advanced template features, and Cascading Style Sheets.

But this book will steer you away from possible Dreamweaver traps. Each chapter focuses on a particular area of Dreamweaver MX development, and examines likely questions-providing complete solutions. Whether you're having problems with setting up IIS to test your ASP pages, or you have a CSS quandary that you just can't wrap your brain around, then this is the book for you!

< < prev next > >

Top PHP Questions

In this chapter, we show working solutions for many of the PHP questions that are often asked. We look at dealing with session variables, file uploading, e-mail, date and time, common PHP errors, and other common queries.

For each question we show some basic working code that you can easily expand on for your own projects. For information on installing PHP and MySQL, see Chapters 5, 6, 7, and 8.

Why Don't Session Variables Work?

One of the main problems faced by users of PHP is that once they have installed it, they can't get session variables to work. The main cause of session variables not working on a new server installation is the default settings in the php.ini file. Information held in session variables is actually stored in files in a temporary directory on the server. PHP must be able to write to this directory successfully to use session variables. The setting that causes the problem is the default session.save_path in the php.ini file, which on a new installation is usually set to the following:

session.save_path = /tmp
On Windows systems, this directory doesn't exist, and it isn't created during the PHP installation, so PHP has nowhere to store session data. To fix this problem, create a directory somewhere on your server, such as C:/temp, and then edit the php.ini file and change the session.save_path setting to point to this new directory. For security reasons, make sure this directory is outside of the web folder, for example:
session.save_path = "C:/temp";
You'll then need to restart the web server so that the new setting takes effect, unless you're running PHP as a CGI module. On a Linux server running Apache, this situation doesn't occur so often, as most Linux servers do have a /tmp directory. However, it's a good idea not to use the /tmp directory and instead create a new directory exclusively for PHP temporary files. For example, you can create a directory at /home/phptemp using the command
mkdir /home/phptemp
Next, open the Apache configuration file, httpd.conf, and find which user the server runs under (usually nobody). Next, give PHP write permissions by using the command
chown nobody /home/phptemp
where the user that Apache runs under is nobody. Restart Apache, and session variables should now be working.

How Do I Check That Session Variables Are Working?

To check that session variables are working, you need to create two simple pages, one called set_session.php and one called read_session.php. The first page will set a session variable, and the second page will read it back. set_session.php contains the following:


<?php

// Code to place a value in a Session Variable

session_start();

session_register("testSession");

$HTTP_SESSION_VARS['testSession'] = "Sessions are working!"

?>

<html>

<head>

<title>Set Session</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<a href="read_session.php">Read Session</a>

</body>

</html>

This page starts session support by using the session_start function. Next, you register a session variable with the name testSession using session_register. Finally, you assign it a value.