Foros del Web » Programando para Internet » PHP »

Proyecto web de Trivial

Estas en el tema de Proyecto web de Trivial en el foro de PHP en Foros del Web. Buenos dias. Estoy tratando de hacer una web con un minijuego de trivial para jugar con mis amigos , tengo conocimientos basicos y he estado ...
  #1 (permalink)  
Antiguo 07/02/2014, 07:21
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Proyecto web de Trivial

Buenos dias.

Estoy tratando de hacer una web con un minijuego de trivial para jugar con mis amigos , tengo conocimientos basicos y he estado navegando e informandome por distintos foros y ejemplos, para tratar de realizarlo y avanzar.

Estoy teniendo unos problemas con el registro de usuario y reconocimiento dentro de la web.

Llevo peleandome con esto, dias y no consigo avanzar.

Si alguien mas experto puede ayudarme, me seria de mucha utilidad.
La web es http://thetruth.hol.es/
Servidor Hostinger y base de datos PHPMYADMIN

Disculpen las molestias, si alguien quiere que le pase parte del codigo o algo del codigo indicarmelo.
  #2 (permalink)  
Antiguo 07/02/2014, 07:50
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: Proyecto web de Trivial

Cita:
y base de datos PHPMYADMIN


phpMyadmin no es una base de datos. Es una interfaz de usuario para administrar MySQL de un modo amigable.

Explica claramente lo del problema de registro de usuario, postea los códigos, mensajes de error, y si es posible una descripcion de lo que quieres obtener.

Nota: No vamos a entrar en la web para hacer experiencias. Y postear el link se puede tomar como autopromo, como ya lo sabrás.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #3 (permalink)  
Antiguo 11/02/2014, 06:26
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

index.php
require_once "config.php";

if (strlen(trim($strSessionPath)) > 0)
session_save_path($strSessionPath);

session_start();

$strMessage = "";

if (!empty($_SESSION['message'])) {
$strMessage = trim($_SESSION['message']);
}
?>

<html>
<head>
<title>Registro</title>
<meta charset="UTF-8">
</head>
<body>

<center><img src="images/yoshua.png" width="50%" height="40%"></center><br><hr>

<form name="login" action='login.php' method='POST'>
<table width='800'>
<tr>
<td width='160' valign='middle' align='center' STYLE='background-image:url(images/count.png); background-repeat: no-repeat; background-position:center center;'>
<table>
<tr><td STYLE='color: #000000;'>
<a href="options.php" accesskey='c'style=" font-size:20px;">
[<span STYLE="color: red">C</span>rear una cuenta]</a></td></tr>
</table>
</td>
<td width='640' align='center'>
<?php
if (strlen(trim($strMessage)) > 0) {
echo '<font size="5"><b>'.$strMessage.'</b></font>';
$_SESSION['message'] = "";
}
?>
<table>
<tr><td><u>N</u>ick:</td></tr>
<tr><td><input type='text area' name='name' accesskey='u' size='10'></td></tr>
<tr><td><u>C</u>ontraseña:</td></tr>
<tr><td><input type='password' name='password' accesskey='p' size='10'></td></tr>
<tr><td><input type='submit' name='submit' value='Logueate' class='button'></td></tr>
</table>
</td>
</tr>
</table>
</form>

<?php require_once "footer.php"; ?>
</body>
</html>

<script type="text/javascript">
<!--
document.login.name.focus();
document.onkeypress = keyevent;

function keyevent(e)
{
var c;

c = String.fromCharCode(window.event.keyCode).toUpperC ase();
target = window.event.srcElement;

if (target.nodeName.toUpperCase() == 'INPUT')
{
if (target.type.toUpperCase() == 'SUBMIT')
{
if (c == 'C') {
window.location = 'options.php';
;
return false;
}
}
}
else
{
if (c == 'C') {
window.location = 'options.php';
;
return false;
}
}
}
//-->
</script>
  #4 (permalink)  
Antiguo 11/02/2014, 06:27
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

login.php
require_once "config.php";

if (strlen(trim($strSessionPath)) > 0)
session_save_path($strSessionPath);

session_start();

$intUserNumber = 0;
$strName = "";
$strPassword = "";
$boolError = false;
$strTempDBInfo = "";

if (empty($HTTP_POST_VARS['name']))
{
$_SESSION['usernumber'] = 0;
$_SESSION['name'] = "";
$_SESSION['message'] = "Datos Incorrectos";
$boolError = true;
}
else
{
$strName = $HTTP_POST_VARS['name'];
$strPassword = $HTTP_POST_VARS['password'];
}

if (!$boolError)
{
$strTempDBInfo = DBTYPE."_pconnect";
$conn = $strTempDBInfo($DB_HOST,$DB_USER,$DB_PASS);
}

if (!$boolError && !$conn)
{
$_SESSION['usernumber'] = 0;
$_SESSION['name'] = "";
$strTempDBInfo = DBTYPE."_error";
$_SESSION['message'] = "Unable to connect to DB server: " . $strTempDBInfo($conn);
$boolError = true;
}

$strTempDBInfo = DBTYPE."_select_db";

if (!$boolError && (!$strTempDBInfo($DB_NAME)))
{
$_SESSION['usernumber'] = 0;
$_SESSION['name'] = "";
$strTempDBInfo = DBTYPE."_error";
$_SESSION['message'] = "Unable to select DB name: " . $strTempDBInfo($conn);
$boolError = true;
}

if (!$boolError)
{
$sql = "SELECT UserNumber, UserName FROM login " .
"WHERE UserName = '$strName' AND UserPassword = '$strPassword'";

$strTempDBInfo = DBTYPE."_query";
$result = $strTempDBInfo($sql);

if (!$result)
{
$_SESSION['usernumber'] = 0;
$_SESSION['name'] = "";
$strTempDBInfo = DBTYPE."_error";
$_SESSION['message'] = "Could not successfully run query ($sql) from DB: " . $strTempDBInfo($conn);
$boolError = true;
}
}

if (!$boolError)
{
$strTempDBInfo = DBTYPE."_num_rows";

if ($strTempDBInfo($result) == 0)
{
$_SESSION['usernumber'] = 0;
$_SESSION['name'] = "";
$_SESSION['message'] = "User not found.";
$boolError = true;
}
else
{
$strTempDBInfo = DBTYPE."_fetch_assoc";
$row = $strTempDBInfo($result);

$_SESSION['usernumber'] = $row['UserNumber'];
$_SESSION['name'] = $row['UserName'];

//Updte UserLastIP here
$strUserLastIP = $_SERVER['REMOTE_ADDR'];
$sql = "UPDATE login SET UserLastIP = '$strUserLastIP' " .
"WHERE UserName = '".$row['UserName']."'";

$strTempDBInfo = DBTYPE."_query";
$result = $strTempDBInfo($sql);

if (!$result)
{
$strTempDBInfo = DBTYPE."_error";
$strMessage = "Could not successfully run query ($sql) from DB: " . $strTempDBInfo($conn);
$boolError = true;
}
else
{
$_SESSION['message'] = "";
$boolError = false;
}
}
}

if ($boolError)
{
header("Location: index.php");
}
else
{
header("Location: main.php");
}
?>
  #5 (permalink)  
Antiguo 11/02/2014, 06:27
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

config.php
define('DBTYPE',"mysql");

$DB_HOST="mysql.hostinger.es"; //Database Hostname
$DB_USER="u565572846_yo"; //Database Username
$DB_PASS="camello"; //Database Password
$DB_NAME="u565572846_truth"; //Database Databasename

// Trivia Games:
$strTriviaTables = array
(
array("riddles", "Riddles from Legend Of the Green Dragon"),
//array("gwztrivia", "Galactic Warzone's Trivia"),
//array("irctrivia", "IRC Trivia")
);

//path where session informations is stored if different from the default path.
$strSessionPath = "";

$strCrLf = "`n";
$strFieldSeperator = ";";

if ((DBTYPE == "") || ($DB_HOST == "") || ($DB_USER == "") ||
($DB_PASS == "") || ($DB_NAME == ""))
{
$_SESSION['message'] = "You must edit the config.php file to access your database.";
header("Location: index.php");
exit;
}
?>
  #6 (permalink)  
Antiguo 11/02/2014, 06:30
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

options.php
require_once "config.php";

if (strlen(trim($strSessionPath)) > 0)
session_save_path($strSessionPath);

session_start();

$strName = "";
$strMessage = "";
$strAction = "";

if (empty($_SESSION))
{
$_SESSION['action'] = $strAction = "Crear nuevo Usuario";
}
else
{
if (strlen(trim($_SESSION['name'])) > 0)
{
$strName = $_SESSION['name'];
$_SESSION['action'] = $strAction = "Cambiar Contraseña";
}
else
{
$strName = "";
$_SESSION['action'] = $strAction = "Crear nuevo Usuario";
}

if (!empty($_SESSION['message']))
{
$strMessage = trim($_SESSION['message']);
}
}
?>

<html>
<head>
<title>Registro</title>
<meta charset="UTF-8">
</head>
<body>
<?php
if (strlen(trim($strMessage)) > 0)
{
echo $strMessage;
$_SESSION['message'] = "";
}
?>

<table width='800'>
<tr>
<td width='160'><table></table></td>
<td width='640' align='center' style="font-weight: bold; font-size:25px;">
<table><?php echo $strAction ?></table>
</td>
</tr>
</table>

<hr>
<form name='options' action='user.php' method='POST'>
<table width='800'>
<tr>
<td width='160' valign='center' align='center' STYLE='background-image:url(images/count.png); background-repeat: no-repeat; background-position:center center;''>
<table>
<tr>
<td STYLE='color: #000000; font-size: 20px;'>
<?php
if ($strAction == "Cambiar Contraseña")
{
echo "<a href='main.php' accesskey='b'>[<span STYLE='color: red'>B</span>ack]</a>";

}

if ($strAction == "Crear nuevo Usuario")
{
echo "<a href='logout.php' accesskey='l' >[<span STYLE='color: red'>L</span>oguearse]</a>";
}
?>
</td>
</tr>
</table>
</td>
<td width='640' align='center'>
<table>
<tr><td><u>U</u>suario:</td></tr>
<tr>
<td>
<?php
if ($strAction == "Cambiar Contraseña")
{
echo "<input type='text area' name='name' accesskey='u' size='10' readonly value='$strName'>";
}

if ($strAction == "Crear nuevo Usuario")
{
echo "<input type='text area' name='name' accesskey='u' size='10'>";
}
?>
</td>
</tr>
<tr><td>Nueva <u>C</u>ontraseña:</td></tr>
<tr><td><input type='password' name='password1' accesskey='p' size='10'></td></tr>
<tr><td><u>R</u>epetir:</td></tr>
<tr><td><input type='password' name='password2' accesskey='r' size='10'></td></tr>
<tr><td><input type='submit' name='submit' value='Guardar' class='button'></td></tr>
</table>
</td>
</tr>
</table>
</form>

<?php require_once "footer.php"; ?>
</body>
</html>

<script type="text/javascript">
<!--
if (document.options.name.value.length == 0 )
{
document.options.name.focus();
}
else
{
document.options.password1.focus();
}

document.onkeypress=keyevent;

function keyevent(e)
{
var c;

c=String.fromCharCode(window.event.keyCode).toUppe rCase();
target=window.event.srcElement;

if (target.nodeName.toUpperCase() == 'INPUT')
{
if (target.type.toUpperCase() == 'SUBMIT')
{
if (document.options.name.value.length == 0 )
{
if (c == 'L') { window.location='logout.php';; return false; }
}
else
{
if (c == 'B') { window.location='main.php';; return false; }
}
}
}
else
{
if (document.options.name.value.length == 0 )
{
if (c == 'L') { window.location='logout.php';; return false; }
}
else
{
if (c == 'B') { window.location='main.php';; return false; }
}
}
}
//-->
</script>
  #7 (permalink)  
Antiguo 11/02/2014, 06:31
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

user.php
require_once "config.php";

if (strlen(trim($strSessionPath)) > 0)
session_save_path($strSessionPath);

session_start();

$boolError = false;
$strAction = "";
$strMessage = "";
$strName = "";
$strPassword1 = "";
$strPassword2 = "";
$strTempDBInfo = "";

// Critical Error checking
if (empty($_SESSION))
{
$_SESSION['name'] = "";
$_SESSION['message'] = "You must log in to proceed.";
header("Location: index.php");
exit;
}
else
{
$strAction = $_SESSION['action'];
}

// User Error checking
if (!empty($HTTP_POST_VARS['name']))
{
$strName = $HTTP_POST_VARS['name'];
}
elseif ($strAction == "Create New User")
{
$strMessage = "User was NOT created! You must specify a user. ";
$boolError = true;
}

// boolError checks are in there own clause instead of merging them with the nested if statement.
// Otherwise, the error message of the real error will be overwritten by the last message in the
// last error check.
if (!$boolError)
{
if (!empty($HTTP_POST_VARS['password1']))
{
$strPassword1 = $HTTP_POST_VARS['password1'];
}
else
{
$strMessage = "You must specify a password.";
$boolError = true;
}
}

if (!$boolError)
{
if (!empty($HTTP_POST_VARS['password2']))
{
$strPassword2 = $HTTP_POST_VARS['password2'];
}
else
{
$strMessage = "You must validate your password by typing it twice.";
$boolError = true;
}
}

// $boolError can be merged with if statements if there is no 'else' clause
if (!$boolError && ((strlen($strPassword1) < 4) || (strlen($strPassword1) > 32)))
{
$strMessage = "Change was NOT successful! Password must be no shorter than 4 characters and no longer than 32 characters.";
$boolError = true;
}

if (!$boolError && ($strPassword1 != $strPassword2))
{
$strMessage = "Change was NOT successful! New password was not the same as the retyped password.";
$boolError = true;
}

if (!$boolError)
{
$strTempDBInfo = DBTYPE."_pconnect";
$conn = $strTempDBInfo($DB_HOST,$DB_USER,$DB_PASS);

if (!$conn)
{
$strTempDBInfo = DBTYPE."_error";
$strMessage = "Unable to connect to DB server: " . $strTempDBInfo($conn);
$boolError = true;
}
else
{
$strTempDBInfo = DBTYPE."_select_db";
}
}

if (!$boolError && (!$strTempDBInfo($DB_NAME)))
{
$strTempDBInfo = DBTYPE."_error";
$strMessage = "Unable to select DB name: " . $strTempDBInfo($conn);
$strTempDBInfo = DBTYPE."_close";
$strTempDBInfo($conn);
$boolError = true;
}

if (!$boolError)
{
if ($strAction == "Create New User")
{
$sql = "SELECT UserName FROM login WHERE UserName = '" . $strName . "'";
$strTempDBInfo = DBTYPE."_query";
$result = $strTempDBInfo($sql);

if (!$result)
{
$strTempDBInfo = DBTYPE."_error";
$strMessage = "Could not successfully run query ($sql) from DB: " . $strTempDBInfo($conn);
$boolError = true;
}
else
{
$strTempDBInfo = DBTYPE."_num_rows";

if ($strTempDBInfo($result) != 0)
{
$strMessage = "This user already exists.";
$boolError = true;
}
}
}
}

if (!$boolError)
{
if ($strAction == "Change Password")
{
$sql = "UPDATE login SET UserPassword = '$strPassword1' " .
"WHERE UserName = '$strName'";
}

if ($strAction == "Create New User")
{
$strUserLastIP = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO login ( UserName, UserPassword, UserLastIP ) " .
"VALUES ('$strName', '$strPassword1', '$strUserLastIP')";
}

$strTempDBInfo = DBTYPE."_query";
$result = $strTempDBInfo($sql);

if (!$result)
{
$strTempDBInfo = DBTYPE."_error";
$strMessage = "Could not successfully run query ($sql) from DB: " . $strTempDBInfo($conn);
$boolError = true;
}
else
{
// If $strMessage is not empty and $boolError is false then it's just a Message.
// Otherwise, it's an Error Message.
if ($strAction == "Change Password")
{
$strMessage = "Password successfully changed.";
}

if ($strAction == "Create New User")
{
$strMessage = "User successfully added.";
}

$boolError = false;
}

$strTempDBInfo = DBTYPE."_close";
$strTempDBInfo($conn);
}

$_SESSION['message'] = $strMessage;
header("Location: options.php");
?>
  #8 (permalink)  
Antiguo 11/02/2014, 06:34
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

He subido varias de las clases iniciales, para que veais y compareis.
El problema es que no me registra ningun usuario ni me lo loguea.
Y no entiendo porque.
Trabajo con el phpmyadmin de hostinger para gestionar la base de datos.

Es un ejemplo que encontre en internet el codigo para ir modificandolo y aprendiendo a como se hace. Tiene licencia GNU.

Si alguien puede echarme una mano con el funcionamiento, o necesita algo, se lo subo gustosamente.

Un saludo.
  #9 (permalink)  
Antiguo 11/02/2014, 06:52
lolainas
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Proyecto web de Trivial

Código PHP:
require_once "config.php";

if (
strlen(trim($strSessionPath)) > 0)
    
session_save_path($strSessionPath);

session_start();

$boolError false;
$strAction "";
$strMessage "";
$strName "";
$strPassword1 "";
$strPassword2 "";
$strTempDBInfo "";

// Critical Error checking
if (empty($_SESSION)) {
    
$_SESSION['name'] = "";
    
$_SESSION['message'] = "You must log in to proceed.";
    
header("Location: index.php");
    exit;
}
else {
    
$strAction $_SESSION['action'];
}

// User Error checking
if (!empty($HTTP_POST_VARS['name'])) {
    
$strName $HTTP_POST_VARS['name'];
}
elseif (
$strAction == "Create New User") {
    
$strMessage "User was NOT created! You must specify a user. ";
    
$boolError true;
}

// boolError checks are in there own clause instead of merging them with the nested if statement.
// Otherwise, the error message of the real error will be overwritten by the last message in the
// last error check.
if (!$boolError) {
    if (!empty(
$HTTP_POST_VARS['password1'])) {
        
$strPassword1 $HTTP_POST_VARS['password1'];
    }
    else {
        
$strMessage "You must specify a password.";
        
$boolError true;
    }
}

if (!
$boolError) {
    if (!empty(
$HTTP_POST_VARS['password2'])) {
        
$strPassword2 $HTTP_POST_VARS['password2'];
    }
    else {
        
$strMessage "You must validate your password by typing it twice.";
        
$boolError true;
    }
}

// $boolError can be merged with if statements if there is no 'else' clause
if (!$boolError && ((strlen($strPassword1) < 4) || (strlen($strPassword1) > 32))) {
    
$strMessage "Change was NOT successful! Password must be no shorter than 4 characters and no longer than 32 characters.";
    
$boolError true;
}

if (!
$boolError && ($strPassword1 != $strPassword2)) {
    
$strMessage "Change was NOT successful! New password was not the same as the retyped password.";
    
$boolError true;
}

if (!
$boolError) {
    
$strTempDBInfo DBTYPE "_pconnect";
    
$conn $strTempDBInfo($DB_HOST$DB_USER$DB_PASS);

    if (!
$conn) {
        
$strTempDBInfo DBTYPE "_error";
        
$strMessage "Unable to connect to DB server: " $strTempDBInfo($conn);
        
$boolError true;
    }
    else {
        
$strTempDBInfo DBTYPE "_select_db";
    }
}

if (!
$boolError && (!$strTempDBInfo($DB_NAME))) {
    
$strTempDBInfo DBTYPE "_error";
    
$strMessage "Unable to select DB name: " $strTempDBInfo($conn);
    
$strTempDBInfo DBTYPE "_close";
    
$strTempDBInfo($conn);
    
$boolError true;
}

if (!
$boolError) {
    if (
$strAction == "Create New User") {
        
$sql "SELECT UserName FROM login WHERE UserName = '" $strName "'";
        
$strTempDBInfo DBTYPE "_query";
        
$result $strTempDBInfo($sql);

        if (!
$result) {
            
$strTempDBInfo DBTYPE "_error";
            
$strMessage "Could not successfully run query ($sql) from DB: " $strTempDBInfo($conn);
            
$boolError true;
        }
        else {
            
$strTempDBInfo DBTYPE "_num_rows";

            if (
$strTempDBInfo($result) != 0) {
                
$strMessage "This user already exists.";
                
$boolError true;
            }
        }
    }
}

if (!
$boolError) {
    if (
$strAction == "Change Password") {
        
$sql "UPDATE login SET UserPassword = '$strPassword1' " .
            
"WHERE UserName = '$strName'";
    }

    if (
$strAction == "Create New User") {
        
$strUserLastIP $_SERVER['REMOTE_ADDR'];
        
$sql "INSERT INTO login ( UserName, UserPassword, UserLastIP ) " .
            
"VALUES ('$strName', '$strPassword1', '$strUserLastIP')";
    }

    
$strTempDBInfo DBTYPE "_query";
    
$result $strTempDBInfo($sql);

    if (!
$result) {
        
$strTempDBInfo DBTYPE "_error";
        
$strMessage "Could not successfully run query ($sql) from DB: " $strTempDBInfo($conn);
        
$boolError true;
    }
    else {
// If $strMessage is not empty and $boolError is false then it's just a Message.
// Otherwise, it's an Error Message.
        
if ($strAction == "Change Password") {
            
$strMessage "Password successfully changed.";
        }

        if (
$strAction == "Create New User") {
            
$strMessage "User successfully added.";
        }

        
$boolError false;
    }

    
$strTempDBInfo DBTYPE "_close";
    
$strTempDBInfo($conn);
}

$_SESSION['message'] = $strMessage;
header("Location: options.php"); 
Perdon, es que si no se me cansa la vista (como al resto de usuario supongo), ahora le echaré un ojo...
  #10 (permalink)  
Antiguo 11/02/2014, 06:56
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

Gracias por editarlo para que sea mas claro, su lectura :)

Última edición por Yoshua9; 11/02/2014 a las 14:27
  #11 (permalink)  
Antiguo 25/02/2014, 07:41
 
Fecha de Ingreso: abril-2008
Mensajes: 33
Antigüedad: 16 años
Puntos: 0
Respuesta: Proyecto web de Trivial

¿Nadie puede darme una orientación sobre el tema este?

Etiquetas: proyecto, registro
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:56.