Login page not working in dreamweaver cs3

Discussion in 'PHP' started by radhababu, Apr 5, 2008.

  1. #1
    I am new to php. I created a login (php5.2.5) page using dreamweaver cs3 with mysql database. I have added the login user server behaviour. When I preview, the login page opens, i enter the username and password, but the username and password is not validated and page not redirected, remains as it is. I get the following error in the localhost.error.log:

    PHP Warning: Cannot modify header information - headers already sent by (output started at C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\PHPCLI\\loginmainpage.php:1) in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\PHPCLI\\loginmainpage.php on line 68, referer: http://localhost/PHPCLI/loginmainpage.php

    The page works fine before adding login server behaviour.


    Kindly help...
     
    radhababu, Apr 5, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Hi,

    Your script sends information before your script does send header information, that is wrong. If you like to send a header to your browser (or a cookie) you may not send any other data before that (html code, or whatever)
     
    EricBruggema, Apr 5, 2008 IP
  3. Marc Fraser

    Marc Fraser Peon

    Messages:
    283
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Unless, at the top of the page you put ob_start(); and at the end ob_flush(); ... remember, put the ob_start() below your session_start() if you have one.

    It would help to see your code, though.

    Cheers
    Marc
     
    Marc Fraser, Apr 6, 2008 IP
  4. radhababu

    radhababu Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the reply, but still not working. Here is the code from main.php(created thru dw cs3). mysql database created thru phpmyadmin.


    <?php virtual('/Connections/js.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $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;
    }
    }

    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $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_js, $js);
    $query_jsrecord = "SELECT * FROM matrimony";
    $jsrecord = mysql_query($query_jsrecord, $js) or die(mysql_error());
    $row_jsrecord = mysql_fetch_assoc($jsrecord);
    $totalRows_jsrecord = mysql_num_rows($jsrecord);
    ?>
    <?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['profileid'])) {
    $loginUsername=$_POST['profileid'];
    $password=$_POST['password'];
    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = "/jsdirectory.php";
    $MM_redirectLoginFailed = "/errorlogin.php";
    $MM_redirecttoReferrer = false;
    mysql_select_db($database_js, $js);

    $LoginRS__query=sprintf("SELECT profileid, password FROM matrimony WHERE profileid=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

    $LoginRS = mysql_query($LoginRS__query, $js) or die(mysql_error());
    $loginFoundUser = mysql_num_rows($LoginRS);
    if ($loginFoundUser) {
    $loginStrGroup = "";

    //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>
    <style type="text/css">
    <!--
    body {
    background-color: #FFFFFF;
    }
    -->
    </style></head>

    <body>
    <div id="main">
    <div align="center">
    <p>&nbsp;</p>
    <form action="<?php echo $loginFormAction; ?>" method="POST" name="jsloginform" id="jsloginform">
    <table width="100" border="1">
    <tr>
    <td><label for="profileid">profile id</label>
    <input type="text" name="profileid" id="profileid" /></td>
    </tr>
    <tr>
    <td><label for="password">password</label>
    <input type="password" name="password" id="password" /></td>
    </tr>
    <tr>
    <td><label for="submit"></label>
    <input type="submit" name="submit" id="submit" value="Submit" /></td>
    </tr>
    </table>
    </form>
    <p>&nbsp;</p>
    </div>
    </div>
    </body>
    </html>
    <?php
    mysql_free_result($jsrecord);
    ?>
     
    radhababu, Apr 6, 2008 IP
  5. radhababu

    radhababu Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Please note, I get the same error in localhost.error.log.

    PHP Warning: Cannot modify header information - headers already sent by (output started at C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\main.php:1) in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\main.php on line 101, referer: http://localhost/main.php


    Thanks in advance.:
     
    radhababu, Apr 7, 2008 IP
  6. radhababu

    radhababu Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    :D
    It worked! Thanks anyway for your help. I have been breaking my head over this.

    The problem was with the preference I set in the site definition. When I changed to the document option, virtual connection changed to require_once in the script and it worked!

    :):):)
     
    radhababu, Apr 8, 2008 IP