I have an array of 7 numbers (1,2,3,4,5,6,7) and I want to choose 5 of the numbers like (1,2,3,4,5), (1,2,3,4,6), (1,2,3,4,7). Note that (1,2,3,4,5) is equal to (4,5,3,1,2), so only one of those …
PHP session without cookies
Is there a way that I can initiate a persistent session in PHP without the placement of a session cookie? Are there other ways of maintaining a session across pages, such as an IP address-based …
How insecure is a salted SHA1 compared to a salted SHA512
SHA1 is completely insecure and should be replaced. This question is 8+ years old and times have changed: https://arstechnica.com/information-technology/2017/02/at-deaths-door-for-years-widely-used-sha1-function-is-now-dead/ For passwords: https://en.wikipedia.org/wiki/PBKDF2 For data: SHA3 SHA512 is more com…
Adding days to $Date in PHP
I have a date returned as part of a mySQL query in the form 2010-09-17 I would like to set the variables $Date2 to $Date5 as follows: $Date2 = $Date + 1 $Date3 = $Date + 2 etc.. so that it returns 2010-09-18, 2010-09-19 etc… I have tried but this gives me the date BEFORE $Date. What is the correct
PHP method chaining or fluent interface?
I am using PHP 5 and I’ve heard of a new featured in the object-oriented approach, called ‘method chaining’. What is it exactly? How do I implement it? Answer It’s rather simple, really. You have a series of mutator methods that all return the original (or other) object. That way, you …
Trying to scrape the entire content of a div
I have this project i’m working on and id like to add a really small list of nearby places using facebooks places in an iframe featured from touch.facebook.com I can easily just use touch.facebook.com/…
How to handle user input of invalid UTF-8 characters
I’m looking for a general strategy/advice on how to handle invalid UTF-8 input from users. Even though my web application uses UTF-8, somehow some users enter invalid characters. This causes errors in PHP’s json_encode() and overall seems like a bad idea to have around. W3C I18N FAQ: Multilingual …
In PHP, what does “<<<" represent?
For example: Answer That’s heredoc syntax. You start a heredoc string by putting <<< plus a token of your choice, and terminate it by putting only the token (and nothing else!) on a new line. As a convenience, there is one exception: you are allowed to add a single semicolon after the end delim…
Scraping a messy html website with PHP
I am in the following situation. I am trying to convert a messy scraped html code to a nice and neat xml structure. A partial HTML code of the scraped website: Now I want to create the following xml structure with php: Have been trying the simple html dom method, but have no idea how to get the next sibling
Fastest Way to Serve a File Using PHP
I’m trying to put together a function that receives a file path, identifies what it is, sets the appropriate headers, and serves it just like Apache would. The reason I am doing this is because I need to use PHP to process some information about the request before serving the file. Speed is critical vir…