I have a PHP app that creates a CSV file which is forced to download using headers. Here’s the relevant part of the code: What I’d like to do is redirect users to a new page after the file is built and the download prompt is sent. Just adding header(“Location: /newpage”) to the end didn’t work, expectedly, so I’m not
Tag: php
is_file or file_exists in PHP
I need to check if a file is on HDD at a specified location ($path.$file_name). Which is the difference between is_file() and file_exists() functions and which is better/faster to use in PHP? Answer is_file() will return false if the given path points to a directory. file_exists() will return true if the given path points to a valid file or directory.
PHP equivalent of send and getattr?
If Ruby gets invited to a party and brings: .. and Python gets invited to the same party and brings: .. what does PHP have to bring to the party? Bonus question: If Ruby and Python got jealous of PHP’s party-favors, what English terms would they search for in PHP’s documentation in order to talk about it behind PHP’s back?
PHP “pretty print” HTML (not Tidy)
I’m using the DOM extension in PHP to build some HTML documents, and I want the output to be formatted nicely (with new lines and indentation) so that it’s readable, however, from the many tests I’ve …
What’s the point of using wordy Time Zones?
I know this isn’t specific to PHP, but what’s the point of using timezones listed like this :http://us2.php.net/manual/en/timezones.america.php? For example “America/Indianapolis” and “America/…
Are singleline if statements or if statements without braces bad practice?
I was told that the first instance wasn’t a good idea. I have no idea whether this is really this case (or for the second one either); does it not shorten the amount to type? Or is it because it just makes a mess? Answer The best practice is to write code that others can read and update easily. Your
MySQL query to extract first word from a field
I would like to run a query that returns the first word only from a particular field, this field has multiple words separated by spaces, I assume I may need to carry out some regex work to accomplish this? I know how to do this using a few ways in PHP but this would best be carried out on the
how to detect search engine bots with php?
How can one detect the search engine bots using php? Answer Here’s a Search Engine Directory of Spider names Then you use $_SERVER[‘HTTP_USER_AGENT’]; to check if the agent is said spider.
How to solve “Fatal error: Class ‘MySQLi’ not found”?
I am doing a tutorial and am getting this error: Fatal error: Class ‘MySQLi’ not found (LONG URL) on line 8 The code on line 8 is: $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name); …
Combine PHP prepared statments with LIKE
Anyone know how to combine PHP prepared statements with LIKE? i.e. “SELECT * FROM table WHERE name LIKE %?%”; Answer The % signs need to go in the variable that you assign to the parameter, instead of in the query. I don’t know if you’re using mysqli or PDO, but with PDO it would be something like: For mysqli user