I have used the fancyhdr package to customize the header of my pages. However, when I want a page to be landscape (by using the pdflscape package), it does produce a page in landscape orientation, but the header is on the right side of the page (see attached picture). I am using the article document class. Here is my code:
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\sectionmark}[1]{\markboth{\thesection.\ #1}{}}
\lhead{\leftmark} %section
\rhead{\thepage} %page number
\newpage
\begin{landscape}
\subsection{asdasd}
\end{landscape}
How can I move the header to the top of the page?

@grimler solved the problem with rotation of the header but now the pictures cannot be in the center and the margines of the landscape page is not symmetric
\documentclass[12pt]{article}
\usepackage[left=2cm, right=2cm, bottom=2cm, top=3cm]{geometry}
\geometry{letterpaper}
\begin{document}
\section{Nima}
\subsection{aaaaaaaaaaaaa}
\lipsum[1]
\begin{figure}[H]
\centering
\includegraphics[width=0.5\linewidth]{male.jpg}
\caption{Example of a forward looking algorithm that identifies peaks \& troughs.}
\label{fig:old_zig_1}
\end{figure}
\newpage
\paperwidth=\pdfpageheight
\paperheight=\pdfpagewidth
\pdfpageheight=\paperheight
\pdfpagewidth=\paperwidth
\headwidth=\textheight
\begingroup
\vsize=\textwidth
\hsize=\textheight
\begin{figure}[H]
\begin{center}
\includegraphics[width=0.4\linewidth]{male.jpg}
\end{center}
\caption{Example of a forward looking algorithm that identifies peaks \& troughs.}
\label{fig:old_zig_1}
\end{figure}
\endgroup


\begin{center}\includegraphics[]{male.jpg}\end{center}then centering works fine. (But you don't get a caption and label). The reason for the asymmetric margins is your\usepackage[left=2cm, right=2cm, bottom=2cm, top=3cm]{geometry}line. We have tilted the page and this makes the right margin 1 cm longer than the other margins. To fix it, add\addtolength{\textheight}{1cm}before the\headwidth=\textheightline. – May 15 '15 at 10:51\addtolength{\textheight}{1cm}line, be sure to\addtolength{\textheight}{-1cm}afterwards, else you get a blank page when going back to portrait mode. – tb87 Oct 26 '21 at 03:38