Mostrando entradas con la etiqueta PHP. Mostrar todas las entradas
Mostrando entradas con la etiqueta PHP. Mostrar todas las entradas

jueves, 27 de septiembre de 2012

PHP: ip 2 country json

<?php 

$ip = $_SERVER['REMOTE_ADDR'];
$json = file_get_contents("http://api.easyjquery.com/ips/?ip=".$ip."&full=true");
$json = json_decode($json,true);

echo "
<pre>";
print_r($json);

?>

url:
http://www.easyjquery.com/detect-get-clients-ip-address-country-using-javascript-php/

otra forma:
http://freegeoip.appspot.com/

martes, 17 de julio de 2012

PHP y MySQLi: conexion con mysqli y manejo de errores

<?php
include "db.php";
$conexion = new mysqli($MYSQL_HOST, $MYSQL_LOGIN, $MYSQL_PASS, $MYSQL_DB);

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$result = $conexion->query("select * from users");
echo "Num de filas al iniciar: ".$result->num_rows. "</br>";

while($row = $result->fetch_array(MYSQLI_ASSOC)){
    echo $row['name']." ";
}

echo "<hr>";

$conexion->autocommit(false);

try{

    $result = $conexion->query("INSERT INTO users (name, email) VALUES ('ambro', 'un email');");
        if(!$result) throw new Exception($conexion->error);
        
    echo "id usuario nuevo: ".$conexion->insert_id; //si
    echo "<hr>";

    $result = $conexion->query("INSERT INTO users_comments (id_user, TEXT) VALUES ({$conexion->insert_id}, 'un comentario del user {$conexion->insert_id}');");
        if(!$result) throw new Exception($conexion->error);

    echo "id comentario nuevo: ".$conexion->insert_id; //si
    echo "<hr>";

    $result = $conexion->query("INSERT INTO users_comments (id_user, TEXT) VALUES (85, 'un comentario del user asd');");
        if(!$result) throw new Exception($conexion->error);
            //throw new SqlException( mysqli_error( $connection ) );
        
    $conexion->commit();

}
catch(Exception $e){
    $conexion->rollback();
    die("error lo agarra el catch: <br>".$e->getMessage() );
}

?>

jueves, 28 de junio de 2012

PHP: logueo con LDAP

<?php

function authLDAP($username, $password){
    $ldap_domain = 'midominio';

    $adServer = "miservidor";
    $ldapconn = ldap_connect($adServer) or die("Could not connect to LDAP server.");

    $ldaprdn = $username;    

    # Descomentar si la App corre bajo Apache2 sobre Windows Server
    #ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3)

    $ldapbind = ldap_bind($ldapconn, "$ldaprdn@$ldap_domain", $password);

    if($ldapbind)
        return true;
    else
        return false;
}

authLDAP("sad", "asd");

?>

sábado, 31 de marzo de 2012

PHP: leer excel desde php con libreria PHPExcelReader

<?php
set_time_limit(0);
require_once 'Excel/reader.php';
 
$data = new Spreadsheet_Excel_Reader();
 
// $data->setOutputEncoding('CP1251');
 
$data->read('alumno_notas.xls');
 
$filas = $data->sheets[0]['cells']; //[fila][columna].

// echo count($filas);
// echo "<br>";
// echo $filas[1][1];

for($z=1; $z<count($filas); $z++)
{
    echo $filas[$z][1]."<br>";
}
?>

miércoles, 14 de marzo de 2012

PHP: Imprimir etiquetas con formato para impresora datamax

<?
// error_reporting(E_ALL);
set_time_limit(999);

include "class.ezpdf.php"; //rck manual: http://www.ros.co.nz/pdf/readme.pdf

// $pdf =& new Cezpdf('a4');
$pdf =& new Cezpdf($paper=array(0,0,(118.00 * 72 / 25.4 ), (25.00 * 72 / 25.4 )), $orientation='portrait');

    $pdf->ez['topMargin']=1;
    $pdf->ez['bottomMargin']=1;
    $pdf->ez['leftMargin']=5;
    $pdf->ez['rightMargin']=5;

$pdf->selectFont('fonts/php_times-told.afm');


for ($i=0; $i<count($res); $i++)
{
    $pdf->addText($x=15,$y=50,$size=6,$text= "Defensoria General de la Nación");
    $pdf->addText($x=15,$y=44,$size=6,$text= $res[$i]["DescTipoEquipo"]);

    $pdf->addText($x=195,$y=50,$size=6,$text= "Defensoria General de la Nación");
    $pdf->addText($x=195,$y=44,$size=6,$text= $res[$i]["DescTipoEquipo"]);


    $imagen = "http://".$_SERVER["HTTP_HOST"].STRROOTNAME."/genera_barras_rck.php?code=".$res[$i]['BienUso'];
    $img = ImageCreatefromjpeg($imagen);

    $pdf-> addImage($img,$x=15,$y= 14, $w=116, $h=28, $quality=75);
    $pdf-> addImage($img,$x=195,$y= 14, $w=116, $h=28, $quality=75);
    
    if($i<count($res)-1)$pdf->ezNewPage();
}

ob_end_clean();
$pdf->ezStream();
?>

viernes, 9 de marzo de 2012

PHP: Insertar Imagen Dinamica en un PDF

<?php
for ($i=0; $i<count($res); $i++) {

    $data[] = array('num'=>$text.$res[$i]["DescTipoEquipo"].$br,'nada'=>" ", 'mes'=>$text.$res[$i]["DescTipoEquipo"].$br);

    $imagen = "http://".$_SERVER["HTTP_HOST"].STRROOTNAME."/genera_barras_rck.php?code=".$res[$i]['BienCode'];

    $img = ImageCreatefromjpeg($imagen); //obtiene la imagen generada por el PHP

    $pdf-> addImage($img,$x=96,$y= $pdf->y - (86 + $i*108), $w=150, $h=0, $quality=75);
    $pdf-> addImage($img,$x=350,$y= $pdf->y - (86 + $i*108), $w=150, $h=0, $quality=75);
    
}
?>

PHP: Generar PDF desde PHP con imagenes Libreria ROS

Site Oficial de la libreria R&OS: http://www.ros.co.nz/pdf/

El uso es muy simple lo pueden ver en http://blog.unijimpe.net/generar-pdf-con-php/

lo que quedo muy corto es la inclusion de imagenes que tambien es simple y aca muestro 3 maneras de hacerlo.

<?php
error_reporting(E_ALL);
set_time_limit(0);

include "class.ezpdf.php";

$pdf->ezImage($image="ros.jpg", $pad = 0,$width = 200,$resize = 'none',$just = 'left',$border = '');
/* This function makes it much easier to simply place an image (either jpeg or png) within the flow of
text within a documen
*/

$pdf->addImage($img="ros.jpg",$x=80,$y=0,$w=200,$h=0,$quality=75);
/* Add an image to the document, this feature needs some development. But as it stands, img must be a
handle to a GD graphics object, and one or both of w or h must be specified, if only one of them is
specified, then the other is calculated by keeping the ratio of the height and width of the image
constant.
The image will be placed with its lower left corner at (x,y), and w and h refer to page units, not pixels.
*/

$pdf->addJpegFromFile($img = 'ros.jpg',$x=199, $y= $pdf->y-100 ,$w=200,$h=0);

/* Add a JPEG image to the document, this function does not require the GD functionality, so should be
usable to more people, interestingly it also seems to
be more reliable and better quality. The syntax of the command is similar to the above 'addImage'
function, though 'img' is a string containing the file name of the jpeg image.
x,y are the position of the lower left corner of the image, and w,h are the width and height. Note that
the resolution of the image in the document is defined only by the resolution of the image that you
insert, and the size that you make it on the page. If you have an image which is 500 pixels across and
then you place it on the page so that it is 72 units across then this image will be about 500 dpi (as 72
units is about 72 points which is 1 inch)
*/


ob_end_clean(); //IMPORTANTE!!
$pdf->ezStream();
?>

viernes, 1 de octubre de 2010

jQuery: jSon

<script type="text/javascript">
$(document).ready(function () {

var query = "SELECT * FROM tbl_users WHERE user_id = 3";

$.getJSON("query_executor.php", { query: query}, function(data){
alert("user_name: " + data[0].user_name);

});
});
</script>


O
var html = $.ajax({
type: "GET",
url: "php_ajax/query_executor.php",
data: "query=" + query,
async: false
}).responseText;

var myObject = eval('(' + html + ')');

alert(var_dump_rck(myObject[0]));



El PHP
<?php
include("db.php");
    
$query = $_REQUEST['query'];
$result = mysql_query($query) or trigger_error(mysql_error());

$jsonArr = array();
while($row = mysql_fetch_object($result))
{
    $jsonArr[] = $row;
}

echo json_encode($jsonArr);

?>

El Json Generado

[
{"user_id":"1","user_name":"pepe","user_fecha_nacimiento":"1986-09-01"},
{"user_id":"2","user_name":"juan","user_fecha_nacimiento":"1988-12-05"},
{"user_id":"3","user_name":"Ambrosio Romero","user_fecha_nacimiento":"1984-05-12"}
]