login

Marco196943

Utente Attivo
19 Ago 2012
66
0
0
Scusatemi ma sto scapocciando posso chiedere aiuto per un login?

io ho fatto:
PHP:
<?php require_once('../Connections/centergym.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['nome_utente'])) {
  $loginUsername=$_POST['nome_utente'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "inserimento.php";
  $MM_redirectLoginFailed = "registrazione.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_centergym, $centergym);
  
  $LoginRS__query=sprintf("SELECT username, password FROM login_aquagym WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $centergym) 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>Documento senza titolo</title>
<style type="text/css">
.continer {
	height: 271px;
	width: 500px;
	margin-right: auto;
	margin-left: auto;
	background-image: url(img/bkg_login.png);
	background-repeat: no-repeat;
	background-position: center center;
	margin-top: 15%;
	padding-top: 15px;
}
.continer #id_form h3 {
	font-size: 24px;
}
.continer form {
	margin-right: auto;
	margin-left: auto;
	width: 250px;
}
.class_input {
	height: 20px;
	width: 190px;
	padding: 5px;
}

#id_form {
	width: 300px;
	margin-right: auto;
	margin-left: auto;
}
.save_input {
	padding: 3px;
	width: 85px;
	display: block;
	margin-top: 10px;
}

</style>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	color: #000;
}
body {
	background-color: #333;
}
</style>
</head>

<body>
<div class="continer">
  <div id="id_form">
<h3>Login Utente</h3>
<form action="<?php echo $loginFormAction; ?>" method="POST" name="login">
  <div align="center"><span id="sprytextfield1">
  </span></div>
  <span id="sprytextfield1">
  <label for="nome_utente">
    <div align="center">Nome Utente</div>
  </label>
  <div align="center">
    <input name="nome_utente" type="text" class="class_input" id="nome_utente" />
    <span class="textfieldRequiredMsg">È obbligatorio specificare un valore.</span></div>
  </span>
  <div align="center"><span id="sprypassword1">
  </span></div>
  <span id="sprypassword1">
  <label for="password">
    <div align="center">Password</div>
  </label>
  <div align="center">
    <input name="password" type="password" class="class_input" id="password" />
    <span class="passwordRequiredMsg">È obbligatorio specificare un valore.</span></div>
  </span>
  <div align="center">
    <input name="invia" type="submit" class="save_input" id="invia" value="Login" />
  </div>
</form></div>
</div>

<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprypassword1 = new Spry.Widget.ValidationPassword("sprypassword1");
</script>
</body>
</html>
e in locale funziona alla perfezzione, ma quando pubblico mi restituisce:


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /htdocs/public/www/prenotazioni/loigin.php:2) in /htdocs/public/wwwmiosito/loigin.php on line 38.

e se mi loggo ugualmente mi da:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /htdocs/public/www/prenotazioni/loigin.php:2) in /htdocs/public/www/miosito/loigin.php on line 38

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /htdocs/public/www/prenotazioni/loigin.php on line 63

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/public/www/miosito/loigin.php:2) in /htdocs/public/www/prenotazioni/loigin.php on line 71

potete aiutarmi gentilmente?
saluti a tutti.
 
Ciao,
prova ad eliminare il seguente codice che trovi alla riga 38

PHP:
if (!isset($_SESSION)) { 
  session_start(); 
}

e spostalo in alto ad inizio pagina.

PHP:
<?
if (!isset($_SESSION)) { 
  session_start(); 
} 
?>
 
Qualche correzione generale:
PHP:
<?php
if (!isset($_SESSION)) {
    session_start();
}

require_once __DIR__ . '/../Connections/centergym.php';

if (!function_exists('GetSQLValueString')) {
    function GetSQLValueString($value, $type, $definedValue = '', $undefinedValue = '')
    {
        if (PHP_VERSION < 6 && get_magic_quotes_gpc()) {
            $value = stripslashes($value);
        }

        if (function_exists('mysql_real_escape_string')) {
            $value = mysql_real_escape_string($value);
        } else {
            $value = mysql_escape_string($value);
        }

        switch ($type) {
            case 'text':
                $value = $value != '' ? "'{$value}'" : 'NULL';
            break;

            case 'long':
            case 'int':
                $value = $value != '' ? intval($value) : 'NULL';
            break;

            case 'double':
                $value = $value != '' ? doubleval($value) : 'NULL';
            break;

            case 'date':
                $value = $value != '' ? "'{$value}'" : 'NULL';
            break;

            case 'defined':
                $value = $value != '' ? $definedValue : $undefinedValue;
            break;
        }

        return $value;
    }
}

$loginFormAction = $_SERVER['PHP_SELF'];

if (isset($_GET['accesscheck'])) {
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['nome_utente'])) {
    $loginUsername = $_POST['nome_utente'];
    $password = $_POST['password'];

    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = 'inserimento.php';
    $MM_redirectLoginFailed = 'registrazione.php';
    $MM_redirecttoReferrer = false;

    mysql_select_db($database_centergym, $centergym);

    $LoginRS__query = sprintf(
        'SELECT username, password FROM login_aquagym WHERE username = %s AND password = %s',
        GetSQLValueString($loginUsername, "text"),
        GetSQLValueString($password, "text")
    ); 

    $LoginRS = mysql_query($LoginRS__query, $centergym) 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();
        }
        
        $_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>Documento senza titolo</title>
        
        <style type="text/css">
            .continer {
                height: 271px;
                width: 500px;
                margin-right: auto;
                margin-left: auto;
                background-image: url(img/bkg_login.png);
                background-repeat: no-repeat;
                background-position: center center;
                margin-top: 15%;
                padding-top: 15px;
            }
            .continer #id_form h3 {
                font-size: 24px;
            }
            .continer form {
                margin-right: auto;
                margin-left: auto;
                width: 250px;
            }
            .class_input {
                height: 20px;
                width: 190px;
                padding: 5px;
            }

            #id_form {
                width: 300px;
                margin-right: auto;
                margin-left: auto;
            }
            .save_input {
                padding: 3px;
                width: 85px;
                display: block;
                margin-top: 10px;
            }
        </style>
        
        <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
        <script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
        
        <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
        <link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" />
        
        <style type="text/css">
            body, td, th {
                font-family: Verdana, Geneva, sans-serif;
                font-size: 12px;
                color: #000;
            }
            body {
                background-color: #333;
            }
        </style>
    </head>

    <body>
        <div class="continer">
            <div id="id_form">
                <h3>Login Utente</h3>
                
                <form action="<?php echo $loginFormAction; ?>" method="POST" name="login">
                    <div align="center">
                        <span id="sprytextfield1"></span>
                    </div>
                    
                    <span id="sprytextfield1">
                        <label for="nome_utente">
                            <div align="center">Nome Utente</div>
                        </label>
                        
                        <div align="center">
                            <input name="nome_utente" type="text" class="class_input" id="nome_utente" />
                            <span class="textfieldRequiredMsg">È obbligatorio specificare un valore.</span>
                        </div>
                    </span>
                    
                    <div align="center">
                        <span id="sprypassword1"></span>
                    </div>
                    
                    <span id="sprypassword1">
                        <label for="password">
                            <div align="center">Password</div>
                        </label>
                        
                        <div align="center">
                            <input name="password" type="password" class="class_input" id="password" />
                            <span class="passwordRequiredMsg">È obbligatorio specificare un valore.</span>
                        </div>
                    </span>
                    
                    <div align="center">
                        <input name="invia" type="submit" class="save_input" id="invia" value="Login" />
                    </div>
                </form>
            </div>
        </div>

        <script type="text/javascript">
            var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
            var sprypassword1 = new Spry.Widget.ValidationPassword("sprypassword1");
        </script>
    </body>
</html>
Se il file viene richiamato direttamente è difficile che non funzioni.
 

Discussioni simili