A Chinese college has stirred some controversy by putting photographs of seven people on the final exams and asking students to identify the one who is their teacher and write the name underneath. Those who were unable to do so were penalized. The goal was to see who had been attending classes, because apparently skipping classes has become a problem.
Forcing students to attend class by various means such as the above or taking attendance or giving surprise quizzes seems to me to be pointless. Why would you want to force students to attend and have their resentful presence spoiling the atmosphere? I refused to take measures to force attendance even when I was teaching large classes of about 200 students where it would be hard to tell who was skipping classes. I felt that my goal was to ensure that students learned whatever my course objectives were and that my exams should assess whether they had in fact learned them. If they could do so without attending my classes, why should that be a problem? My attitude to teaching was that I should make classes worth attending for their own sake, by providing insights and classroom activities (such as group exercises) that students would benefit from and that they would lose out on by not being there. I never had a problem with absences, in the sense that the lecture halls were almost always full, suggesting that absences were few.
In smaller discussion or seminar classes, where participation was an integral part of the course, students knew they should be there and that their absence was noticeable, so there was no problem with attendance in those classes either.