People who have nowhere to sleep or are about to lose their homes are being turned away illegally by councils, BBC Scotland can reveal.
Local authorities have a legal obligation to find accommodation for people facing homelessness.
Government statistics show that most people are made homeless following a family breakdown or household dispute.
Legal experts told the BBC that people were being unlawfully turned away by councils, despite their statutory duty.
The Legal Services Agency, a charity which provides legal advice to vulnerable people, said last year they saw about 200 people in Glasgow, many of whom had been turned away unlawfully without accommodation or help.
Solicitor Alastair Houston said people were either being told straight away they were not entitled or that there were no temporary places available.
Mr Houston said it was a "breach of their statutory duties" for local authorities to fail to provide temporary accommodation to someone presenting as homeless.
He said council case work staff would often send people to him to get a lawyer's letter threatening the local authority with a judicial review.
"The thinking seems to be that the council will prioritise those who are clutching a legal letter if they don't get the assistance they are entitled to," he said.
What is the law on homelessness?
Any person has a right (under section 28 of the Housing (Scotland) Act) to make a homelessness application to their local authority.
The council will then make inquiries to investigate:
- whether a person is homeless
- whether they are "intentionally homeless"
- whether the person has a local connection
A person has a right (under section 29 of the Housing (Scotland) Act 1987) to temporary accommodation while the local authority is considering their homelessness application.
Freedom of information
People applying for homelessness status are entitled to temporary accommodation while awaiting an assessment on whether they are unintentionally homeless and also while waiting for permanent accommodation to be found.
The law states that a person has a right to make a homeless application and government guidance says they must always be recorded as such if they have a homelessness reason.
This must happen - even if they are also applying for advice under what is known as "Housing Options".
Being recorded as officially homeless ensures the applicant is not missing out on access to temporary accommodation and additional support.
But figures obtained via a series of coordinated freedom of information (FOI) requests reveal that in many cases people with homeless reasons are only recorded under Housing Options.
The figures show a large variation in how many people recorded under Housing Options do not make a homeless application.
In Dundee it is 0% meaning all people are registered homeless as the guidance states they should be.
However, in East Ayrshire last year 87% of those presenting with homelessness reasons were only recorded as asking for advice. They were never registered as officially homeless.
See the table below for a more detailed list of council data.
If people are recorded as "Housing Options", they do not have to be provided with a bed and nor would they show up in homeless statistics.
Housing options is an advice scheme which began in 2010 and is based on prevention of homelessness.
'Fresh start': A case study
After years as an alcoholic and a drug addict, Tam Lyon went into rehab to get clean but his fresh start hit problems when he tried to get rehomed.
Weeks before the end of his six-month rehab, Tam told housing officials he could not go back to his old flat in the west of Glasgow because he owed money to drug dealers who would "do him in".
Tam says his case worker refused to sit down with him, saying if he gave up his flat he would be "intentionally homeless".
However, the law states that a person with accommodation is classed as homeless if occupying it could lead to violence against them.
Tam says he was amazed that after going through a rehab programme costing £26,000 he was being told go back to the place he was trying to get away from.
A spokesman for Glasgow Health and Social Care Partnership said Tam was offered support to help him to return to his home, which was declined.
He said it was later agreed that Tam be provided with "appropriate, alternative accommodation, which he accessed on the day he left residential rehab".
Adam Lang, head of communications and policy at Shelter Scotland, said: "These figures would seem to support Shelter Scotland's long-standing concern that despite world-leading legislation, not every homeless person in Scotland is getting the support and home they need and have a right to.
"While we know that approaches can vary significantly, our frontline advisers tell us this is happening far too often and on a regular basis across Scotland.
"Just last year we had to intervene to support a family in one of Scotland's major cities that had been turned away by the local authority and had to sleep rough in a city centre alleyway with their children.
"This is fundamentally about people not getting the home they have a right to."
Mr Lang said the BBC's analysis prompted further questions about how well homelessness and Housing Options services were delivered.
Homelessness applications have been falling in Scotland.
In the past year there were 34,000 applications but Shelter Scotland is concerned the fall is explained in part by people being recorded under "housing options", masking the problem.
In the same time period, there were 50,000 "housing options" approaches.
Katie Kelly, head of housing and communities for East Ayrshire Council, said: "For the avoidance of any doubt, our ethos and approach to our Housing Options Service provision is not in any way designed to prevent people accessing core housing, housing support and homelessness services."
A spokesman for Glasgow Health and Social Care Partnership said: "Going through the Housing Options process does not in any way prevent someone from making a formal homelessness application.
"In Glasgow, some 58% of people who are assessed through Housing Options are supported to go on and make a homelessness application, which is well above the national average for all local authorities.
"Out of all the major cities in Scotland, Glasgow ranks highest for the number of Housing Options cases that progressed to a formal homelessness application."
The spokesman added: "However, we fully accept there have been issues in relation to access to temporary accommodation.
"We have been working with the Scottish Housing Regulator on a voluntary basis to address these issues and, as a result, we have reviewed and significantly reformed our service to improve the support we provide to those affected by homelessness.
"We have invested £12m in two 30-bedded emergency accommodation units and have been working extensively with social and private landlords to expand the number of temporary homes available to the homelessness service in Glasgow.
"We have also developed a very strong partnership with third sector organisations to ensure we work more effectively with the most chaotic individuals affected by homelessness."
Councillor Elena Whitham, Cosla's community wellbeing spokeswoman, told BBC Scotland: "We know there are variations across councils in the proportions of those who go through the housing options process and are, or are not, recorded as homeless.
"There are good reasons why this happens.
"Some people will either return to or remain in the house they were in, some we simply lose contact with as they find other solutions to the problems they are facing."
She added: "Councils are fully aware of their duty to help those in housing need.
"This includes our statutory duty to investigate and to provide people with any necessary temporary accommodation until that investigation is concluded.
"We have no evidence to suggest there is either a widespread failure to comply with this duty or that anything other than a small number of people have been affected."