Solved

Dreamweaver User Authentication with PHP and mySQL error

Posted on 2011-03-24
28
1,153 Views
Last Modified: 2013-12-13
Hi, I have created a simple login form in Dreamweaver CS5 with Log In User server behavior. It connects with my sql database(which has table, username, and passwords), yet when I check it in live view there are 3 error messages on the page above the login(which doesnt work either). The messages are orange and read:
rning: virtual() [function.virtual]: Unable to include '/public_html/Connections/connIAL.php' - request execution failed in C:\wamp\www\Intellicom Website\login.php on line 1

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\Intellicom Website\login.php:1) in C:\wamp\www\Intellicom Website\login.php on line 37

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\Intellicom Website\login.php:1) in C:\wamp\www\Intellicom Website\login.php on line 37

Not sure what I am doing wrong here. I am fairly new to php and followed a tutuorial and everything seems like it should work. ANy suggestions? Thanks in advance
0
Comment
Question by:dshmed
  • 12
  • 12
  • 4
28 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35212289
Hi dshmed,

It looks like you have a bad path somewhere.  The errors are all caused by the PHP page's inability to find connIAL.php which it expects to be at:

/public_html/Connections/connIAL.php

My guess is you have the DW site paths defined incorrectly.
0
 
LVL 6

Expert Comment

by:NeoAshura
ID: 35216086
I must agree with Jason here, It looks liek to me that it cannot find the correct path name. if you do the following... on wamp...

find the wamp folder ( usually located on C:)

Then go into www folder. This is where all your php files are stored. Then navigate to the correct path of "connIAL.php" make sure the path it goes to is the same as the path in your code.

For testing purpose's you could always remove the connection at the top of your login page to the database and replace it with the code from your "connIAL.php" page. This way you would be able to see if that was indeed the problem.

I hope this help you if you need any help just ask.

If you are new to php i can also give advice on a few books which have helped me alot.

I can also provide you with login code and "login checking" code if that helps your situation with this problem.

Hope it gets solved soon.

Best Wishes.
0
 

Author Comment

by:dshmed
ID: 35218672
Thanks to both of you, I appreciate the help. Here is some additional info:

SIte Name: Intellicom Analytics
Local Site Folder: C:\wamp\www\Intellicom Website\

Remote Server Name: Intellicom Website
Connect Using: FTP
FTP Address: www.intellicom-endpointsreport.com
Username: commuoa5
Password: ********
Root directory: public_html
web URL: http://www.intellicom-endpointsreport.com/

Testing Server Name: local testing
Connect Using: Local/network
Server Folder: C:\wamp\www\Intellicom Website\
Web URL: http://localhost/Intellicom Website/

MySQL Connection Name: connLogin
MySQL server: localhost
User name: root
Password: none
Database: users

***When I test connection here it says Connection was made successfully***

My users.sql file location: C:\wamp\www\Intellicom Website\
My login.php(my php file with the login form) location: C:\wamp\www\Intellicom Website\
My connLogin location: C:\wamp\www\Intellicom Website\Connections
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35219503
Your testing server is configured differently than your remote server (different paths) and thus DW is writing your include path the wrong way.

Do you actually have a different server for remote and testing or is this all one box?
0
 

Author Comment

by:dshmed
ID: 35220633
Hey Jason.

Again thanks for the input.  To be honest I'm not too sure. I have 2 servers listed in site setup, one remote, and one testing.  Is it unnecessary to have 2 separate servers?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220644
It depends on how your work more than anything else.  When you have two separate servers it makes thing a little more difficult in terms of file/version management and if the two servers have different paths it REALLY makes things difficult because you have to make sure that you correct paths when transferring from testing to remote.

I usually define the testing and remote servers to be the same thing if I cannot completely replicate the environment from one box to the next.
0
 

Author Comment

by:dshmed
ID: 35220661
Ok, that makes sense. I am not sure then what the server settings need to be in that case. Is it as simple\ as just clicking both the remote and testing boxes in the current server setup I had described earlier? Or are there things that need to be changed?  
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220665
Yes, to make your live site your testing server, click both checkboxes in the Server dialog in  site setup and delete any servers that don't need to be there.  

However, you will still need to fix the misbehaving page above...DW will not fix the paths automatically.
0
 

Author Comment

by:dshmed
ID: 35220705
Does it make a difference whether I use phpmyadmin that I downloaded with WAMP or should I be using the phpmyadmin on my web host's cPANEL?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220709
One connects to a local database on your computer, the other connects a database on the web host.  So you should probably use the one on your web host unless you know how to synchronize databases between two mysql installations....
0
 

Author Comment

by:dshmed
ID: 35220729
Ok, so I set up my current remote server as my remote and testing server.  I added the following mySQL connection

MySQL Connection Name: connLogin
MySQL server: localhost
User name: commuoa5
Password: *********
Database: commuoa5_IALUsers

The database shows up and I can see the data when I expand it in database window. I add the Log In User Behavior and my preview in browser ends up like this:

Fatal error: Call to undefined function virtual() in /home7/commuoa5/public_html/login.php on line 1

My live view in DW looks like this:

= 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']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];       } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?>
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220732
What is line 1 in login.php?
0
 

Author Comment

by:dshmed
ID: 35220735
<?php virtual('/Connections/connLogin.php'); ?>
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 35220738
Okay, your version of PHP may not support the virtual() function.

Try changing it to:

<?php require('Connections/connLogin.php'); ?>
0
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:dshmed
ID: 35220746
Tried it and in browser preview I am getting:

 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home7/commuoa5/public_html/login.php:2) in /home7/commuoa5/public_html/login.php on line 37

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home7/commuoa5/public_html/login.php:2) in /home7/commuoa5/public_html/login.php on line 37

line 37 reads: session_start();
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220757
Can you post all of the PHP code from that page, please.  
0
 

Author Comment

by:dshmed
ID: 35220761
<?php require('Connections/connLogin.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['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "/about.html";
  $MM_redirectLoginFailed = "/programs.html";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_connLogin, $connLogin);
  
  $LoginRS__query=sprintf("SELECT username, password FROM login WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $connLogin) 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']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  <p>Username
    <label for="username"></label>
    <input type="text" name="username" id="username" />
  </p>
  <p>Password
    <label for="password"></label>
    <input type="text" name="password" id="password" />
    <input type="submit" name="login" id="login" value="Submit" />
  </p>
</form>
</body>
</html>

Open in new window

0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220775
Move lines 36-38 to above line 3.  
0
 

Author Comment

by:dshmed
ID: 35220797
When I do that it inserts a second Log In User behavior and then says The Server Behavior panel cannot determine whether "Log in User" or "Log In User" is applied to your page.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220800
Don't worry about the Server Behavior Panel.  Does it work in the browser?
0
 

Author Comment

by:dshmed
ID: 35220807
it has the same warning session start error as before but ends with Line 4 instead of line 37
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35220843
Alright, revert it back to the way it was.  

Do you have any whitespace at the top or bottom of the code?  Sometimes that screws up PHP into thinking headers have already been sent.

Is this on your remote box or the WAMP installation?
0
 
LVL 6

Expert Comment

by:NeoAshura
ID: 35221729
Perhaps it would be wise im sure jason would agree to put error_reporting(E_ALL);  at the start before any code in every page to get more detailed errors.
0
 
LVL 6

Expert Comment

by:NeoAshura
ID: 35221741
Also, It may not make much difference but try transfering your files and database to easyPHP rather than wamp? its a portable version of WAMP basiclly. I used wamp and had loads of errors moved it to easyPHP and suddenly no more errors, i found that really strange...

also try posting your

connLogin.php

code here without the password etc.. for obv reasons.

Hopefully we will get this solved :)
0
 
LVL 6

Expert Comment

by:NeoAshura
ID: 35221757
Also i think start session should go at the top before any code. Not just above line 3.
0
 

Author Comment

by:dshmed
ID: 35222595
hey guys, thanks for the responses.  I finally got it.  Jason, you were riight I had  to change my script on line 1 to read <?php require('Connections/connLogin.php'); ?>  instead of <?php virtual(Connect...... i must have had a typo the first time I tried it.

Jason, thanks for sticking it out with me. I can finally move on to finishing this site (needs to be published by 4/1) so getting this accomplished now is huge for me.  

Thanks NeoAshura also for the input. I think I will look into EasyPHP as suggested, as this is not the first time I have encountered errors.

Take care guys and thanks again
0
 

Author Closing Comment

by:dshmed
ID: 35222605
Very clear and thorough solution.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35222998
dshmed,

Thanks for the kind words (and poinks).  

Just FYI, the built-in behaviors for DW are kind of crappy and lack features.  If you need to deploy a site fast and need more features or even better wizards, look into the WebAssist extensions (specifically: DataAssist, SecurityAssist, and Universal Email).  They will cost some extra money but will really extend your abilities until your coding skills catch up.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now