aximbigfan Posted May 6, 2008 Share Posted May 6, 2008 I have coded a custom DB server, and client API. Currently, the syntax of the DB function goes like this remotereg($DBHOST, $RRPASS, $SVRURL, "W", $KEYCAT, $KEYNAME, 0, NULL); Note that I have to put in $DBHOST, $RRPASS, $SVRUR for each call to the function. Is there anyway I can create a function like remotereg_CONNECT($DBHOST, $RRPASS, $SVRUR); And then be able to have remotereg( "W", $KEYCAT, $KEYNAME, 0, NULL); Below it? The thing is, that I don't want new global variables created so tha tthe other function can read them. Basically, I want it setup in a way where I have a few vars, but only the "remotereg" function can see them, or in a similar setup that would work. Sorry if this is hard to understand. The basic thing is that I don't want to constantly have to enter the DB hostname, Path, and Pass, and I want to use another function to set them up, so that remotereg can see them, but nothing else can. Thanks! Chris Quote Link to comment Share on other sites More sharing options...
AP81 Posted May 6, 2008 Share Posted May 6, 2008 How have you defined your functions? If you use a class you can have the constructor set the $DBHOST, $RRPASS, $SVRUR, i.e. <?php Class remoteReg() { private $DBHOST; private $RRPASS; private $SVRURL; public function __construct($host, $pass, $url) { $this->DBHOST = $host; $this->RRPASS = $pass; $this->SVRURL = $url; } public function Connect() { // connection code here } public function remotereg($var1, $KEYCAT, $KEYNAME, $var2, $var3) { //do the remote reg, sorry don't know what your variable names are } } // now create the class $host = 'xxxx'; $pass = 'yyyy'; $url = 'testserver'; $reg = new remoteReg($host,$pass,$url); $reg->remotereg("W", 'keycat1', 'keyname1', 0, NULL); ?> Obviously you need to modify this so it reflects your code. Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted May 6, 2008 Author Share Posted May 6, 2008 Thanks! I don't currently have the functions in a class, but it should be very simple to do so. Chris Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted May 9, 2008 Author Share Posted May 9, 2008 Ok, I have this class, but it does not work. Is the syntax correct? class remoteReg { //Make configuration variables private private $host; private $pass; private $path; //Construct function __consruct($host, $pass, $path) { $this->host = $host; $this->pass = $pass; $this->path = $path; } //Main RemoteReg function public function remotereg($mode, $cat=null, $key=null, $val=null, $args=null ) { $host = $this->host; $pass = $this->pass; $path = $this->path; $val = json_encode(urlencode($val)); $val = urlencode($val); $http_response = ""; $data = "pass=$pass&mode=$mode&cat=$cat&key=$key&val=$val&args=$args"; $content_length = strlen($data); $fp = fsockopen($host, 80); fputs($fp, "POST $path HTTP/1.0\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-Length: $content_length\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $http_response = stream_get_contents($fp); fclose($fp); if (preg_match("[CONTENT.TYPE:RCODE]", $http_response)==1) { @$wall = "[CONTENT.TYPE:RCODE]"; @$explode = explode($wall, $http_response); @$output = $explode[1]; return (int)$output; } $parsein = "$http_response"; $start = "[CONTENT-START->>>>]"; $explode = explode($start, $parsein); @$output = $explode[1]; $http_response = urldecode(json_decode($output)); return $http_response; } } Thanks, Chris Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted May 9, 2008 Author Share Posted May 9, 2008 NEVER MIND!! I'm a moron. I had 2 seperate files, and one had a typo in it, and I corrected the typo in the other. : It works. Chris Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.