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

Servicio SOAP PHP

Tanto para el servidor como para el cliente se utiliza la libreria nusoap.

El php servidor seria asi:


require_once("lib/nusoap.php");

function getMetodo1($parametro1,$parametro2){

$res = array(array('id' => '1', 'nombre' => 'nombre1'),
array('id' => '2', 'nombre' => 'nombre2'));

return $res;

}


$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server = new soap_server;
$server->configureWSDL('items', 'urn:'.$_SERVER['SCRIPT_URI']);
$server->wsdl->addComplexType(
'Item',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name' => 'id', 'type' => 'xsd:string'),
'nombre' => array('name' => 'nombre', 'type' => 'xsd:string'),
)
);

$server->wsdl->addComplexType(
'ItemArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Item[]')
),
'tns:Item'
);

$server->register('getMetodo1',
array('parametro1' => 'xsd:string', 'parametro2' => 'xsd:string'), // input parameters
array('return' => 'tns:ItemArray'),
'urn:'.$_SERVER['SCRIPT_URI'], // namespace
'urn:'.$_SERVER['SCRIPT_URI']."#getMetodo1", // soapaction
'rpc', // style
'encoded', // use
'Documentacion sobre el servicio'); // documentation

#$server->wsdl->schemaTargetNamespace = $_SERVER['SCRIPT_URI'];
$server->service($HTTP_RAW_POST_DATA);
exit();


El php cliente:

require_once('lib/nusoap.php');
$soapclient = new nusoap_client('http://84.124.186.232/Biblioteca/ServiciosWeb/1server1.php');
$result = $soapclient->call( 'getMetodo1' , array('parametro1' => 'valorParametro1','parametro2' => 'valorParametro2'));
print_r($result);
//echo($soapclient->request);
echo($soapclient->response);
//echo($soapclient->debug_str);

Crear carpeta PHP

$nombre_carpeta = "nueva carpeta";

if(!is_dir($nombre_carpeta))
{
@mkdir($nombre_carpeta, 0755);
echo("creada carpeta ".$nombre_carpeta);
}
else
{
echo "Ya existe ese directorio\n";
}

Enviar POST PHP

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "pasametro1=valor1¶metro2=valor");
curl_exec ($ch);
curl_close ($ch)

Leer variables POST

foreach($_POST as $nombre_campo => $valor){
$asignacion = $nombre_campo . " => " . $valor . "
";
eval($asignacion);
echo($asignacion);
}

Leer HTML con PHP

$lines = file('http://itunes.apple.com/es/genre/mobile-software-applications/id6015?mt=8');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #{$line_num} : " . htmlspecialchars($line) . "
\n";
}

Parar variables entre paginas PHP


- Se puede pasar directamente en el url de la nueva dirección:


echo "<input name='BcitaPM' type='button' value='PEDIR' onclick='window.location=\"Cita.php?a=$a&b=$b&c=$c&d=$d&e=$e\"'>";



- Puedes usar sesiones. Las variables que declares de sesión podras usarlas en cualquier página que esté dentro de la sesión sin pasarlas en el url:


principal.php

<?php

session_start();

$_SESSION['a'] = "Valor de a";

$_SESSION['b'] = "Valor de b";

$_SESSION['c'] = "Valor de c";

$_SESSION['d'] = "Valor de d";

$_SESSION['e'] = "Valor de e";


?>

<form name='formulario' method='POST' action='Cita.php'>

<input name='BcitaPM' type='submit' value='PEDIR'>

</form>



Cita.php

<?php

session_start();

echo $_SESSION['a'] ."<br>";

echo $_SESSION['b'] ."<br>";

echo $_SESSION['c'] ."<br>";

echo $_SESSION['d'] ."<br>";

echo $_SESSION['e'] ."<br>";

?>


Form PHP

Link

Sending a username and password with PHP CURL

CURL and PHP combined can be really useful for getting data from websites, connecting to APIs (such as the Google Analytics API) and so on. Sometimes you may need to connect to a website that is password protected so this post looks at how to pass the username and password with PHP and CURL


If the following example, $url is the url to connect to and $username and $password contain your authorization details:

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); 

The "curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);" line is not actually necessary but it means the HTML from the web page returned goes into the $output variable rather than echoed out to standard output.

Likewise you don't necessarily need to do "$info = curl_getinfo($ch);" but it does contain useful information about the HTTP status and so on. Doing print_r($info) from the above example on the script I used for writing and testing this post outputs the following:

Array (     [url] => http://www.testing.local/auth/     [content_type] => text/html;charset=UTF-8     [http_code] => 200     [header_size] => 208     [request_size] => 100     [filetime] => -1     [ssl_verify_result] => 0     [redirect_count] => 0     [total_time] => 0.022493     [namelookup_time] => 0.000279     [connect_time] => 0.000475     [pretransfer_time] => 0.000487     [size_upload] => 0     [size_download] => 732     [speed_download] => 32543     [speed_upload] => 0     [download_content_length] => 732     [upload_content_length] => 0     [starttransfer_time] => 0.022389     [redirect_time] => 0 ) 

Getting the http_code from the information is useful so you know if it successfully connected to the page before parsing any of the return data.


Fuente

Extraer contenido web PHP