Hello you guys,
I've with a problem, I hope you guys can help me.
I need, from server b, to connect to server a, over the internet, to be able
to open a .txt file and make it a copy to insert line by line inside server
b, the problem, is that I need to make sure the user from server b, is
someone ok, what I mean is, there's a table inside server a, and the user
from server b, to be able to open the file, must be in that table in server
a, to be able to login, but I'm not sure how to connect to server a from
server b, make a verification in the database from server a, and allow the
user to open the file, copy it, and insert into server b database.
So far I can from server b, open the file in server a, copy it, and insert
line by line in server's b database, here's the, I hope you guys can help
me:
/*************** *************** *************
* Function cached_fopen_ur l():
* Caches data from a HTTP resource/url to a
* local file (HTTP headers are stripped)
*************** *************** *************/
function cached_fopen_ur l($url, $file_mode, $timeout_second s = 90,
$cache_path, $fsocket_timeou t = 10, $name_db, $host_db, $user_db, $pass_db){
$debug = FALSE;
clearstatcache( );
//$cache_filename =$cache_path . "/" . urlencode($url) .".cached";
$cache_filename = $cache_path."pr oxylist.txt";
if($debug){
print "local_cach e creation_time =" .
@filemtime($cac he_filename) .
" actual time = " . time() .
" timeout = " .
timeout_seconds ."<p>";
}
//if ( ( @file_exists($c ache_filename ) and ( (
@filemtime($cac he_filename) + $timeout_second s) > ( time() ) ) ) ) {
if ( ( @filemtime($cac he_filename) + $timeout_second s) > ( time() ) ) {
// ok, file is already cached and young enouth
if ($debug) { print "using cached file ($cache_filenam e) <p>";}
} else {
if ($debug) {
print "caching file ($url) to local ($cache_filenam e)<p>";
}
$urlParts = parse_url($url) ;
$host = $urlParts['host'];
$port = (isset($urlPart s['port'])) ? $urlParts['port'] : 80;
if( !$fp = @fsockopen( $host, $port, $errno, $errstr,
$fsocket_timeou t )) {
// Server not responding
} else {
if( !fputs( $fp, "GET $url HTTP/1.0\r\nHost:$ho st\r\n\r\n" ) ) {
die( "unable to send get request" );
}
$data = null;
stream_set_time out($fp, $fsocket_timeou t);
$status = socket_get_stat us($fp);
while( !feof($fp) && !$status['timed_out']){
$data .= fgets ($fp,8192);
$status = socket_get_stat us($fp);
}
fclose ($fp);
// strip headers
$sData = split("\r\n\r\n ", $data, 2);
$data = $sData[1];
// save to cache file
$f2 = fopen($cache_fi lename,"w+");
fwrite($f2,$dat a);
fclose($f2);
}
}
// ok, point to (fresh) cached file
if ( @file_exists($c ache_filename )) {
$handle = fopen($cache_fi lename, $file_mode);
$data = array();
for($x = 0; !feof($handle); $x++ ){
$data[$x] .= fgets ($handle,8192);
}
if( count($data) > 0 ){
//truncate table for new
$this->_mysql_multi_q uery($data, $name_db, $host_db, $user_db,
$pass_db);
}
}
return TRUE;
}
}
Tks a lot
Freebird
I've with a problem, I hope you guys can help me.
I need, from server b, to connect to server a, over the internet, to be able
to open a .txt file and make it a copy to insert line by line inside server
b, the problem, is that I need to make sure the user from server b, is
someone ok, what I mean is, there's a table inside server a, and the user
from server b, to be able to open the file, must be in that table in server
a, to be able to login, but I'm not sure how to connect to server a from
server b, make a verification in the database from server a, and allow the
user to open the file, copy it, and insert into server b database.
So far I can from server b, open the file in server a, copy it, and insert
line by line in server's b database, here's the, I hope you guys can help
me:
/*************** *************** *************
* Function cached_fopen_ur l():
* Caches data from a HTTP resource/url to a
* local file (HTTP headers are stripped)
*************** *************** *************/
function cached_fopen_ur l($url, $file_mode, $timeout_second s = 90,
$cache_path, $fsocket_timeou t = 10, $name_db, $host_db, $user_db, $pass_db){
$debug = FALSE;
clearstatcache( );
//$cache_filename =$cache_path . "/" . urlencode($url) .".cached";
$cache_filename = $cache_path."pr oxylist.txt";
if($debug){
print "local_cach e creation_time =" .
@filemtime($cac he_filename) .
" actual time = " . time() .
" timeout = " .
timeout_seconds ."<p>";
}
//if ( ( @file_exists($c ache_filename ) and ( (
@filemtime($cac he_filename) + $timeout_second s) > ( time() ) ) ) ) {
if ( ( @filemtime($cac he_filename) + $timeout_second s) > ( time() ) ) {
// ok, file is already cached and young enouth
if ($debug) { print "using cached file ($cache_filenam e) <p>";}
} else {
if ($debug) {
print "caching file ($url) to local ($cache_filenam e)<p>";
}
$urlParts = parse_url($url) ;
$host = $urlParts['host'];
$port = (isset($urlPart s['port'])) ? $urlParts['port'] : 80;
if( !$fp = @fsockopen( $host, $port, $errno, $errstr,
$fsocket_timeou t )) {
// Server not responding
} else {
if( !fputs( $fp, "GET $url HTTP/1.0\r\nHost:$ho st\r\n\r\n" ) ) {
die( "unable to send get request" );
}
$data = null;
stream_set_time out($fp, $fsocket_timeou t);
$status = socket_get_stat us($fp);
while( !feof($fp) && !$status['timed_out']){
$data .= fgets ($fp,8192);
$status = socket_get_stat us($fp);
}
fclose ($fp);
// strip headers
$sData = split("\r\n\r\n ", $data, 2);
$data = $sData[1];
// save to cache file
$f2 = fopen($cache_fi lename,"w+");
fwrite($f2,$dat a);
fclose($f2);
}
}
// ok, point to (fresh) cached file
if ( @file_exists($c ache_filename )) {
$handle = fopen($cache_fi lename, $file_mode);
$data = array();
for($x = 0; !feof($handle); $x++ ){
$data[$x] .= fgets ($handle,8192);
}
if( count($data) > 0 ){
//truncate table for new
$this->_mysql_multi_q uery($data, $name_db, $host_db, $user_db,
$pass_db);
}
}
return TRUE;
}
}
Tks a lot
Freebird