Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. Windows has a task scheduler application that lets you setup the equivalent of a cron job. You can make a simple batch file that calls the windows ftp command line client. If you open up a cmd window and type ftp --help you'll see something like this: C:\Users\David>ftp --help Transfers files to and from a computer running an FTP server service (sometimes called a daemon). Ftp can be used interactively. FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvb fer] [-b:asyncbuffers] [-w:windowsize] [host] -v Suppresses display of remote server responses. -n Suppresses auto-login upon initial connection. -i Turns off interactive prompting during multiple file transfers. -d Enables debugging. -g Disables filename globbing (see GLOB command). -s:filename Specifies a text file containing FTP commands; the commands will automatically run after FTP starts. -a Use any local interface when binding data connection. -A login as anonymous. -x:send sockbuf Overrides the default SO_SNDBUF size of 8192. -r:recv sockbuf Overrides the default SO_RCVBUF size of 8192. -b:async count Overrides the default async count of 3 -w:windowsize Overrides the default transfer buffer size of 65535. host Specifies the host name or IP address of the remote host to connect to. Notes: - mget and mput commands take y/n/q for yes/no/quit. - Use Control-C to abort commands. The two important arguments to notice are -n and -s. You can use the -n to turn off the automatic login attempt and the -s to specify a file of commands to be automatically run. So you can make a simple batch file that starts ftp with these parameters and a file that has the commands to PUT the file on the ftp server. ftpfile.bat ftp -n -s:ftp.txt ftp.server.com ftp.txt user yourusername ftpuserpassword binary literal pasv put thefilename.txt quit Then setup this batch file to be called in the windows scheduler application. This is a simple barebones solution which admittedly has absolutely no error checking, but it will get the job done in most cases. There are scores of more robust solutions out there, but a lot might be overkill for what you're doing.
  2. No. There is nothing magic about a session variable, other than the fact that it is serialized out to storage when it gets set, and this serialized version gets read into memory with session_start(). Exactly what that variable contains is up to the programmer. In this case, the assumption is that the OP has a routine that counts the number of message that have not been marked as seen/read. Like any form of "caching" the value needs to be invalidated/updated anytime something happens that would change that. Like all caching, you have a tradeoff between performance and accuracy. The only problem with this system is that a user will not be notified of new messages that are sent during the duration of the session, although this could be mitigated by adding in a timing feature, that insures that the "getunreadmessagecount" routine gets called again if a certain amount of time has gone by. This could be designed to occur every 3-5 minutes, and for a high traffic site with a lot of users the savings on database queries could be significant. In my opinion, a memcache based design is superior, since the cached entry can be invalidated whenever a message is read OR sent to a particular user.
  3. I think it's clearly established already that OP already has a login system and is using sessions, so your comment about "sessions going away" is completely irrelevant. If the session "went away" then the user will no longer be logged in.
  4. I can't speak to what else you have in the session, but something like that is the perfect use of a session variable. Another alternative is to cache the data in an in-memory cache like apc or memcache.
  5. Of course. What operating system is your computer running?
  6. I'd suggest you have your connectdatabase() function return an array: array('type' = $type, $dbh = //database handle ); The trick with resource variables is that you need to pass them by reference rather than value, so you'd need to return this array by reference. $con = array(); $con['type'] = $type; //.... make connection and assign $con['dbh'] = mysql_connect($server, $username, $password); // // At the end return $con. return &$con; For your query function(s) specify that the $con array will be passed by reference as well. function query(&$con) { } FWIW, this is a good argument for why PHP Oop can be helpful, and in particular having a singleton registry object is a helpful design pattern.
  7. The 2 functions are identitcal, with the only exception being that htmlspecialchars only converts a small subset of characters to their html entity equivalent. It is basically a safety function for preventing attempted xss or sql injections. htmlentities converts any character that has an html entity equivalent.
  8. Basically, but you can simplify it... I'd do something more along the lines of: for ($try=1; $try $myfile = file_get_contents("http://example.com"); if ($myfile) { break; } sleep(3); }
  9. A for loop executes until the condition part of the loop is met. You can use break to exit the loop immediately, so you could use your for loop, and inside the loop if your function is successful, break out immediately.
  10. phpinfo(); Point to this -- what do you see?
  11. You would help everyone out including yourself, if you did a better job describing your problem. Yes you had the wrong syntax, but your question didn't indicate that you'd tried anything and had a problem-- instead it asked: "How do I do this?"
  12. Ditto. Glad to hear that this has been a valuable resource for you.
  13. query and fetch the column into a variable. Then use your explode. What is the confusion, you already described exactly what you need to do along with the function you need to do it.
  14. http://dioscouri.com/index.php?option=com_ambrasubs&view=categories&categoryid=46&Itemid=43
  15. Here's a heredoc. Heredocs interpolate variables in the same way that using the double quotes does. $golfers = implode("\",\"",$golfers); $js =<br /> var jsgolfers = ["$golfers"];<br /> <br /> function gn(str)<br /> {<br /> alert(jsgolfers[str]);<br /> }<br /> JS; echo $js; Eliminates all the annoying quoting, and escaping etc.
  16. As an aside, when I need to output js from php I will either include it, or use a Heredoc. The code you provided is not valid php, so I'm not confident in answering your question, when I don't know what the real code is. For example, you have echo statements (php) and then you start a new php section right in the middle of what is already php. That code would cause an error.
  17. As for session -- you want the session to be valid for your entire domain. It will survive the transition from http to https. When you configure the vhost for ssl, simply have it map to the same docroot in the same way as your normal site. You will then have the ability to serve up the same files as either http or https. The only problem comes if you hardcoded urls into things, but since you are using a framework that should have url helpers i don't see that should be a concern. I have never used CI so I can't speak to that specifically, but other people who frequent the site probably have so you can always make another thread indicating a CI specific question and probably will get a more specific answer on that. The cpanel is going to automate making a self signed cert. That is not acceptable for a website that is doing eccomerce. You will need to pay for a cert from a real Certificate Authority. In layman's terms, when you have a cert, it need to be cryptographically "signed" by a "certificate authority". Browsers come with a pre-configured list of known CA's. When you start an SSL connection and the certificate gets sent to the browser, a little handshake occurs where the browser checks with the CA to get check that they issued it, and that all the information matches. The browsers are all configured to squawk if anything is amiss, and they will always display a message for self signed certificates (where you act as your own "unofficial" CA and generate all the cert and "sign" it, because you are not one of the official CA's that the browsers ship with. When you buy a real certificate, there is a process involved where you have to provide information to the CA that identifies your business, and in general allows them to vouch for your entity. This is part of the process in terms of ecommerce, and purely from a technical standpoint is key to preventing "man in the middle" exploits.
  18. sunfighter and Nightslyr both pretty much nailed it. I like to describe PHP as having "page scope". A page (script) runs in the server environment, creates allocates memory/creates variables etc, executes, and destroys everything upon completion -- which is done as quickly as possible, and i the web context, is completed at the point that the HTTP response has been sent to the client. If you want to persist data, you need to use files, or a database, or a memory cache, or something else that exists outside of php. Java in particular is often used due to its common support for application servers, where you can make pojos or ejb's that can exist independently of what is going on in the web layer. Yes you can persist data in session variables. This shouldn't be overused in my opinion. Session variables have to be serialized when changed or added to (by default to files on the web server) and unserialized on every request. One important concept to understand, is that of PHP resource variables. These are in general, handles, connections and other variables that are often used by php to provide an interface to client libraries or other external libraries. They are special, and can not survive the serialization/unserialization process.
  19. I'm not sure what this has to do with Oop vs. procedural. The mechanics of "return" are the same. You can return a single variable, however that is not a limitation, as the variable can be any of the php types, including objects themselves. The simple answer here would be to return an array with both the items you need in it. return array('tickers' => $tickers, 'stocklist' => $stockList);
  20. This is a big reason why people don't use mysqli -- it's tedious, because you have to bind a variable to every column in your result set. In your case, you are only selecting one column and returning one so it's no big deal, but this is why a lot of people use PDO instead, when they want the advantages of bind variables, but desire the flexibility of the old mysql api. As requinix stated, you made the "bind" to the $profissao variable. What that "binding" does, is make a sort of contract between mysql for the fetch. Whenever you fetch a row, the value for the column will be put into the $profissao variable. All you really need to change is this line: 'label' => $row['profissao'] And make it: 'label' => $profissao;
  21. Yeah I had a bug in there.. i just type this stuff in and don't really test it usually. Do exactly what requinix wrote in his reply for the outer while loop. while ($row = mysql_fetch_array($data)) { $arr[$row['id']] = array($row['name'], $row['amount']); var_dump($arr); echo ' '; }
  22. No you are not wrong, that is often what people do --> build the cart and then only send them to https on checkout. If it is cleaner for you to keep the https scripts inside a particular directory that is fine. But again, the https server is in essence a totally different apache vhost with its own configuration section. The important thing described above, is that you can't mix http and https served elements on the same page without getting a bunch of obtrusive warnings, so you need to make sure that everything on your page (every .js, .css or image) is being served through https. This is what he was referrring to. For this reason it's probably going to be undesirable to have 2 copies of all those assets just so you can have them in a directory that you consider https:// only stuff. You could however put the scripts there, and it might not be a bad idea, in that if anyone attempts to access those items using http:// you use a rule in the .htaccess file to redirect them to https://. Quite honestly there is a lot of different techniques possible, and a fair degree of complexity. Step 1 is just to get the https server configured properly. If you're doing commerce then you'll need to buy a real certificate from an established cert vendor, and configure you apache. If this is for an internal system or intranet application you can get by with a self signed cert. Get everything configured so that your whole site will come up under either http or https and then go from there, in worrying about these other issues until you have that working.
  23. You are aware of https:// and what that does? This is more of a system administration and website configuration exercise.
  24. You can explicitly apply a write lock to the table. It will limit concurrency, but has the effect of serializing things in the way you desire.
  25. It's a deprecated (but still supported) switch that means CLI mode. With older versions (like 4) PHP would spit out HTTP headers, even when run from the command line. The -q flag disabled that. So it does, interesting that it's not listed when you do php --help.
×
×
  • 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.