To start with, we start with Lagrangian mechanics. Lagrangian mechanics states that the variation of the “action” with respect to every dynamical variable is zero.
Suppose the action can be written in the form
$$S=\int Ld\tau d\sigma$$
Then standard variational methods give the Euler-Lagrange equation
$$\frac{\partial L}{\partial x}=\frac{\partial}{\partial\tau}\frac{\partial L}{\partial \frac{\partial x}{\partial \tau}}+\frac{\partial}{\partial\sigma}\frac{\partial L}{\partial \frac{\partial x}{\partial \sigma}}$$
For brevity, we will henceforth abbreviate $\frac{\partial}{\partial \tau}=\partial_\tau$ and $\frac{\partial}{\partial\sigma}=\partial_\sigma$.
Next, let’s suppose there is only one dynamical variable $x$. Then we introduce the canonical conjugates $p^\tau=\frac{\partial L}{\partial_\tau x}$ and $p^\sigma=\frac{\partial L}{\partial_\sigma x}$.
Then form the Hamiltonian
$$H=p^\tau\partial_\tau x+p^\sigma\partial_\sigma x-L$$
Next, calculate the total differential of the Hamiltonian
$$dH=-\frac{\partial L}{\partial x}dx+\partial_\tau xdp^\tau+\partial_\sigma xdp^\sigma=\frac{\partial H}{\partial x}dx+\frac{\partial H}{\partial p^\tau}dp^\tau+\frac{\partial H}{\partial p^\sigma}dp^\sigma$$
Note that these equations still leve many degrees of freedom. This is to be expected, as if $S$ is invariant under diffeomorphisms of $\tau$ and $\sigma$, the resulting equations should be, too. Thus we should not expect the equations to determine the resulting values of $x$ and $p$.
The classical dynamics of string theory
Now we apply this to string theory (where else would you have two times?) Bosonic string theory contains a “worldsheet metric” $h_{ab}$ and a spacetime vector $X$. $h_{ab}$ has an inverse denoted $h^{ab}$ satisfying $h_{a\tau}h^{b\tau}+h_{a\sigma}h^{b\sigma}=\delta^a_b$.
For brevity, we denote worldsheet vector indexes ($\tau$ and $\sigma$) by $a$, $b$, $\ldots$, and we use vector notation to exclusively refer to spacetime vectors. Furthermore, we use the Einstein repeated index convention. Then we can write down the Polyakov action for string theory:
$$S=\int\frac{T}{2}\sqrt{-\det h}h^{ab}\partial_a X\cdot\partial_bXd\tau d\sigma$$
Next, we calculate the canonical conjugate of all the dynamical variables. Denote the conjugate of $h_{ab}$ as $r^{ab}$ and the conjugate of $X$ as $P$:
$$r^{ab\tau}=r^{ab\sigma}=0$$
$$P^a=T\sqrt{-\det h}\partial^a X^\prime$$
where $X^\prime$ is the covariant version of $X$.
Note that the conjugates of $h$ are zero. This implies the resulting theory has a Hamiltonian constraint.
Hext, form the Polyakov Hamiltonian
$$H=P^a\cdot \partial_a X+r^{abc}\partial_ch_{ab}-\frac{T}{2}\sqrt{-\det h}h^{ab}\partial_a X\cdot\partial_b X$$
and then eliminate the derivatives on $X$ by $\partial_a X=\frac{1}{T\sqrt{-\det h}}P_a$ so that
$$H=\frac{1}{2T\sqrt{-\det h}}P^a\cdot P_a+r^{abc}\partial_ch_{ab}$$
To find the Hamiltonian constraint, use Hamilton’s equation
$$\frac{\partial H}{\partial h_{ab}}=-\partial_c r^{abc}$$
together with $r^{abc}=0$, which leads to the equation
$$-\frac{1}{4\sqrt {-\det h}}h^{ab}P^c\cdot P_c+\frac{1}{2\sqrt{-\det h}}P^a\cdot P^b=0$$
Therefore $h^{ab}P^c\cdot P_c-2P^a\cdot P^b=0$
Next, vary with respect to $X$, producing
$$-\partial_c P^c=0$$
And finally, with respect to $P^a$, to yield:
$$\partial_a X=\frac{1}{T\sqrt {-\det h}}P_a$$