But language does not always keep to the tramlines of strict logic, and it is quite common to find attached phrases applying to some other part of the main clause (here, the 'I' implied by my head). Such phrases usually contain participles: they are called dangling participles, or hanging participles, or unattached participles. In the sentence above, the dangling participle is a present participle walking, but you can also have a dangling past participle: If properly secured, you shouldn't be able to remove the cover.
Dangling participles are not considered acceptable in standard English, so they should be avoided in writing. Recast offending sentences so that the subject of the attached phrase is clear: As I was walking back home yesterday a tree nearly fell on my head; If the cover is properly secured, you shouldn't be able to remove it.