Hungary's parliament has approved the automatic detention of all asylum seekers in container camps at the country's southern borders, despite a fierce backlash from human rights groups.

Under the new legislation, asylum seekers entering Hungary and those already in the country will be detained or moved to the container camps.

Earlier this year, Prime Minister Viktor Orban said the measure was needed as a response to "terror" attacks in Europe, citing the November 2015 attacks in Paris.

IN PICTURES: Refugees stranded on Serbia-Hungary border amid winter

The move reinstates Hungary's practice of detaining asylum applicants, which it suspended in 2013 under pressure from human rights groups.

Measure 'violates' international law

The UN High Commissioner for Refugees, or UNHCR, immediately criticised the measure.

"This new law violates Hungary's obligations under international and EU laws, and will have a terrible physical and psychological impact on women, children and men who have already greatly suffered," the UNHCR said in a statement.

On Tuesday, Orban ordered the reinforcement of fences on the country's southern border.

Work began last week on a second border fence and the right-wing government extended a state of emergency that gave authorities additional powers to secure the borders. Hungary had previously built a fence on its borders with Serbia and Croatia in September 2015.

READ MORE: Toxic fear mongering pushing back human rights, Amnesty

In October last year, the majority of Hungarians voted against an EU referendum aimed at sharing 160,000 refugees around the 28-member bloc through mandatory quotas.

It has since not accepted any asylum seekers allocated under the scheme.

Hungary granted asylum, or some form of protection, to 425 people out of 29,432 applications in 2016. 

Source: Al Jazeera and news agencies