Hello,

I have a script which uses if available the function exec() like:

exec("whois -h whois.crsnic.net  \"domain.com\"", $buffer);

or if the server is a windows type or in case of that the command line is not accessible:

function get_whois_data($test_server, $test_domain) {
	$msg = "";
	$connection = fsockopen($test_server, 43, $errno, $errstr, 10);
	if (!$connection) {
		$msg = "Can't connect to the server!";
	} else {
		sleep(2);
		fputs($connection, $test_domain."\r\n"); 
		while (!feof($connection)) {
			$msg .= fgets($connection, 4096);
		}
		fclose($connection);
	}
	return $msg;
}

I think that "function_exits()" will work but what if "safe_mode_exec_dir" is set to some value?

    4 days later

    Hello,

    anyone with an idea here?

      <?php
      $dir = get_cfg_var('safe_mode_exec_dir');
      if (!empty($dir))
      	echo 'exec_dir is set to: '. $dir;
      else
      	echo 'exec_dir is not set...';
      ?>
      

      example here...

      sometimes searching PHP.net will answer all your questions.... took me 5 minutes...

      obviously you will want to check if safe_mode is on first..

        Hi thanks, I read the manual every day...(not the whole one) ;-)

        ... but back to my question, first I check if safe_mode is "on" and then if this is true then I have to check that the script is inside a existing safe_mode_exe_dir?

        Looks to me like a very strange and extensive check... what do you think? (think about the function I wan't to use)

          olaf wrote:

          Hi thanks, I read the manual every day...(not the whole one) ;-)

          ... but back to my question, first I check if safe_mode is "on" and then if this is true then I have to check that the script is inside a existing safe_mode_exe_dir?

          Looks to me like a very strange and extensive check... what do you think? (think about the function I wan't to use)

          If you prefer using exec() over your back up method, then its exactly as "strange and extensive" as it has to be...

          or you can setup error_handling and call exec everytime and on error, use the backup method... either way, its "strange and extensive"

            stop stop... you understand me wrong ;-)

            I have a script where I can switch between both methods (the one the other). I'm looking for a simple where to put there some automatisation. (to stop getting questions from people who doesn't know)

              olaf wrote:

              stop stop... you understand me wrong ;-)

              I have a script where I can switch between both methods (the one the other). I'm looking for a simple where to put there some automatisation. (to stop getting questions from people who doesn't know)

              Well unless you know of a simpler way, the get_cfg_var() is the easiest way I know... OTHER then trapping errors and doing it that way... I would prefer the get_cfg_var() method as it doesnt DEPEND on trapping a mistake...

                But you understand what I try to do?

                I have this situation at the moment:

                class SIDN_contract extends fpdi {
                
                var $os_system = "linux"; // change this to "win" for windows hosts
                
                function get_whois_data() {
                	$buffer = "";
                	$domein = $this->domain.".nl";
                	if ($this->os_system == "win") {
                		$connection = @fsockopen("whois.domain-registry.nl", 43);
                		if (!$connection) {
                			return;
                		} else {
                			fputs($connection, "is ".$domein); 
                			while (!feof($connection)) {
                				$buffer .= fgets($connection, 4096);
                			}
                			fclose($connection);
                		}
                	} else {
                		$string = "whois -h whois.domain-registry.nl \"is ".$domein."\""; 
                		exec($string, $buffer);
                	}
                	if ($buffer != "") {
                		if (eregi("is free", $buffer)) {
                			return true;
                		} else {
                			return false;
                		}
                	} else {
                		$this->message[] = $this->message_strings(12);
                	}
                }
                     // the other code
                }
                

                I want to automate this function/method...
                Does it make sense to check the for this purpose?

                Thanks for your advice until now.

                  oooh...
                  by the way if I check only with function_exists does it be enough?

                  If someone placed this script outside the safe_mode_exe_dir the exec() function is not available. In this case I should give the advice to place the script in the right directory to raise the performance, what do you think?

                    might work, try it and see, as far as understanding you, yes and the answer is still the same

                      I think I know what I do I check both and inform the user if the exec() function is only possible inside his safe_mode dirs. Thanks, you helped me a lot ...

                        Write a Reply...