Ayuda para subir y editar código PHP en 000webhost.com

  • Autor Autor thejigg0695
  • Fecha de inicio Fecha de inicio
T

thejigg0695

Dseda
Redactor
Hola quisiera que alguien me dijiera como subir y editarlo con mis datos a 000webhost.com, es un contador de visitas por post de blogger.

Insertar CODE, HTML o PHP:
<?php

//Created by Anuj Pathania --- anujpathania#gmail.com. Please Feel Free to mail me if you want any help, script has a bug or just wanna say Hi. :D

//This code is released under GPL (General Public License).

/*
You need to create a database and table to store data first, please do so by executing this command in phpmyadmin first but make sure you change database and table name --

 CREATE TABLE `YOUR-COUNTER-DATABASE`.`YOUR-COUNTER-TABLE` (
`SN` BIGINT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 1000 ) NOT NULL ,
`hit` BIGINT NOT NULL DEFAULT '1',
PRIMARY KEY ( `SN` )
) ENGINE = MYISAM 

*/
	Header("content-type: application/x-javascript");
	$url = getenv("HTTP_REFERER");
	$url = str_replace ("http://",'',$url);
	$url = str_replace ("www.",'',$url);
    if ($url != "")
		{
			$username = "YOUR-USERNAME"; // Enter Your Username and Password Here
			$password = 'YOUR-PASSWORD'; // Enter Your Username and Password Here
			$database = 'YOUR-COUNTER-DATABASE';  //Enter Your Database Name Here
			$table = "YOUR-COUNTER-TABLE"; //Enter Your Counter Table Name Here
			
			
			$link = mysql_connect('localhost', $username, $password); 
			if (!$link) 
			{
    			die('Could not connect: ' . mysql_error());
			}
			$db_selected = mysql_select_db($database, $link); 
			if (!$db_selected) 
			{
    			die ('Cann\'t select database : ' . mysql_error());
			}
			$query = "Select hit from $table where name = '$url'"; 
			$result = mysql_query($query);
			if (!$result) 
			{
    			die('Invalid query: ' . mysql_error());
			}
			if (mysql_affected_rows()==0)
			{
				$query = "Insert into counter (name) values ('$url')";
				$result = mysql_query($query);
				echo "document.write('1');";
				if (!$result) 
				{
    				die('Invalid query: ' . mysql_error());
				}
			}
			else
			{
				$hitcount = mysql_result($result, 0);
				$hitcount++;
				echo "document.write('$hitcount');";
				$query = "Update counter set hit = $hitcount where name = '$url'";
				$result = mysql_query($query);
				if (!$result) 
				{
    				die('Invalid query: ' . mysql_error());
				}
			}
		}
		mysql_close($link);
?>
 
Facil , ve a tu base de datos y crea una nueva tabla y llamala counter

agrega 3 campos
1.- id INT(11) primary key not null auto increment,
2.- hit varchar 250 not null, -- en este campo me parece que puede ser INT pero solo le heche un vistazo a tu codigo.
3.- name varchar 255 not null

Y ahora en tu codigo configura tu conexion mysql y en la parte $table = "YOUR-COUNTER-TABLE" , ingresas $table = "counter";

Por cierto como dato adicional el script tiene un pequeño error ya que la variable $table no funciona en todas las peticiones porque en un UPDATE pone que la tabla se llama counter , cuando deberia ser $table, para llamar al nombre de tu tabla elegida como contador, de ahi surge que crees una tabla que se llame counter para que no obtengas ningun error :3.

Un saludo
 
soy novato nose nada de codigo php :fatigue: tienes un mp
alguien que me quiera explicar con manzanitas y palitos :welcoming: estoy dispuesto a pagar :encouragement:
 
Atrás
Arriba