Jump to content

rhodesa

Staff Alumni
  • Posts

    5,253
  • Joined

  • Last visited

Everything posted by rhodesa

  1. after $query = "SELECT * FROM `rawmaterials` WHERE `$searchtype` LIKE '$searchterm'"; if you do echo $query; what is the output?
  2. @OZZY9384 Based on the questions you are asking, I think you are getting in way over your head. You need to start simple before developing an application of this caliber. Once you gain the experience and get a handle on it, we can help with specific questions, but I'm not about to go back and forth writing out each step of this from start to finish.
  3. PC? As in Personal Computer? Every home computer out there is a PC (including your brother's MAC). I guess you could mean a computer running Windows, but does your HP Laptop not run Windows? You want to test it in each OS (Mac, Windows, and Various Linux Distros if you can) and each Browser for each OS (Internet Explorer, FireFox, Safari, etc)
  4. again, each number corresponds to a card in the deck So, just save your cards as 1.jpg 2.jpg etc
  5. $deck = range(1,52); that makes an array of numbers from 1 to 52. the rest of the code assigns those numbers to people's hands and the community cards
  6. In PHP: <?php $date1 = '08-14-2009 08:00:00'; $date2 = '08-14-2009 09:15:00'; $diff = strtotime($date2) - strtotime($date1); //This gives it in seconds $diff_minutes = $diff / 60; echo $diff_minutes; ?> But is this coming from MySQL? If so, you can do it right in the MySQL query
  7. You don't "need" a mysql database. You may want to use it to track users/points/etc. If the level of complexity grows on this, you may want to use a database to track every move...
  8. Check to make sure you are connecting to the correct database and table, cus that error means you have the datatype of the ParentName field as Double and not Varchar
  9. first thing i notice is this: $query = 'SELECT * FROM `rawmaterials` WHERE `$searchtype` LIKE `$searchterm` '; should be $query = "SELECT * FROM `rawmaterials` WHERE `$searchtype` LIKE '$searchterm'"; to make it syntactically correct...depending on what your logic is, it may need more changes also, when debugging, use mysql_error() to see what is wrong: $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable: ".mysql_error());
  10. Please don't hijack this post...start a new one: http://www.phpfreaks.com/forums/index.php?action=post;board=3.0
  11. think of it just like cards...when you start, you need to build a full "deck", then shuffle them so they are random, thes give them out. Let's assume you have a way to translate the numbers 1 to 52...so 1 is the Ace of spades, 2 is the 2 of spades, 13 is the king of spades, 14 is the ace of hearts, etc. <?php $players = 4; $deck = range(1,52); shuffle($deck); //Kill the first card array_pop($deck); $hands = array(); $community = array(); //Deal for($a = 0;$a < 3;$a++){ for($b = 0;$b < $players;$b++){ $hands[b][] = array_pop($deck); } } //Kill the another card array_pop($deck); //Flop $community[] = array_pop($deck); $community[] = array_pop($deck); $community[] = array_pop($deck); //Kill the another card array_pop($deck); //Turn $community[] = array_pop($deck); //Kill the another card array_pop($deck); //River $community[] = array_pop($deck); ?>
  12. try function tep_draw_pull_down_time($name='') { $times = array(); for($i=1;$i<25;$i++) { $times[$i] = sprintf('%04d',$i * 100); } $fields = temp_draw_pull_down_menu($name, $times, ''); return fields; }
  13. Here is a class I wrote to help with SSH commands: <?php /************************************************************************************************** * SSH Class * * This class was writen to be used in conjuction with the SSH2 PECL extension. It does a pretty * good job handling bi-directional pipeing in the cmd() function. If you find ways to improve * this class, please notify me so I can spread the word. * * NOTE: PasswordAuthentication must be set to yes in the sshd_config file of the server the * script is connecting to. *************************************************************************************************/ class ssh { protected static $instances = array(); /*************************************************************************** * CONSTANTS * * DEFAULT_TIMEOUT: Default Timeout for commands (20 seconds) **************************************************************************/ const DEFAULT_TIMEOUT = 20; /*************************************************************************** * MEMBERS **************************************************************************/ protected $host; protected $port; protected $user; protected $pass; protected $cnx; protected $stream; protected $timeout = self :: DEFAULT_TIMEOUT; /*************************************************************************** * METHODS **************************************************************************/ public static function getInstance($id = null) { if (empty ($id)) $id = 0; if (isset (self :: $instances[$id])) return self :: $instances[$id]; return false; } public function registerInstance($id = null) { if (empty ($id)) { if (isset (self :: $instances[0])) throw new Exception("Default instance already exists"); self :: $instances[0] = $this; return true; } if (isset (self :: $instances[$id])) throw new Exception("Instance '{$id}' already exists"); self :: $instances[$id] = $this; return true; } #-------------------------------------------------------------------------------------------------- # __construct(string $host,[string $port]) # # HOST - Hostname used for the ssh connection. IP address is also acceptable. # PORT - (Optional) Port to use for the ssh connection. If omitted, the default port (22) will # be used # # Class constructor. Checks the SSH2 extension is loaded then executes the ssh2_connect # command to establish a connection with the specified host at the specified port. #-------------------------------------------------------------------------------------------------- public function __construct($host, $port = '22') { //Check to make sure the SSH2 if (!extension_loaded('ssh2')) throw new Exception("SSH2 Extension must be installed"); //Save host/port $this->host = $host; if (strlen($port)) $this->port = $port; //Establish SSH connection if (!($this->cnx = ssh2_connect($this->host, $this->port))) throw new Exception("Connection failed to host '{$this->host}:{$this->port}'"); } #-------------------------------------------------------------------------------------------------- # boolean getFingerprint() # # Returns the fingerprint of the remote server. #-------------------------------------------------------------------------------------------------- public function getFingerprint() { return @ ssh2_fingerprint($this->cnx); } #-------------------------------------------------------------------------------------------------- # boolean auth(string $user,[string $password]) # # USER - Username used to authenticate the current connection. # PASSWORD - (Optional) Password used to authenticate user at the current connection. If # omitted, no password is used durring authentication. # # Tries to authenticate with the specified user and optional password. If successful, it # opens a shell and stores the stream into a variable. Returns true if sucessful, false if # there is an error. #-------------------------------------------------------------------------------------------------- public function auth($user, $password = null) { if (!@ ssh2_auth_password($this->cnx, $user, $password)) throw new Exception("Authorization for '$user' failed at host '{$this->host}:{$this->port}'"); $this->user = $user; $this->pass = $password; return true; } #-------------------------------------------------------------------------------------------------- # boolean setTimeout([int seconds]) # # SECONDS - (Optional) Number of seconds until a cmd() command times out. # # Sets the timeout variable used in the cmd() function. If seconds is specified, it confirms # the value is an integer then sets the timeout. If ommited, it sets timeout to the default # value. Returns true if successful, otherwise returns false. #-------------------------------------------------------------------------------------------------- public function setTimeout($seconds = self :: DEFAULT_TIMEOUT) { if (is_numeric($seconds) && $seconds > 0) return $this->timeout = $seconds; return false; } #-------------------------------------------------------------------------------------------------- # boolean cmd(string $cmd,[ref $output],[ref $error],[string $user],[string $pass]) # # CMD - Command to run on the remote system. # OUTPUT - (Optional) Reference to a variable in which any output from the remote terminal will # be stored. # RC - (Optional) Reference to a variable in which the command's exit code will be stored. # USER - (Optional) User to run the command as. # PASS - (Optional) Password for the user above. If user is null but a password is specified, # sudo is assumed. # # Runs a command on the remote system and gathers any output from the command. Returns true # if sucessful, false if there is an error. #-------------------------------------------------------------------------------------------------- public function cmd($cmd, & $output = null, & $rc = null, $user = null, $pass = null) { //Confirm we have a stream open if (!$this->stream) { if (!($this->stream = @ ssh2_shell($this->cnx))) throw new Exception("Could not open a shell for '$user' at host '{$this->host}:{$this->port}'"); } //Generate a random string to use as a key we can parse for. $prefix = md5(microtime()); $suffix = md5(microtime()); $fail = md5(microtime()); //Set some variables $output = null; $rc = null; $start = time(); //Generate the command // It wraps the command with echo statements in order to determine the begining // and end of the output from running the command. $command = $cmd; if (strlen($user) && strlen($pass)) //Run as other user $command = sprintf('su %s -c %s', escapeshellarg($user), escapeshellarg($command)); elseif (strlen($pass)) //Sudo $command = sprintf("sudo %s", escapeshellarg($command)); $command = sprintf("echo %s && %s && echo %s || echo %s\n", $prefix, $command, $suffix . ':$?', $fail . ':$?'); fwrite($this->stream, $command); //Start the inifinite loop while (1) { //Get some output from shell $output .= stream_get_contents($this->stream); //Flush the output // Found the prefix key. Strip everything up to and including the prefix key from output // The \r\n is to make sure we get the new line feed after the echo if (preg_match(sprintf('/%s\r?\n(.*)/s', $prefix), $output, $matches)) $output = $matches[1]; //Finished // Found the suffix key so the command is done. Strip the suffix key and everything after from output if (preg_match(sprintf('/(.*)%s:(\d*)\r?\n/s', $suffix), $output, $matches)) { $output = $matches[1]; $rc = $matches[2]; return true; } //Failed // Found the failed suffix key so the command errored out for some reason. // Strip the failed suffix key and everything after from output and return false. if (preg_match(sprintf('/(.*)%s:(\d*)\r?\n/s', $fail), $output, $matches)) { $output = $matches[1]; $rc = $matches[2]; return false; } //Check for password prompt if (strlen($pass) && preg_match('/password:\s*$/i', $output)) { $output = null; fwrite($this->stream, "{$pass}\n"); $pass = null; } //Check for timeout if (time() > $start + $this->timeout) throw new Exception("Command '{$cmd}' timed out"); //Sleep for a micro second to save the processor usleep(1); } //If we get here something weird happened. return false; } #-------------------------------------------------------------------------------------------------- # boolean su_cmd(string $cmd,string $user,string $pass,[ref $output],[ref $error]) # # CMD - Command to run on the remote system. # USER - User to run the command as. # PASS - Password for the user above. # OUTPUT - (Optional) Reference to a variable in which any output from the remote terminal will # be stored. # RC - (Optional) Reference to a variable in which the command's exit code will be stored. # # Runs the cmd() function. #-------------------------------------------------------------------------------------------------- public function su_cmd($cmd, $user, $pass, & $output = null, & $rc = null) { return $this->cmd($cmd, $output, $rc, $user, $pass); } #-------------------------------------------------------------------------------------------------- # boolean sudo_cmd(string $cmd,string $pass,[ref $output],[ref $error]) # # CMD - Command to run on the remote system. # OUTPUT - (Optional) Reference to a variable in which any output from the remote terminal will # be stored. # RC - (Optional) Reference to a variable in which the command's exit code will be stored. # # Runs the cmd() function. #-------------------------------------------------------------------------------------------------- public function sudo_cmd($cmd, & $output = null, & $rc = null) { return $this->cmd($cmd, $output, $rc, null, $this->pass); } #-------------------------------------------------------------------------------------------------- # boolean put(string $local,string $remote,[int $mode]) # # LOCAL - Local path to the file that will be sent. # REMOTE - Remote path where the file being sent will be stored. # MODE - (Optional) Mode to create the file with. If ommited a default of 700 is used. # # Checks to make sure the local file exists then sends it via SCP. Returns true if # sucessful, false if there is an error. #-------------------------------------------------------------------------------------------------- public function put($local, $remote, $mode = 0700) { if (!is_file($local)) throw new Exception("Tried sending '{$local}' but it does not exist"); if (!$remote) $remote = basename($local); if (@ ssh2_scp_send($this->cnx, $local, $remote, $mode)) return true; throw new Exception("Failed to send '{$local}'"); } #-------------------------------------------------------------------------------------------------- # boolean get(string $remote,string $local) # # REMOTE - Remote path to the file being received. # LOCAL - Local path where the file being received will be stored. # # Receives a file via SCP. Returns true if sucessful, false if there is an error. #-------------------------------------------------------------------------------------------------- public function get($remote, $local) { if (@ ssh2_scp_recv($this->cnx, $remote, $local)) return true; throw new Exception("Failed to get '{$remote}'"); } } ?> Usage for your case would be something like: <?php require_once('ssh.class.inc'); $ssh = new ssh($hostname); if (!$ssh->auth($user,$pass)) die("Failed to authenticate to '{$hostname}' as '{$user}'\n"); $cmd1 = "/srv/www/htdocs/exec/rebuild.sh"; $ssh->setTimeout(60); //Timeout after 60 seconds...increase if needed if(!$ssh->cmd($cmd, $output, $rc)) die("Failed to run command {$cmd}"); print "Return Code: {$rc}\n"; print "======= Output =======\n$output\n======================\n"; ?>
  14. yeah, keep it simple....just getting a remote file like that doesn't need cURL. cURL is nice, but in this case it's like using a sledgehammer to hang a picture
  15. Yes, the ID will get passed as the value. If you want to test it, put this at the top of the PHP page it's submitting to: <?php print '<pre>'.print_r($_POST).'</pre>'; exit; ?> That will print the array of all the data being submitted by the form
  16. Well, I just tested your code and it works fine. The only other thing it could be, is $t_email not being set correctly. Are you sure that value is good? Next step is to call your hosting service. It could be that mail is not configured correctly at all on the system and they need to change something at the system level. Either way, there is no other changes you can make from a coding level to make this work.
  17. My guess is your hosting service doesn't allow emails to be sent from external domains. If you change the $from to something@yourdomain.com does it work? Try removing the $headers part all together too. Long story short, your code is fine. Your hosting service must be blocking it for some reason. Call your hosting service and ask them what you need to do.
  18. Try this instead: <?php function twitter_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($c, CURLOPT_TIMEOUT, 5); $response = curl_exec($c); $responseInfo = curl_getinfo($c); curl_close($c); if (intval($responseInfo['http_code']) == 200) { if (class_exists('SimpleXMLElement')) { $xml = new SimpleXMLElement($response); return $xml; } else { return $response; } } else { return false; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <ul> <?php if ($twitter_xml = twitter_status('61289623')) { foreach ($twitter_xml->status as $key => $status) { ?> <li><?php echo $status->text; ?></li> <?php ++$i; if ($i == 1) break; } ?> <li><a href="http://twitter.com/YOUR_PROFILE_HERE">more...</a></li> <?php } else { echo 'Sorry, Twitter seems to be unavailable at the moment...again...'; } ?> </ul> <body> </body> </html>
  19. um...your twitter_status() function is defined as JavaScript not PHP....
  20. <?php $sql = 'SELECT id,name FROM someTable'; $result = mysql_query($sql) or die(mysql_error()); echo '<select name="some_field">'; while($row = mysql_fetch_assoc($result)){ printf('<option value="%s">%s</option>',htmlspecialchars($row['id']),htmlspecialchars($row['name'])); } echo '</select>'; ?>
  21. SELECT r.ID, r.name, r.address, i.inDate FROM restaurants r, inspections i WHERE r.ID = i.<FIELD WITH RESTAURANT ID> AND r.name != '' AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= i.inDate GROUP BY r.ID, r.name, r.address, i.inDate ORDER BY r.name You need to fill in <FIELD WITH RESTAURANT ID> with the column that holds the restaurant id in the inspections table. Then the rest *should* work. edit: with this method you don't need any of the PHP strtotime() code
  22. Nope, returning to your site from PayPal is purely optional for the user.
  23. without all the code, it's kind of hard to debug it. but my guess is it should be: $('#changing_content').html($('#changing_content').html()+'<center><a onClick="open_window(\''+artist+'\', \''+title+'\');" href="#"><img src="image/buybutton.gif" style="border: none;" /></a><br /><br /><b>'+json.title+'</b></center>'); also, should json.title just be title?
  24. if ($user_class->admin != 1 && $user_class->admin != 2) { echo Message("You are not authorized to be here. YOU MOTHERFUCKER"); include 'footer.php'; die(); }
  25. i don't see anything wrong with the upload code. do you have a link i can click to try and download it? when you are serving up the file, is it a direct link to the file or through a php script?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.