Jump to content

Mike Solstice

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Mike Solstice's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. So something like this? $myfile = file_get_contents("http://example.com"); $maxTries = "3"; for ($try=1; $try<=$maxTries; $try++) { if ($myfile === FALSE) { sleep(3); $myfile = file_get_contents("http://example.com"); } else { break; //close for loop } //continue with script & close else } //close else
  2. Ok, I'm having some trouble with file_get_contents failing & am trying to make a loop that will sleep & then retry a maximum of 3 times before giving up & moving to the next item. I tried using a while loop but I'm getting unexpected T_WHILE, which I assume is because it's already in a while loop? I found this: $maxTries = "3"; for ($try=1; $try<=$maxTries; $try++) { but could use some clarification. Will that only trigger if it failes or do I need to include another if statement like $myfile = file_get_contents("http://example.com"); if ($myfile === FALSE) { $maxTries = "3"; for ($try=1; $try<=$maxTries; $try++) { sleep(3); $myfile = file_get_contents("http://example.com"); } else { //continue with script I hope that makes sense...trying to explain it as best I can without having to post my actual source code as I've had it stolen off forums before & now I have a clone to compete with. I'm not great at putting this into words so if I need to clarify, please feel free to ask. I appreciate any & all help given. Thanks!
  3. Nevermind...I found my error. Forgot to specify the field name in the replace command. LOL Thanks anyway!!
  4. Sorry, kind of assumed people would go read the thread that quote is linked to I have a MySQL column that was created as VARCHAR and has numeric entries that contain commas. I need to convert that to INT in order to be able to use the data in calculations, but need to strip the commas out before I can convert to INT otherwise it just cuts off at the comma & I loose the rest of the data.
  5. Moved here since that thread was marked as solved & it's more of a PHP issue at this point anyway. Any & all help is greatly appreciated!
  6. Ok, that works if I run it CLI or though phpMyAdmin, but won't if I try it in php $remcomma = "UPDATE top_train SET deaths = replace( replace(field_name, ',', ''), '"', '' )"; mysql_query($remcomma); I assume because of the quotes used in the regex. I tried escaping the " $remcomma = "UPDATE top_train SET deaths = replace( replace(field_name, ',', ''), '\"', '' )"; mysql_query($remcomma); Which broke it altogether. Anyone have any ideas? Thanks!
  7. Nevermind, was over-complicating it. Got it UPDATE table SET field_name = replace( replace(field_name, ',', ''), '"', '' );
  8. Ok, so if I just simply alter the column to be INT instead of VARCHAR, it drops the numbers after the comma...which isn't going to work. I have a script that cycles through a mysql dump line by line & then writes it to the database, and could use str_replace there to remove the commas in question...but how do I keep it from removing the commas in the dump that are supposed to be there?
  9. *facepalm* Yes, it was the comma. Fixed using str_replace....so obvious...knew it had to be, just been staring at the code too long to see it lol TY!!! On a side note though, even leaving it as varchar...it works.
  10. Ok...been at this for quite a while now & I've decided it's time to bow to the masters lol Please help!! Totally stumped. Not sure if this is the right forum or not, as it's kind of both a mysql & php problem...sorry if not I need to calculate the sum of numeric values in a column. If I use: $sql = "SELECT sum(column) AS total FROM top_train WHERE days = 365 ORDER By lvl DESC LIMIT $from,$to"; $query = $dbcon->run($sql); while($row = mysql_fetch_array($query)){ $result = $row['total']; } return $result; } I get 550 If I use: $sql = "SELECT example AS total FROM top_train WHERE days = 365 ORDER By lvl DESC LIMIT 0,200"; $query = $dbcon->run($sql); $total1 = "0"; while($row = mysql_fetch_array($query)){ $total1 += $row['total']; } I get 550. If I: $sql = "SELECT deaths AS total FROM top_train WHERE days = 365 ORDER By lvl DESC LIMIT 0,200"; $query = $dbcon->run($sql); $total1 = "0"; while($row = mysql_fetch_array($query)){ echo $row['total'] . "<br />"; } I get: 2,710 4,386 120 118 306 Which are the correct values. I've read more pages than I care to count on how to fix this...but nothing has worked. It's currently set to VARCHAR...which I assume isn't correct but would really rather avoid changing it as this new script is an update going on about 700 identical accounts. I have tried changing it to INT, TINYINT, and all the rest...the only difference was 371 instead of 550. Still not accurate? Any & all help would be GREATLY appreciated...but please keep it as simple as possible, still really new to php & mysql. Not a total novice but definitely padawan learner LOL Thanks!!
  11. Ok, basically I'm wanting to make a generic licensing system that will check the subdomain the php file is loaded on & if the root domain is authorized, load. If not display error or do some other action. I've tried: $address = $_SERVER['SERVER_NAME']; $address = str_replace('www.', '', $hostname); if (preg_match('{^http://[\w\.]*google.com/}i', $address)) { else { echo "fail"; } Also tried a more complicated script I found on Google $address = $_SERVER['SERVER_NAME']; $address = str_replace('www.', '', $hostname); if (get_domain($address) == "google.com") { print "Yes."; } function get_domain($url) { $pieces = parse_url($url); $domain = isset($pieces['host']) ? $pieces['host'] : ''; if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) { return $regs['domain']; } return false; } Anyone have any ideas?
  12. Just to test my understanding, basically what's happening is that AfterModuleCreate is passing on an array within an array, so it's necessary to specify both in the var & b/c I didn't it was only looking at the first array & not finding the index in question? Am I even in the right ballpark here? lol
  13. Ok...so I'm pretty new to WHMCS and PHP in general, trying to learn how to create action hooks. The basic idea here is that after WHMCS runs ModuleCreate which connects to cPanel/WHM, creates the user/domain/etc. it will execute this script to create a mysql database in the newly created user's account. I have everything else working, if I manually put in the username & password, save/upload/execute the script goes off without a hitch. The problem is I can't figure out how to set the variables passed on by the AfterModuleCreate action hook. If I function create_forum_account($vars) { print_r($vars); } add_hook("AfterModuleCreate",1,"create_forum_account"); then when the account is created I get: Array ( [params] => Array ( [accountid] => 123 [serviceid] => 123 [domain] => example.com [username] => abcdefg [password] => gfedcba [packageid] => 1 [pid] => 1 [serverid] => 1 [customfields] => Array ( ) [configoptions] => Array ( ) [type] => hostingaccount [producttype] => hostingaccount [moduletype] => cpanel [configoption1] => some_hosting_plan [configoption2] => 0 [configoption3] => 10 [configoption4] => 0 [configoption5] => 500 [configoption6] => [configoption7] => [configoption8] => 1 [configoption9] => [configoption10] => 0 [configoption11] => [configoption12] => 0 [configoption13] => x3 [configoption14] => 0 [configoption15] => [configoption16] => [configoption17] => 10 [configoption18] => 500 [configoption19] => [configoption20] => [configoption21] => [configoption22] => [configoption23] => [configoption24] => [clientsdetails] => Array ( [userid] => 10 [id] => 10 [firstname] => Ima [lastname] => Luser [companyname] => My Company [email] => User@Example.com [address1] => 123 Any St [address2] => [city] => Anytown [state] => NV [postcode] => 00000 [country] => US [countryname] => United States [phonenumber] => (702) 555-1212 [notes] => [password] => encrypted_password_here [currency] => 1 [cctype] => [cclastfour] => [securityqid] => 4 [securityqans] => My Answer [groupid] => 0 [status] => Active [credit] => 0.00 [taxexempt] => [latefeeoveride] => [overideduenotices] => [language] => [lastlogin] => No Login Logged [billingcid] => 0 ) [server] => 1 ) ) And a few other indexes I'm not including here for security purposes. But then if I $cpanel_user = $vars["username"]; $cpanel_password = $vars["password"]; $cpanel_host = $vars["domain"]; I get Notice: Undefined index: username in /absolute/path/file-to-execute.php on line 8 Notice: Undefined index: password in /absolute/path/file-to-execute.php on line 9 Notice: Undefined index: domain in /absolute/path/file-to-execute.php on line 10 In the example action hook that comes with WHMCS $vars["indexname"] supposedly works fine. I've but the WHMCS documentation is absolutely worthless, staff are rude & the forum queens....don't get me started. I hope this makes sense to someone. Any & all help would be greatly appreciated!
×
×
  • 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.