Hola, tengo una web de juegos, y quiero poner una pagina antes del juego, me explico
ahora tengo
listado de juego --> juego
y quiero que sea
listado de juego--> pagina antes del juego --> juego
en el listado juego tengo esto
Código PHP:
<?php session_start();
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
<?
include('lib/config.php');
include('lib/funciones.php');
?>
y asi lista a todos los post
<?
if(isset($_GET['pg']) && is_numeric($_GET['pg'])) {
$pg = $_GET['pg'];
} else {
$pg = 0;
}
$base= $dbname;
$con=mysql_connect($host,$dbuser,$dbpws);
mysql_select_db($base,$con);
$cantidad= 15; // cantidad de resultados por página
$inicial = $pg * $cantidad;
$ruta_url = "";
$pegar = "Select * from " . $dbname . ".db_juegos where fecha<='" . date("Y-m-d H:i:s") . "' order by fecha desc LIMIT $inicial,$cantidad";
$cad = mysql_query($pegar,$db) or die (mysql_error());
$contar="Select * from " . $dbname . ".db_juegos where fecha<='" . date("Y-m-d H:i:s") . "' order by fecha desc";
$contarok= mysql_query($contar,$db);
$total_records = mysql_num_rows($contarok);
$pages = intval($total_records / $cantidad);
while($juego=mysql_fetch_array($cad)) {
include('inc/inc.juego.listado.php');
} ?>
Estes es el enlace
<a href="<? echo txt('url.categorias');?>-<? echo categoria_url($juego['idcategoria']);?>/<? echo $juego['titulot'];?>.html"> jugar <a/>
Por .htaccess
Código PHP:
Rewriterule ^juegos-(.*)/(.*).html$ jugar.php?cat=$1&juego=$2 [L]
La url que da es dominio/juegos-categoria/nombre del juego
y en jugar.php tengo
Código PHP:
<?php session_start();
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
<?
include('lib/config.php');
include('lib/funciones.php');
include('lib/ktools.php');
//Almacenamos la busqueda
if(isset($_GET['q'])) {
ktool_almacena_busqueda($_GET['q']);
}
require('facebook/facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$user = $facebook->getUser();
if ($user)
{
try
{
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
$cat=var_segura($_GET['cat']);
$juego123=var_segura($_GET['juego']);
$strsqlcatjuego = "select * from " . $dbname . ".db_m_categorias where categoriat='" . $cat . "'";
$rscatjuego = mysql_query($strsqlcatjuego,$db);
$catjuego = mysql_fetch_array($rscatjuego);
//Sacamos los datos del juego seleccionado
$strsql = "select * from " . $dbname . ".db_juegos where titulot='" . $juego123 . "' and idcategoria=" . $catjuego['idcategoria'];
$rs = mysql_query($strsql,$db);
if(!($juego=mysql_fetch_array($rs))){
header("Location: /404.php");
}
$loginUrl='ingresar_facebook.php?retorno='.base64_encode(URL_total());
// if(visitaunica($_SERVER['REMOTE_ADDR'],"db_juegos_stats",$juego['idjuego'])==false) {
visita_juego($juego['idjuego']);
// }
$rutajuego = $config['url.base'] . txt('url.categorias') . "-" . categoria_url($juego['idcategoria']) . "/" . $juego['titulot'] .".html";
if ($user)//est� dentro
{
try
{
$uid=$user_profile['id'];
$fecha=date("Y-m-d");
$consulta="select * from " . $dbname . ".usuario_facebook WHERE uid=$uid";
$rs12 = mysql_query($consulta,$db);
$existe=mysql_num_rows($rs12);
if($existe==0)
{
$insertar="insert into " . $dbname . ".usuario_facebook (id, uid, fecha) values ('', '$uid', '$fecha')";
mysql_query($insertar,$db);
}
$id_juego=$juego['idjuego'];
if (!isset($_SESSION['publico']))
{
$_SESSION['publico']=2;
}
if ($_SESSION['publico']!=$id_juego)
{
$mensaje='Estoy jugando a '.$juego['titulo'].' a trav�s de http://localhost/juegos';
$facebook->api('/me/feed', 'post',
array(
'name' => 'juegos ',
'message' => $mensaje,
'link' => 'http://localhost/juegos/',
'picture' => 'http://localhost/juegos/css/img/muro.png',
'description'=> 'Juegos gratis '
));
$_SESSION['publico']=$id_juego;
}
$var_onload='cargajuego('.$juego['idjuego'].')';
}
catch(Exception $e)
{
}
}
else
{
$var_onload='controlTiempo()';
}
?>
Hasta hay todo correcto y sin problemas
He creado un archivo pre-jugar.php que esta de esta manera
Código PHP:
<?php session_start();
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
<?
require_once('lib/config.php');
require_once('lib/funciones.php');
$cat=var_segura($_GET['cat']);
$juego123=var_segura($_GET['juego']);
$strsqlcatjuego = "select * from " . $dbname . ".db_m_categorias where categoriat='" . $cat . "'";
$rscatjuego = mysql_query($strsqlcatjuego,$db);
$catjuego = mysql_fetch_array($rscatjuego);
//Sacamos los datos del juego seleccionado
$strsql = "select * from " . $dbname . ".db_juegos where titulot='" . $juego123 . "' and idcategoria=" . $catjuego['idcategoria'];
$rs = mysql_query($strsql,$db);
if(!($juego=mysql_fetch_array($rs))){
header("Location: /404.php");
}
y cambie en .htaccess
Código PHP:
Rewriterule ^juegos-(.*)/(.*).html$ pre-jugar.php?cat=$1&juego=$2 [L]
url La url que da es dominio/juegos-categoria/nombre del juego
me muestra los datos del juego y no da ningun error,
¿Como hago para pasarlo a la pagina juego.php?
esta es algun ejemplo de lo que he ido probando, pero sin conseguir nada
Código PHP:
<a href="jugar-<? echo categoria_url($juego['idcategoria']);?>/<? echo $juego['titulot'];?>.html"> jugar <a/>
Rewriterule ^jugar(.*)/(.*).html$ jugar.php?cat=$1&juego=$2 [L]
me da estos errores
Notice: Undefined index: cat in C:\xampp\htdocs\juegos\jugar.php on line 30
Código PHP:
$cat=var_segura($_GET['cat']);
Notice: Undefined index: juego in C:\xampp\htdocs\juegos\jugar.php on line 31
Código PHP:
$juego123=var_segura($_GET['juego']);
Notice: Undefined variable: juego in C:\xampp\htdocs\juegos\jugar.php on line 43
Código PHP:
$rscatjuego = mysql_query($strsqlcatjuego,$db);
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\juegos\lib\funciones.php on line 160
Esta es la funcion
Código PHP:
function sumavisita_juego($id) {
include ('lib/config.php');
$dbfunc = mysql_connect($host,$dbuser,$dbpws);
$strsql = "Select * from " . $dbname . ".db_juegos where idjuego=" . $id;
$rsfunc = mysql_query($strsql,$dbfunc);
if($lignefunc = mysql_fetch_array ($rsfunc)){
//Sacamos el numero de visitas y le sumamos una mas
$visitas = $lignefunc['visitas']+1;
$strsqlfunc = "update " . $dbname . ".db_juegos set visitas=" . $visitas . " where idjuego=" . $id;
$rsfunc = mysql_query($strsqlfunc,$dbfunc);
}
}
Notice: Undefined variable: juego in C:\xampp\htdocs\juegos\jugar.php on line 46
Código PHP:
visita_juego($juego['idjuego']);
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\juegos\lib\funciones.php on line 100
Esta es la funcion
Código PHP:
function categoria_url($idcategoria){
include ('lib/config.php');
$dbfunc = mysql_connect($host,$dbuser,$dbpws);
$strsqlfunc = "select * from ". $dbname .".db_m_categorias where idcategoria=" . $idcategoria;
$rsfunc = mysql_query($strsqlfunc,$dbfunc);
if($lignefunc = mysql_fetch_array ($rsfunc)) {
return $lignefunc['categoriat'];
} else {
return "N/A";
}
}
¿Donde puede estar el fallo?
Muchas gracias