This depends on your nationality, your activity in UK, and whether you have previously paid any UK National Insurance contributions.
If you are a national from the European Economic Area (EEA) you will normally be entitled to the same benefits as a UK citizen subject to certain conditions. Some benefits are linked to National Insurance Contributions (NICs) paid by workers (see below), for example Employment Support Allowance, Statutory Maternity Pay and maternity allowance, while other benefits are covered through public funds, such as housing allowance and child benefit. You can find out more from the Department of Work and Pensions.
EURES, the multilingual European Job Mobility Portal has useful information regarding specific benefits in different countries and your entitlements as an EEA national.
If you are from outside the EEA your home country may have a separate agreement with the UK regarding specific social security benefits. You can find a list of these agreements on the Department for Work and Pensions website. Otherwise, your entitlement to social security will depend on whether you are under immigration control. If you are studying in the UK, for example on a Tier 4 (general) student visa, and funded through a grant or bursary, or a Tier 5 visa to undertake training or do research that is supernumerary (ie you are not employed), you are expected to have sufficient funds to meet your own needs and those of any dependents. The same conditions apply to a Tier 1 exceptional talent visa. You will not be entitled to social security, either through public funds or NICs-based benefits. You will, however, have access to free healthcare through the NHS, as will any dependents.
If you are entering the UK on a work visa, for example as a Tier 1 graduate entrepreneur, Tier 1 entrepreneur, or Tier 2 (general) visa for skilled workers, then you will be classed as either self-employed or employed and will pay NICs. This means that you may be entitled to NICs-related benefits such as Employment Support Allowance, Statutory Maternity Pay and maternity allowance if you have paid sufficient NICs over a minimum time period. However, you will not be entitled to publicly funded benefits such as housing allowance or child benefit.
For further information see the HMRC website: Paying UK tax and national insurance and the Department of Work and Pensions website on benefits
See also the UK Immigration rules 6A regarding access to public funds.