Foros del Web » Programando para Internet » PHP »

Ayuda-script de acortador

Estas en el tema de Ayuda-script de acortador en el foro de PHP en Foros del Web. La verdad soy nuevo en este foro. a decir verdad descargue un script desde internet para agregarlo como acortador de urls cuando genero mi URL ...
  #1 (permalink)  
Antiguo 05/04/2011, 16:18
 
Fecha de Ingreso: abril-2011
Mensajes: 2
Antigüedad: 13 años
Puntos: 0
Pregunta Ayuda-script de acortador

La verdad soy nuevo en este foro.
a decir verdad descargue un script desde internet para agregarlo como acortador de urls cuando genero mi URL e mando tres errores y no genera nada, solo si me pudieran ayudar se los agradeceria.
los errores son:
Código:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ...\includes\hjurl.php on line 19

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ...\includes\hjurl.php on line 73

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ...\includes\hjurl.php on line 123
el codigo es:

Código PHP:
<?php /* index.php ( lilURL implementation ) */

require_once 'includes/conf.php'// <- site-specific settings
require_once 'includes/hjurl.php'// <- lilURL class file

$lilurl = new lilURL();
$msg '';

// if the form has been submitted
if ( isset($_POST['longurl']) )
{
    
// escape bad characters from the user's url
    
$longurl trim(mysql_escape_string($_POST['longurl']));

    
// set the protocol to not ok by default
    
$protocol_ok false;
    
    
// if there's a list of allowed protocols, 
    // check to make sure that the user's url uses one of them
    
if ( count($allowed_protocols) )
    {
        foreach ( 
$allowed_protocols as $ap )
        {
            if ( 
strtolower(substr($longurl0strlen($ap))) == strtolower($ap) )
            {
                
$protocol_ok true;
                break;
            }
        }
    }
    else 
// if there's no protocol list, screw all that
    
{
        
$protocol_ok true;
    }
        
    
// add the url to the database
    
if ( $protocol_ok && $lilurl->add_url($longurl) )
    {
        if ( 
REWRITE // mod_rewrite style link
        
{
            
$url 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/'.$lilurl->get_id($longurl);
        }
        else 
// regular GET style link
        
{
            
$url 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?id='.$lilurl->get_id($longurl);
        }

        
$msg '<p class="success">URL is: <a href="'.$url.'">'.$url.'</a></p>';
    }
    elseif ( !
$protocol_ok )
    {
        
$msg '<p class="error">Invalid protocol!</p>';
    }
    else
    {
        
$msg '<p class="error">Creation of your lil´ URL failed for some reason.</p>';
    }
}
else 
// if the form hasn't been submitted, look for an id to redirect to
{
    if ( isSet(
$_GET['id']) ) // check GET first
    
{
        
$id mysql_escape_string($_GET['id']);
    }
    elseif ( 
REWRITE // check the URI if we're using mod_rewrite
    
{
        
$explodo explode('/'$_SERVER['REQUEST_URI']);
        
$id mysql_escape_string($explodo[count($explodo)-1]);
    }
    else 
// otherwise, just make it empty
    
{
        
$id '';
    }
    
    
// if the id isn't empty and it's not this file, redirect to it's url
    
if ( $id != '' && $id != basename($_SERVER['PHP_SELF']) )
    {
        
$location $lilurl->get_url($id);
        
        if ( 
$location != -)
        {
            
header('Location: '.$location);
        }
        else
        {
            
$msg '<p class="error">Sorry, but that lil´ URL isn\'t in our database.</p>';
        }
    }
}

// print the form

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

    <head>
        <title>RealGamez | Acortador Oficial</title>
        
        <style type="text/css">
        body {
            font: .8em "Trebuchet MS", Verdana, Arial, Sans-Serif;
            text-align: center;
            color: #333;
            background-color: #fff;
            margin-top: 5em;
        }
        
        h1 {
            font-size: 2em;
            padding: 0;
            margin: 0;
        }

        h4 {
            font-size: 1em;
            font-weight: bold;
        }
        
        form {
            width: 28em;
            background-color: #eee;
            border: 1px solid #ccc;
            margin-left: auto;
            margin-right: auto;
            padding: 1em;
        }

        fieldset {
            border: 0;
            margin: 0;
            padding: 0;
        }
        
        a {
            color: #09c;
            text-decoration: none;
            font-weight: bold;
        }

        a:visited {
            color: #07a;
        }

        a:hover {
            color: #c30;
        }

        .error, .success {
            font-size: 1.2em;
            font-weight: bold;
        }
        
        .error {
            color: #ff0000;
        }
        
        .success {
            color: #000;
        }
        
        </style>

    </head>
    
    <body onload="document.getElementById('longurl').focus()">
        
        <h1>RealGamez | Acortador Oficial</h1>
        
        <?php echo $msg?>
        
        <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
        
            <fieldset>
                <label for="longurl">Introdusca link:</label>
                <input type="text" name="longurl" id="longurl" />
                <input type="submit" name="submit" id="submit" value="Crear Link!" />
            </fieldset>
        
        </form>

        <h4>Created by <a href="#">Daeck!</a></h4>
    
    </body>

</html>

AYUDA...°°°!!!!!1
  #2 (permalink)  
Antiguo 05/04/2011, 16:22
 
Fecha de Ingreso: noviembre-2009
Mensajes: 226
Antigüedad: 14 años, 5 meses
Puntos: 19
Respuesta: Ayuda-script de acortador

El error te da en hjurl.php, no en el script que has colgado.

Un saludo
__________________
Mi blog: magdkudama.com

Mi clase de validación de datos: magdkudama.com/validation
  #3 (permalink)  
Antiguo 05/04/2011, 16:27
 
Fecha de Ingreso: abril-2011
Mensajes: 2
Antigüedad: 13 años
Puntos: 0
Respuesta: Ayuda-script de acortador

Cita:
Iniciado por GrupoC Ver Mensaje
El error te da en hjurl.php, no en el script que has colgado.

Un saludo
aqui agrego el codigo de hjurl.php
Código PHP:
<?php /* lilurl.php ( lilURL class file ) */

class lilURL
{
    
// constructor
    
function lilURL()
    {
        
// open mysql connection
        
mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_PASS) or die('Could not connect to database');
        
mysql_select_db(MYSQL_DB) or die('Could not select database');    
    }

    
// return the id for a given url (or -1 if the url doesn't exist)
    
function get_id($url)
    {
        
$q 'SELECT id FROM '.URL_TABLE.' WHERE (url="'.$url.'")';
        
$result mysql_query($q);

        if ( 
mysql_num_rows($result) )
        {
            
$row mysql_fetch_array($result);
            return 
$row['id'];
        }
        else
        {
            return -
1;
        }
    }

    
// return the url for a given id (or -1 if the id doesn't exist)
    
function get_url($id)
    {
        
$q 'SELECT url FROM '.URL_TABLE.' WHERE (id="'.$id.'")';
        
$result mysql_query($q);

        if ( 
mysql_num_rows($result) )
        {
            
$row mysql_fetch_array($result);
            return 
$row['url'];
        }
        else
        {
            return -
1;
        }
    }
    
    
// add a url to the database
    
function add_url($url)
    {
        
// check to see if the url's already in there
        
$id $this->get_id($url);
        
        
// if it is, return true
        
if ( $id != -)
        {
            return 
true;
        }
        else 
// otherwise, put it in
        
{
            
$id $this->get_next_id($this->get_last_id());
            
$q 'INSERT INTO '.URL_TABLE.' (id, url, date) VALUES ("'.$id.'", "'.$url.'", NOW())';

            return 
mysql_query($q);
        }
    }

    
// return the most recent id (or -1 if no ids exist)
    
function get_last_id()
    {    
        
$q 'SELECT id FROM '.URL_TABLE.' ORDER BY date DESC LIMIT 1';
        
$result mysql_query($q);

        if ( 
mysql_num_rows($result ) )
        {
            
$row mysql_fetch_array($result);
            return 
$row['id'];
        }
        else
        {
            return -
1;
        }
    }    

    
// return the next id
    
function get_next_id($last_id)
    { 
    
        
// if the last id is -1 (non-existant), start at the begining with 0
        
if ( $last_id == -)
        {
            
$next_id 0;
        }
        else
        {
            
// loop through the id string until we find a character to increment
            
for ( $x 1$x <= strlen($last_id); $x++ )
            {
                
$pos strlen($last_id) - $x;

                if ( 
$last_id[$pos] != 'z' )
                {
                    
$next_id $this->increment_id($last_id$pos);
                    break; 
// <- kill the for loop once we've found our char
                
}
            }

            
// if every character was already at its max value (z),
            // append another character to the string
            
if ( !isSet($next_id) )
            {
                
$next_id $this->append_id($last_id);
            }
        }

        
// check to see if the $next_id we made already exists, and if it does, 
        // loop the function until we find one that doesn't
        //
        // (this is basically a failsafe to get around the potential dangers of
        //  my kludgey use of a timestamp to pick the most recent id)
        
$q 'SELECT id FROM '.URL_TABLE.' WHERE (id="'.$next_id.'")';
        
$result mysql_query($q);
        
        if ( 
mysql_num_rows($result) )
        {
            
$next_id $this->get_next_id($next_id);
        }

        return 
$next_id;
    }

    
// make every character in the string 0, and then add an additional 0 to that
    
function append_id($id)
    {
        for ( 
$x 0$x strlen($id); $x++ )
        {
            
$id[$x] = 0;
        }

        
$id .= 0;

        return 
$id;
    }

    
// increment a character to the next alphanumeric value and return the modified id
    
function increment_id($id$pos)
    {        
        
$char $id[$pos];
        
        
// add 1 to numeric values
        
if ( is_numeric($char) )
        {
            if ( 
$char )
            {
                
$new_char $char 1;
            }
            else 
// if we're at 9, it's time to move to the alphabet
            
{
                
$new_char 'a';
            }
        }
        else 
// move it up the alphabet
        
{
            
$new_char chr(ord($char) + 1);
        }

        
$id[$pos] = $new_char;
        
        
// set all characters after the one we're modifying to 0
        
if ( $pos != (strlen($id) - 1) )
        {
            for ( 
$x = ($pos 1); $x strlen($id); $x++ )
            {
                
$id[$x] = 0;
            }
        }

        return 
$id;
    }

}

?>
  #4 (permalink)  
Antiguo 05/04/2011, 21:54
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Ayuda-script de acortador

El problema es que mysql_query() esta devolviendo falso porque la consulta no se ejecuto correctamente, para saber de que se trata (aunque yo creo que es porque la tabla no existe o la constante URL_TABLE no esta definida):

$result = mysql_query('aqui tu consulta') or die('Error en la consulta: ' . mysql_error());
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: acortador
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 13:59.