oh brother… I finally posted my website just now… that I have been working on for a while and that I have gotten a lot of help with here on the Sitepoint forum (will post address once it’s working…;~)
I get this error:
[site] redirected you too many times....
now I do not get this error in my localhost… this is very upsetting…
so what is wrong, please…
thank you…
PS: this is a typical redirect code:
if ($ss) {
header('Location: page1/photos.php?pn=1&ss=pb');
} else if (!$ss) {
header('Location: page1/photos.php');
}
exit();
Are you trying to redirect the page back to itself? Because that’s most likely where it’s going wrong. If you redirect the same file back to itself, it won’t know what to process. Only the bit of condition you are asking it to which is redirect to itself and/or redirect to a different source which also redirects back to itself. Thus, causing an infinite loop because it can’t go any where.
I partially know what you are doing and I partially don’t. I know that you want to redirect the page if it contains a certain phrase or word, but are you suggesting that if the URL contains itself, that you should redirect it back to itself? See where the infinite loop comes in?
If the user is already on the page, you should validate to see if the page contains the right GET parameters. If it doesn’t, then you would redirect the user to the appropriate page or display a 404 error page.
That’s what I would suggest because they came from an invalid source.
Most likely because you don’t have error log enabled on localhost or you aren’t checking the error log. If you are using a live server and they provide an error log for you and it’s enabled. That’s most likely why you aren’t seeing any errors in your localhost error log. Because it’s not enabled.
Live servers aren’t that different from localhost. The only difference is, some development features are disabled on live servers and production features are disabled on localhost.
They should mirror one another or have very similar configurations.
wait – this problem does not occur in the localhost b/c I don’t have error logs enabled?
well, then I guess I shouldn’t have the error logs enabled in the remote server…;~)
(don’t know how to find error logs either on localhost or in remote server… am new to PHP website… used to have Tomcat/Java… error logs were very easy to find, both locally & on remote server…)
I’m on a mac, it’s an Apache server… it came with the mac out of the box…
I didn’t even have to install anything, just do some configs that I looked up online… it works like a charm… I don’t even have to turn the server on after restarting the computer… (in that sense it’s much simpler than Tomcat… but redirects are much simpler in Java/JSP; I never ever had a problem with redirects in JSP…)
I still don’t get why this is causing a problem only in the remote server…
It’s causing a problem because since you didn’t debug it locally, when you put it online, it will show symptoms of broken code. Sometimes, it could be the live server’s fault, but most of the time, it’s the developer. The reason why one should have error logs enabled both locally and live is because, you can then debug the error if it is the same one. Sometimes, symptoms from live servers should tell you that either you are doing something wrong or your live server doesn’t allow you to use certain functions which isn’t this case.
There seems to be an infinite loop causing your [site] redirected you too many times....
Just a quick Google search already tells me that I am on the right case. Just read this Stack Overflow post.
Just using the key words php redirected you too many times in the Google search box gives me all these fantastic results which basically comes back to my first post of this topic.
An infinite loop
Basically, that’s why I was suspicious with your $ss variable. Also,
} else if (!$ss) {
won’t do anything because it’s basically saying
If the variable $ss is (not?), redirect it to this page.
However, the variable $ss does exist because you’ve declared it manually.
thank you… yes I have also searched a lot and seen some of the same SO threads…
but I still don’t see a solution… how do you do redirects in PHP, then? I mean if you redirect to the same page it’s like reloading the page, no? why would this be a problem? this is never a problem in Java…
and again, how come it works fine in the localhost?
if it works in the localhost it means there will appear no errors in the local error logs… yes???
Is this code above the current file in question? Or is it just in 1 file? You should place it in all files.
As for your first question. No, it only works in localhost when you turn off error logs. When you don’t have error logs enabled, it won’t complain about anything. It will ignore it as if it was executing it like normal.
The simplest way is to start with a fresh file. Try to imitate the same code, but use different wording and logic. Sometimes, the logic may also not work.
} else if (!$ss) {
Is a clear example.
I’ll post a few sample snippets for you to try out in a little bit. I will test them first and provide working snippets.