

<style>

fieldset {
    display: block;
    margin-left: 200px;
    margin-right: 200px;
    padding-top: 0.35em;
    padding-bottom: 0.625em;
    padding-left: 0.75em;
    padding-right: 0.75em;
    border: 2px groove (internal value);
}

</style>

<?php
ini_set('display_errors', 1);
$user_key = 'only_for_dev_or_pro';
$endpoint = 'https://api.upcitemdb.com/prod/trial/lookup';

		if(isset($_POST['Submit']))
		{

			if (empty($_POST["upc"])) 
			{
				echo "Champ vide !.";
			} 
			
			else {

						$ch = curl_init();

						curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
						curl_setopt($ch, CURLOPT_HEADER, 1);
						curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
						curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
						curl_setopt($ch, CURLOPT_HEADER, false);
						curl_setopt($ch, CURLOPT_HTTPHEADER, array(

						));

						
						$upc = $_POST["upc"];	
						$cmd = "https://api.upcitemdb.com/prod/trial/lookup?upc=" .$upc;	
						
						
						curl_setopt($ch, CURLOPT_POST, 0);
						
						//curl_setopt($ch, CURLOPT_URL, $endpoint.'?upc=4002293401102');
						curl_setopt($ch, CURLOPT_URL, $cmd);
						
						
						$response = curl_exec($ch);
						$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
						if ($httpcode != 200)
						  echo "error status $httpcode...\n";
						else 
						//  echo $response."\n";

						/* if you need to run more queries, do them in the same connection.
						* use rawurlencode() instead of URLEncode(), if you set search string
						 * as url query param
						 */
						sleep(2);
						// proceed with other queries
						curl_close($ch);

						$result=json_decode($response,true);
						echo $title=$result['items'][0]["title"];
						echo "<br>";
						echo $title=$result['items'][0]["brand"];
						
				}
			}			

			
?>
			<fieldset>
			<legend> Recherche un produits à partir du code bar : </legend>

			<br><br>
			
			<form action="ean04.php" method="post">
			Code bar: <input type='text' name='upc' size='20'>
			<input type='submit' name='Submit' value='Submit'>
			</form>
			
			</fieldset>
