-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
There's no reliable way to determine what kind of hosting they are using. They might have a dedicated server and have full control but if they are using something like cpanel it'd probably look like shared hosting from your script's point of view. So, just ask them what kind of hosting they have and then show whatever instructions apply for their selected answer.
-
Reliability of HTTP_ACCEPT_LANGUAGE for browser language detection?
kicken replied to LLLLLLL's topic in PHP Coding Help
You can use it as a starting point. Always give the user a way of overriding the language though.- 1 reply
-
- internationalization
- browser
-
(and 2 more)
Tagged with:
-
<?php ... ?> several times in DIVs or just print it all using php?
kicken replied to appobs's topic in PHP Coding Help
If you're going to use PHP as a template engine, then open and close your tags as necessary as in the first example. That way the HTML is clearly separate and it will be easier to deal with not only as a developer but also for your tools such as the IDE's syntax highlighting, error checking, auto-suggest, etc. If you want to go better, then employ a true template system to separate the PHP code and the HTML code even further. Twig is a nice one that I would recommend. Your second example is poor code in pretty much any situation. -
Some things to do: Use either your browsers developer tools or a tool like Fiddler to inspect the actual request data and ensure the browser is sending all three values in the first place. var_dump($_POST) as the very first thing the script does, even before session_start(). what happens if each checkbox has a different name? post the output of your phpinfo() call, or a link to the phpinfo page for us to see.
-
Refresh part of a page upon successful ajax call
kicken replied to lordterrin's topic in PHP Coding Help
Assuming txtHint is the ID of the div you want to put the content into, then you should be using $('#txtHint'). The # is neccessary. As for details about what .html() is and does, see the jQuery documentation on .html(). Basically it gets/sets the HTML content of the element. This is basically just the non-jquery way to do the same thing, set the HTML content of an element. Basically you need to convert the form to submit via ajax and load the results into your DIV. <form id="startPage" method="POST" action="getuser.php?q=<?php echo $q; ?>"> Page <?= $_SESSION['page'] ?> of <?= $totalPages ?> : <button class="button" type="submit" name="previous" value="<?php echo $prevLimit; ?>">START</button> <button class="button" type="submit" name="next" value="<?php echo $nextLimit; ?>">NEXT</button> </form> <script type="text/javascript"> $('#startPage').on('click', 'button', function(e){ e.preventDefault(); //Cancel traditional submission var url = this.form.action; //'this' refers to the button which was clicked. 'this.form' is the form. var postData = {}; postData[this.name] = this.value; //create post data for the PHP script. $.post(url, postData, function(html){ $('#txtHint').html(html); }, 'html'); }); </script> -
There's no need to write to then read from a file, just capture the output. exec('cat /path/page.log | grep FETAL', $output); foreach ($output as $line){ echo split_row($line); }
-
Basically in whatever script you have that polls for the status of the background job you need to ensure it will detect if the job failed and if so, report any available error information to the user. Within your background jobs, if there is a failure you need to ensure that you log the error messages somewhere that the polling script will be able to later locate them and report them if necessary. The script that kicks off the background job is not the right place to check for processing errors. The only errors you'd get at that point is if the job failed to queue for some reason. Once queued that script will be done, and any further reporting is up to your status polling script. I'm not familiar with the system you are using so I can't really give any specific advice on how to actually implement any error reporting. A quick look at the README file for the project suggests it will report failures so you can probably at least detect if the job failed and let the user know. I'm not sure if it provides a method of providing the details of the failure (in case you want to display that) or if you'll need to find another way to do that.
-
Technically yes, if you run out of Inode's. This seems unlikely however. If you have lots of tiny files, a large block size, and a small inode table it could happen though. Without shell access I can't really recommend much other than make sure you back up everything on the device just in case you have to wipe it and start over. I'm not familiar with that device so not sure what kind of debugging options you'd have.
-
Help me resolve a wierd problem in a FORM with radio buttons
kicken replied to new2you's topic in PHP Coding Help
Use the Direct Input tab on the validator. Load your page in your browser and View-Source. Copy and paste that into the Direct Input tab on the validator and hit validate. It is simply not possible for the code to hit the else block and create the record within the same request with the code shown. Most likely explanations that might cause the behavior are: Your code is being run twice, either in separate requests or in the same request. The code you are showing us does not accurately represent the code you are running. You are incorrectly diagnosing the problem Make sure you are actually seeing the symptoms correctly. For example replace one of your column's value in the INSERT with a fixed value and then see if that value is shown in the table after running the script. Make sure you are not running the script twice. Check your browser's debugging tools for the list of requests it is making. Check your server's access logs for the requests it's receiving. -
It's been a while since I used linux as a desktop OS but from what I remember of the scene at the time, linux was fine for basically two groups of people: - Code Developers - Generic net surfers Linux was lacking in software support for a number of things that they might want to do. Wanna play a game? Good luck. It *might* work in WINE or a VM, but you'll probably still need a copy of windows in either case. Graphics designer and need photoshop? Same story. Wanna watch a commercial blu-ray disc? Can't do it without some hack/work around. If linux is going to make it into general consumer use as a desktop OS it needs better software and it needs to be made easier to use so that all the people with the "just work, dammit!" attitude can use it. On the software side of things, I think one of the biggest problems is the "Free as in freedom" philosophy gets confused with the "Free as in beer" desire. A lot of people have the mentality that all this open source software should not cost any money, which for desktop apps usually results in less appealing software either due to complexity in use or a lack of desired features. Developing a media player which can play commercial blu-ray discs legally for example would be difficult due to licensing requirements. On the ease of use side of things the "Free as in freedom" philosophy can get in the way because developers will create software with an ungodly number of configuration options which few people are ever going to care about or even understand. That's not necessarily a bad thing but for your average "just work" user if they open the preferences dialog and see a thousand options they are not going to sit there and sift through every one and figure out what it does. All they want are a few standard options that people are actually likely to want to change. Everything else should just be set to reasonable defaults and hidden away somewhere. Some applications have gotten the options thing down fairly well, for example Mozilla's software only shows common options in the GUI dialog. Everything else is hidden away in the about:config page. VLC has a simplified options dialog by default, with the ability to switch into an advanced mode that shows everything. As I said, it's been a while so the landscape may have improved some. That's just what I noticed at the time that I was using it. All that said I think probably there are two main things someone could do to help get Linux desktops more grounds is: Emphasis that the "Free as in freedom" philosophy is not synonymous with "Free as in beer". You have to be willing to pay some money for good software, either as donations to the various projects or directly from a commercial vendor. Help projects develop simple, "grandma friendly" user interfaces either through suggestions or code contributions if you are able to.
-
MySQL exact equivalent of the PHP "time()" function
kicken replied to roparzhhemon237's topic in PHP Coding Help
As mentioned, using UNIX_TIMESTAMP with an INT column adds some extra processing to the work that needs to be done. It also makes the data less readable if you need to get in and view DB records directly. For example say you are debugging some code and need to browse the DB data. Which would you rather see in the date field: '1414690620' or '2014-10-30 13:37:00'? The best solution when it comes to storing the current datetime into a database is to use a DATETIME field, and use the function UTC_TIMESTAMP(). This gives you a readable format that can be easily manipulated with mysql's date and time functions. The value is also unaffected by the server's timezone setting and is always stored in UTC time meaning it is easy to convert between timezones should you want to do that (such as let users customize their timezone). -
MySQL exact equivalent of the PHP "time()" function
kicken replied to roparzhhemon237's topic in PHP Coding Help
Probably as a result of how you are using it. If you store the value in mysql in the 'YYYY-MM-DD HH:MM:SS' format but then type cast it to an INT in PHP after selecting it, you would observe this behavior. $value = '2014-10-30 12:33:00'; //As would be returned by a query $date = (int)$value; var_dump($date); //int(2014); -
You could format the date client-side using either the built in Date object, or a library like Moment.js. If you don't mind adding another library to your page, I'd take the library route and format it client side. Otherwise I would probably just formatted it server-side and return it either along with or instead of the current date format you have, depending on your needs.
-
Hit page without actually going to page that's NOT on your domain?
kicken replied to mouseywings's topic in PHP Coding Help
You cannot use XMLHttpRequest (Ajax) to contact an external website without their cooperation. Either they need to allow it by setting the appropriate headers or they need to provide an alternative such as JSONP. What you can do is proxy the request via your server by using PHP and cURL to contact the other site then having your Ajax code communicate with your PHP script instead of the other site directly. -
Are donations to specific users okay?
kicken replied to Monkuar's topic in PHPFreaks.com Website Feedback
It's fine if you want to send a little money someone's way. If there isn't anything in their signature regarding donations/tips then a quick PM to them asking if they would accept a tip and via what means would be ok. -
When someone wants to use the service, generate a random access token for them to use when requesting the data. On each request to your API require them to include the token and check if it is valid before returning any data. If later they do not pay then you can simply invalidate the token.
-
How best to send PHP data to a JavaScript client
kicken replied to NotionCommotion's topic in PHP Coding Help
You don't. Whatever parts of the other script need myObj will have to be wrapped in an accessor function which executes a callback once the data is loaded. When called the first time there may be a slight dely but any subsequent calls would just use cached data and run the call back immediately. (function(){ var myObj; var $xhr = $.get('someSlowURL.php', 'json').done(function(jsonObj){ myObj = jsonObj; }); window.getData = function(cb){ $xhr.done(function(){ cb(myObj); }); }; }()); //Later on: getData(function(data){ //Access data }); The above creates an Immediately Invoked Function which creates the XHR request to load the data and when complete assigns it to the myObj variable. Then it creates a global function called getData which accepts a callback. That function will take that callback and execute it when the XHR request is complete and pass the myObj variable as the first argument. For more information about the .done() method being used, look at jQuery's Deferred Object api. -
It can be done using CSS by separating the head/body with the appropriate <thead> and <tbody> tags, then applying overflow, height, and positioning directives as needed. Last I checked (which was a while ago admittedly) this approach had issues across different browsers. A more popular solution is to render two tables, one that contains only the headers and another inside a scrollable div with the contents. You need to specify a width for each column with this approach so that the header and body columns match. Google for HTML Table fixed header or similar terms and you can find lots of solutions.
-
How best to send PHP data to a JavaScript client
kicken replied to NotionCommotion's topic in PHP Coding Help
If you're going to just put in a script tag then you need to output JS code not just a simple JSON string. The other alternative would be to request the data with AJAX and parse the JSON and assign the result. What are you ultimately trying to accomplish? -
If all the paths are relative, it should be loading everything from https:// as well. Make sure you are not specifying an absolute (beginning with http://) path anywhere and that the page does not have a <base href=""> pointing to a http:// path.
-
It writes out the session data to storage and then closes it. What exactly it does depends on the backend you are using for sessions. For the default file-based sessions what it does is write the contents of $_SESSION to the file, closes the file, and releases the lock. PHP will do this automatically at the end of the script, however there may be instances in which you want to do it earlier so the function is there for you to use if desired.
-
Making a secure delete button (best way?)
kicken replied to anderson_catchme's topic in PHP Coding Help
If you're using Symfony 2 (or willing to switch) there is FOSUserBundle which is commonly used. It's not a drop-in ready system but it provides a solid base which you can use with fairly minimal configuration/coding required. -
Kudos to Psycho - But One Baffling Question Remaining
kicken replied to spock9458's topic in PHP Coding Help
You don't have to have an else branch with duplicated code. All you need to do is make the code listing the company details unconditional foreach($company_array as $company) { if ($company['county'] != $current_county){ { ///print header $current_county=$company_county; } //Print company information } Only the header is wrapped in the if condition so it will only print when the county changes. The rest of the code to print the company details is unconditional and executes on each loop. -
They use Javascript to take what you enter into the boxes and generate the new URL, then re-direct you to that new URL. After that they probably use something like mod_rewrite to map the URL to a script which extracts the parts and does the work. It you look up search engine friendly URL's you will find some information about how to setup the necessary re-writes.
-
Given the structure you showed above the path would be: $array["84EA0353-58EB-E311-A8B1-001D09E7525D"][0]->data['amt']