Definition: An on-shell constant of motion $F(q,p,t)$ satisfies$^1$
$$ \frac{dF}{dt}~\approx~0~\text{for all initial conditions and configurations}.\tag{1}$$
[Here the $\approx$ symbol means equality modulo Hamilton's equations of motion (HEOM). On-shell (in this context) means that the HEOM are satisfied.] Notice for later that the lhs. of eq. (1) in principle is a function of $q$, $p$, $\dot{q}$, $\dot{p}$ and $t$.
Definition: An off-shell constant of motion $F(q,p,t)$ satisfies
$$ \{F,H\}_{PB}+\frac{\partial F}{\partial t} ~\equiv~ 0 \tag{2}$$
off-shell.
Proposition: The two definitions are equivalent: Def. 1 $\Leftrightarrow$ Def. 2.
$\Leftarrow$ proof of Proposition: Use HEOM. $\Box$
$\Rightarrow$ proof of Proposition: Note that the lhs. of eq. (2) does not depend on $\dot{q}$ and $\dot{p}$. So if it is zero with the help of HEOM, it is also zero without. $\Box$
Refs. 1 and 2 do not explicitly stress that eq. (1) should be satisfied for all initial conditions, not just under special circumstances, but this is essential if one wants to have equivalence with eq. (2).
- Finally, as an important application, let us mention that the off-shell condition (2) is the condition that is actually used in the proof of Poisson's theorem (together with the Jacobi identity):
Poisson's Theorem: If $F$ and $G$ are off-shell constants of motion, then the Poisson bracket $\{F,G\}_{PB}$ is an off-shell constant of motion.
- To see an example of what can go wrong if eq. (1) is not satisfied for all initial conditions, see e.g. my Phys.SE answer here.
References:
H. Goldstein, Classical Mechanics; Eq. (9.97).
L.D. Landau & E.M. Lifshitz, Mechanics, vol. 1, 1976; Eq. (42.3). [Note that Ref. 2 confusingly calls a constant of motion for an integral of motion. According to Wikipedia, an integral of motion is a constant of motion without explicit time dependence.]
P.J. Olver, Applications of Lie Groups to Differential Equations, 1993; p. 264.
--
$^1$ Note that Ref. 1 calls an off-shell condition of the form $$\frac{dF}{dt}~\equiv ~0\tag{3}$$ a trivial conservation law of 2nd kind. Assuming that $F(q,p,t)$ does not depend on time derivatives the condition (3) can only occur iff $F$ is a constant that is independent of $q$, $p$ and $t$.