Creating a timestamped URL, a space between date and time breaks the URL

I am working on the first version of PHP and MySql and I have this issue with date / timestamp. I am going to make a URL with a date as a GET parameter. But when the date is returned from the database (timestamp type), there is a space between the date and time, so the URL is interrupted.

How can I format the date to include in the url (along with the rest of the parameters)?

+4
source share
2 answers

Use urlencode . This will encode all URL-reversal characters so that they can pass URLs safely.

Also, consider passing the date in a different format, since regular urlencoded datetimes may look a little ugly. Instead, you can use timestamps. For example, compare these two URLs that have the same dates:

http://www.domain.com/index.php?date=2010-02-09%2018:06:20

http://www.domain.com/index.php?date=1265731567

Alternatively, you can use a custom format, typically YYYYMMDDHHIISS , which will result in the following URLs:

http://www.domain.com/index.php?date=2010020920180620

The timestamp format is one that works with PHP date functions without the need for additional parsing, so I would suggest using this instead.

+2
source

Source: https://habr.com/ru/post/1300767/


All Articles