how can i create a proxy.php to connect to database?

30 views
Skip to first unread message

rim...@gmail.com

unread,
Apr 24, 2017, 11:16:22 AM4/24/17
to Popotojs alpha
hi 
how can i create a proxy.php to connect to database?

Frederic Ciminera

unread,
Jan 11, 2018, 8:26:50 AM1/11/18
to Popotojs alpha
Hi,

The idea is to add a proxy on the neo4j REST API containing the database credentials.
You can do something like this in php:

<?php
// Customize headers to allow the query
header
("Access-Control-Allow-Origin: *");
header
("Access-Control-Allow-Headers: content-type");
header
("Content-Type: application/json");

$method
= $_SERVER['REQUEST_METHOD'];

if ($method == 'POST') {
 
// Get the json query data
 $request_body
= file_get_contents('php://input');

 $protocol
= 'https';
 $host
= 'your.neo4j.host';
 $port
= '7474';
 $curlQuery
= curl_init($protocol . '://' . $host . ':' . $port . '/db/data/transaction/commit');

 curl_setopt
($curlQuery, CURLOPT_CUSTOMREQUEST, "POST");
 curl_setopt
($curlQuery, CURLOPT_POSTFIELDS, $request_body);
 curl_setopt
($curlQuery, CURLOPT_RETURNTRANSFER, true);
 curl_setopt
($curlQuery, CURLOPT_HTTPHEADER, array(
 
'Content-Type: application/json',
 
'Authorization: Basic base64EncodedUser:Password' // For example Base64 encoded value of "neo4j:password" is "bmVvNGo6cGFzc3dvcmQ="
 
)
 
);

 echo curl_exec
($curlQuery);
}


Reply all
Reply to author
Forward
0 new messages