redirect - creating a <a href> element once an unexpected delay in PHP header redirection occurs? -
i have page form in post method, in user posts z
value, following php page process it, , redirect user accordingly:
<?php { if(isset($_post['z'])){ switch ($_post['z']) { case "a": $url = "http://www.a.com"; break; case "b": $url = "http://www.b.com"; break; default: $url = "http://www.default.com/"; } } header( "refresh:0;url=$url" ); } ?> <!doctype html> <html> <head> <style> .wrap{ margin-top: 25%; } </style> </head> <body> <div class="wrap"> being redirected. </div> </body> </html>
usually seems work ok, today have received complaint visitor said message "you being redirected." kept showing , never redirected.
i saw on server logs tried several times (say him posting form @ least 3 times).
what have caused issue? (the code in form haven't change).
to try handle such cases, i thought giving user option click on
a href
link$url
, want link show after 5 seconds (meaning in general, users never see link, header refresh should occur in 0 seconds). yet want users see message "you being redirected".
a. not sure solve problem, since if problem origin $url
value empty, such link not help.
b. don't want user able see link destination viewing page source, unless fits 5-seconds delay category. therefore don't think using javascript suits here, because it's client side, right? so i'm looking php server side solution - load page now, add a href
element after 5 seconds. there anyway this?
edit: here's form:
<form action="redirect.php" method="post" target="_blank"> <input name="z" type="hidden" value="a"/> <input type="submit" value="go"></form>
assign default value before if
instead of in default:
case:
$url = "http://www.default.com/"; if(isset($_post['z'])){ switch ($_post['z']) { case "a": $url = "http://www.a.com"; break; case "b": $url = "http://www.b.com"; break; } }
this way, if $_post['z']
isn't set reason, they'll still default redirection.
Comments
Post a Comment