The error is telling you that the header call you have on line 507 could not be executed because of output that occurred on line 51. This almost always occurs because of white space that is outside of the php blocks, so if you have any spaces or returns that are outside of the php block that you added it can cause this problem.