I did something that does that when people land on my page for the first time, they get a JavaScript redirection to the same page, but with PHP $_GET URL queries, then this page redirect back to the page without these queries, so the server got the screen's size of the client during this process. The thing is that this redirection is done in JavaScript client-side, so I wonder if it could hurt my website's SEO in some ways (continue reading).Here are solutions that I think could be good, but I'm not sure about what to do and what will happen if I do that. I dont really know how Google scan sites, so I may be wrong: Should I put this JavaScript redirect at the bottom of my page's code, so Google will have the time to scan my entire page before being redirected?Should I put this JavaScript code in the <head> of the page so that there will be no waiting before the redirect is done, so human clients will be satisfied to not have to wait some milliseconds more, but Google will scan the second page instead of the first, or will incompletely scan the first?Should I detect with PHP whether or not I should echo this JavaScript code based on the type of the visitor (human or not). If this is what I should do, how to do it simply? This is important, as this JavaScript code is on each page and is echoed in PHP each time someone (or a robot) visits the site for the first time. 
How to do a JavaScript redirection to the same page without hurting my SEO?
php;javascript;seo;web crawlers
Your solution here is very misguided for several reasons, mainly that the user's browser must make not one, but three separate requests for the same page. That's tripling your traffic and greatly slowing down the user. You are also passing information back and forth many times between PHP and JavaScript which you simply do not need to do.If you are showing images in a lightbox style popup on the page then there is no need for any server-side interaction at all. JavaScript can detect the browser width and request a different image instead.Perhaps you would be better off looking for a pre-built lightbox plugin. Just search for JavaScript lightbox plugin and you will find hundreds of different ones. Many of them include an explicit showImage function, so you can attach a click event handler to the link/thumbnail, and in that handler check the screen width and either open the image directly or call the lightbox plugin.