Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. You have the \r\n inside single-quotes so it'll be treated literally rather than as a new-line character as intended. So when you send your message you are sending literally slash-r-slash-n and not a new line. The SMTP server is waiting for that new line before it parses the message and sends a response.
  2. Do you mean text messages like from a cell phone? Are you talking about a spying app installed on the phone to record text messages? If yes, then the answer is no, PHP is not the tool to use for this. If no, you'll need to explain better what you mean.
  3. Your site was probably encoded using Zend Guard or similar. If that is the case, then there probably isn't much you can do unless you also have an un-encoded copy of the source code somewhere.
  4. I'd suggest you find some updated code that does what you want. That code is like late-90's era (NS4/IE5) code. Aside from being old it's not written in such a way that you can just copy and paste multiple copies of it into a page. You'd need to rewrite it to remove it's dependence on global variables for that to work.
  5. Sounds like you probably just need to hire someone who knows what they are doing to resolve it. Nobody is going to walk you through everything step by step for free, especially since you don't even really know what is wrong. If you do keep poking around yourself make sure you back everything up first. Randomly guessing at what the problem is and changing things to fix it may just make things even worse.
  6. You need to be assigning the posted data to the session in formPHASE2.php, for example: session_start(); $_SESSION['first'] = $_POST['first']; $_SESSION['last'] = $_POST['last']; There is no need to include it in your URL's for your redirect, so just remove the parameters from there. On the next page, you then need to read the data back out of the session, for example: session_start(); $first = $_SESSION['first']; $last = $_SESSION['last']; echo 'First: '.$first.'; Last: '.$last;
  7. Not entirely. SQL Server's BIT type does act as a boolean field and stores only a single 1 or 0 (or NULL if allowed). Mysql's BIT type allows for multiple bits to be stored, but could still be made to essentially be a boolean field by using a BIT(1) definition (allow only 1 bit). I've never used mysql's BIT type so i'm not sure how it would interact with PHP when selecting the value back out. You could use the HEX() function to find out what is returned. TINYINT is commonly used for boolean fields, partly because before mysql5 it was the best option as there was no BIT type. As you mentioned, with TINYINT you could add a few additional values as well such as a value for 'maybe'. Another common option is to use a CHAR(1) field and strings like 'Y' or 'N'. Both would use the same amount of storage space, it mostly just comes down to what your preference is.
  8. Only the first page load by a user would incur the full cost of all the resources. After that your visitors will most likely have cached all the secondary resources like the CSS file and images. The caching will save a lot of bandwidth costs by either eliminating requests for the files or reducing their size to a few hundred bytes of headers but no content. I doubt you'd get even close to your 30 gigabyte limit for a while, and by the time you manage to get to that level you should have enough money available to pay for better hosting services or more bandwidth access. If you're limited to 30 gig I am going to assume you are using some free host. 30 gig isn't much and most paid hosts I've seen offer far more than that. I pay $20/month for a VPS and get 2TB outbound + free inbound bandwidth included.
  9. You can't wait for the result of your ajax script to decide if the initial form submission should be cancelled or not. When the form is initially submitted you need to just cancel that submission. Then you initiate your ajax request and wait for the response. If the response is good then you can re-submit the form using javascript's .submit() function. In pseudo-code for example: form.onsubmit=function(event){ event.preventDefault(); //cancel submission var ajax=initAjax(); ajax.onreadystatechange=function(){ if (ajax.responseText=='success'){ form.submit(); } } ajax.send(); return false; //older way of canceling submission just incase. };
  10. You can completely disable the timelimit by calling set_time_limit(0). Rather than disable it, some recommend you just pick something reasonable and refresh it in a loop. Calling set_time_limit restarts the timer at zero so if you wrote something like this: while (true){ set_time_limit(5); doSomething(); } so long as doSomething() executed in less than 5 seconds the script would run indefinitely. Only if something caused it to run longer would the script be killed.
  11. If you have in your ini file include_path = ".;c:\php\includes" and your class.phpmailer.php file is located at c:\php\includes\class.phpmailer.php then what you would want to write in your PHP code is simply: require_once 'class.phpmailer.php'; Essentially you need to make sure that the value you give to require_once (or include, etc) combined with one of the paths in your include_path directive points to a valid file. So, given your script is located in C:\websites\Test\ when you do require_once 'class.phpmailer.php'; with include_path=".;c:\php\includes" PHP will:Does c:\website\test\class.phpmailer.php exist? yes/no Does c:\php\includes\class.phpmailer.php exist? yes/no The first one of those to be answered 'yes' is the file that is included. If none are true, you get your error. As mentioned before, you need to make sure you restart apache when making changes to your php.ini file. Changes made are not seen until a restart is done. Also the output of phpinfo() will tell you exactly which php.ini file to be editing and what the current configuration values are incase there are multiple files and you are unsure which to use.
  12. If you want to output HTML into a textarea as content, you need to escape eg. Eg, output: <textarea><p>____</p></textarea>
  13. You can use the watch utility to just re-issue the request every x seconds. that is the closest you'd get to a continuous monitoring like tail. watch mysqladmin -u user -v processlist When it comes to the password, see End-User Guidelines for Password Security for options.
  14. I wouldn't bother with a class for just one function like that. Rather I would just make the function and include it. If you want to do a class, I'd re-work things a bit. Eg: class Filesystem { public function write_file($full_path, $data, $mode='wb', $f_perm=0644, $d_perm=0755){ if (!$this->mkdir(dirname($full_path), $d_perm)){ return false; } $success=false; $fp = fopen($full_path, $mode); if ($fp && flock($fp, LOCK_EX)){ chmod($full_path, $f_perm); if (fwrite($fp, $data) === strlen($data)){ $success = true; } flock($fp, LOCK_UN); } if ($fp) fclose($fp); return $success; } public function mkdir($path, $d_perm=0755){ if (!is_dir($path)){ return mkdir($path, $d_perm, true); } return true; } } You could extend it further to provide methods for deleting files, reading files, virtual root, etc.
  15. There is some more information an examples over on Devshed regarding abstract classes and interfaces in this thread: Why Interfaces!?
  16. & can mean different things depending on the context it is used in. There is no array-specific meaning for it. If used between two expressions then it would be treated as the bitwise AND operator If used before a variable in an assignment or in a function parameter it would be the reference operator and cause a reference to the variable to be used rather than a copy of the variable. If you want more specific information/explanation then you'll have to post the code in question so we can see how it is being used.
  17. I would be inclined to believe that for some reason your database probably doesn't have any indexes and as such is doing a table scan each request resulting in a lot of disk i/o and processing. If not that, maybe your scripts are poorly written and doing something like select * from blah; and filtering the results themselves rather than with a proper WHERE clause. Ultimately we do not have enough information to be able to say one way or the other what your issue might be.
  18. When you add methods to a type in Javascript you generally want to put them on the prototype for efficiency reasons. The prototype is shared among all objects created of that type, so only one copy of the method is needed in memory. If you add methods via the constructor using this.blah = function(){...} then you are creating a new copy of the function for each instance of the type you create, wasting memory space. The benefit of using the this.blah = function(){...} method is you can emulate private instance variables by creating closures and using a variable within the constructor. Eg: function Counter(){ var count=0; this.increment=function(){ return ++count; } this.decrement=function(){ return --count; } } var c = new Counter(); c.increment(); Doing things that way prevents you from modifying the count variable except via those methods at the expense of a bit more memory creating copies of the methods. When using the more traditional prototype method of function Counter(){ this.count=0; } Counter.prototype = { increment: function(){ return ++this.count; } decrement: function(){ return --this.count; } }; var c=new Counter(); c.increment(); Then the increment/decrement methods are shared among all instances of Counter but the state variable count is accessible by doing c.count. In order to keep the shared memory aspect of the prototype method, but still indicate an instance variable is private (or protected) some people prefix the variable with a _. The _ doesn't mean anything to the JS engine but it's a symbol to the developer that the property should not be accessed directly and if it is, bad things could happen.
  19. Typically you define the prototype outside of the constructor. eg: function Animal(){} Animal.prototype = { walk: function(){ return 'walk walk walk'; } }; function Elephant(){} Elephant.prototype = new Animal(); Elephant.prototype.trumpet = function(){ return 'splash splash'; }; The constructor need not return anything, returning 'this' is the default action. When you call the function, you do not involve the prototype, just call the function directly on the object var Elephant1=new Elephant(); console.log(Elephant1.walk()); console.log(Elephant1.trumpet());
  20. No, the script tags importing external files do not contain any { } pairs so they are not affected by smarty. Neither are the external files referenced as they are not parsed by smarty. Online inline scripts (or anywhere else you use { } pairs) needs to be wrapped in the literal tags.
  21. Surround your script tags with smarty's {literal}...{/literal} tags What's happening is smarty is treating the { and } in the script as smarty tags and replacing them. If you view-source on your page you will see that the code is actually: <script type="text/javascript"> $(function() ); }); </script>
  22. It doesn't really matter what framework you are using. It's just basic math. You take the amount and subtract the fees. If you are going to do both a flat fee and percentage, you need to decide which order you want to remove them in and be consistent. Removing the flat fee first then taking a percentage would reduce the percentage fee amount. //As a fraction from 0 (0%) to 1 (100%) $feePercent=0.1; //in dollars $amount = 20; $flatFee = 0.50; $rateFee = $amount*$feePercent; $net = $amount - $flatFee - $rateFee;
  23. The relevant part would be the code that you wrote which deals with the specific issue you are having, in this case the code you wrote dealing with sending your confirmation email, ie: function SendUserConfirmationEmail(&$formvars) { $mailer = new PHPMailer(); $mailer->CharSet = 'utf-8'; $mailer->AddAddress($formvars['email'],$formvars['name']); $mailer->Subject = "Your registration with ".$this->sitename; $mailer->From = $this->GetFromAddress(); $confirmcode = $formvars['confirmcode']; $confirm_url = $this->GetAbsoluteURLFolder().'/confirmreg.php?code='.$confirmcode; $mailer->Body ="Hello ".$formvars['name']."\r\n\r\n". "Thanks for your registration with ".$this->sitename."\r\n". "Please click the link below to confirm your registration.\r\n". "$confirm_url\r\n". "\r\n". "Regards,\r\n". "Webmaster\r\n". $this->sitename; if(!$mailer->Send()) { $this->HandleError("Failed sending registration confirmation email."); return false; } return true; } If we needed more code, we'd ask for it. If using a library, particularly a popular one like PHPMailer you pretty much never need to post that. We can go downloaded if necessary, but most of the time there is nothing wrong in the library code. As for your issue, diagnosing email issues can be hard, especially if you don't have access to email server logs on the outgoing/incoming servers. There are a number of rules of thumb about how to avoid your emails getting blocked by spam filters. Using a library like PHPMailer is a good start as it will typically cover creating proper and valid emails. Another rule of thumb is the address you use as your From: address should be on the same domain as your site and it can be helpful if it exists as a real mailbox. As such, try sending your messages with a real email ending in @yoursite.com. From what I understand it sounds like the messages sometimes arrive but sometimes not, even if all the info for the message is the same (ie same content, same to/from addresses, etc). Have you checked the spam folders to make sure it truly doesn't arrive rather than just being filtered out? Does your mail provider have spam controls that may filter the message at the server level? Have any of the emails just arrived late (maybe hours later) rather than quickly? Have you been able to identify any kind of possible pattern for when it works vs doesn't work (ie time of day, certain providers, etc).
  24. It's not that we are being haters, or that we don't think you are trying. We simply cannot provide any sort of help with the information you are willing to provide. It's like if you ride your bicycle up to the auto-mechanics to tell them your car is broken and ask for help fixing it, but when they ask what's the issue is or if they can see your car you say "Sorry, that's private". The code given to use was a custom function. That is why there is no mention of it in the tutorials/classes you may have watched. Changing the name will not do anything to affect the outcome either. There really isn't any consistency for how an API accepts or returns data. That is why we cannot help you because in order to we'd need to be able to see the API (or documentation at least) to determine how it works. Every API is different with regard to how you pass data to it or get data from it. JSON or XML are common mediums for transferring data but that tells you nothing about the actual data you need to send/get (ie, parameter names, order of fields, etc). Based on what you have stated the API seems to expect a GET request with various parameters in the query string of the URL. What this means is you can use a simple file_get_contents to query the API and see the results without having to mess around with trying to send POST data which is what the help you have thus far received has been oriented toward. Being a simple GET request means you can test the API your browser also by simply entering the URL into your address bar and checking the data returned. Once you get data you expect you can start on your PHP code to issue the request and work with the result. So, here is the basic steps of how you start trying do what you need: Start with your browserInput the Web API URL in your address bar Add the parameters you think it needs in the query string and load the page If you get an error, repeat step b. If you get expected results, move on Code your PHPTake the URL from your address bar and put it into your PHP code as a variable; $url="copy/paste url here" For a simple GET request, all you need to do is use file_get_contents to load response. Use the URL as the first parameter, assign the result to a variable var_dump the variable returned by file_get_contents and ensure it contains similar content to what shows in the browser when you make the api request. When var_dump shows the expected results, move on Process the resultsDetermine what kind of result you are getting. Is it XML? JSON? Something else. JSON is common because it is easy, but XML is still used. If you are getting a JSON result you would use json_decode to convert the data into a PHP object or array for processing. If you are getting a XML result then you'll need to use either SimpleXML or DOMDocument to access the information. In order for us to provide any more specific help than that you need to be able to provide us with more specific information such as API documentation. You can always try and edit out whatever confidential/proprietary information you need to but you still need to convey the usage of the API.
  25. Your PDO setup needs to be configured to throw exceptions on an error for a try/catch to be useful. If it's set to only issue a warning or be silent you will not be catching any of the errors. Wherever you connect to your database at, make sure you have set the PDO::ATTR_ERRMODE attribute to PDO::ERRMODE_EXCEPTION. bindParam accepts a variable by reference. As such you only need to call bindParam once outside your loop, then within your loop just overwrite the variable with the data. For example: $dbh->beginTransaction(); $query = " UPDATE carer SET firstname = ':firstname', surname = ':surname', address1 = ':address1', ... WHERE valid_users_id = ':usrid' "; $stmt = $dbh->prepare($query); $stmt->bindParam(':firstname', $bind_firstname, PDO::PARAM_STR); $stmt->bindParam(':surname', $bind_surname, PDO::PARAM_STR); $stmt->bindParam(':address1', $bind_address1, PDO::PARAM_STR); ... $stmt->bindParam(':usrid', $_SESSION['id'], PDO::PARAM_INT); foreach ($_POST['records'] as $data) { //Overwrite the bind_* variables with data from the arrray extract($data, EXTR_PREFIX_ALL, 'bind'); //Run the query $stmt->execute(); } Another possibility is your encountering a problem before your call to commit(), such as in your emailing function. If the code ends prior to calling commit then the default action is to rollback. As your code is now, a failure would cause additional problems anyway as your code is not properly structured. For each call to ->beginTransaction you can only call either ->commit or ->rollback once. Currently you call ->beginTransaction before your loop, you potentially call ->rollback within the loop (so it may be called several times) and finally you call ->commit after the email regardless of if the transaction was already rolled back or not. You need to re-structure the code to ensure you only call ->commit or ->rollback once depending on if errors occurred. For example: $query = " UPDATE carer SET firstname = ':firstname', surname = ':surname', address1 = ':address1', ... WHERE valid_users_id = ':usrid' "; $stmt = $dbh->prepare($query); $stmt->bindParam(':firstname', $bind_firstname, PDO::PARAM_STR); $stmt->bindParam(':surname', $bind_surname, PDO::PARAM_STR); $stmt->bindParam(':address1', $bind_address1, PDO::PARAM_STR); ... $stmt->bindParam(':usrid', $_SESSION['id'], PDO::PARAM_INT); $dbh->beginTransaction(); try { foreach ($_POST['records'] as $data) { //Overwrite the bind_* variables with data from the arrray extract($data, EXTR_PREFIX_ALL, 'bind'); //Run the query $stmt->execute(); } send_mail(...); $dbh->commit(); } catch (PDOException $e){ //Log Error... $dbh->rollback(); }
×
×
  • 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.