MushMX Posted September 11, 2023 Share Posted September 11, 2023 Hi i need to perform an automatic redirect. sp when the page loads, automatically redirect to another one by using a special function: ?dashboard=user&page=member&tab=viewmember&action=view&member_id=<?php echo esc_attr($retrieved_data->ID);?> but i dont know how can figure out this any ideas? best regards Quote Link to comment https://forums.phpfreaks.com/topic/317274-redirect-using-special-function/ Share on other sites More sharing options...
requinix Posted September 11, 2023 Share Posted September 11, 2023 Why load the first page at all if you're just going to redirect them immediately anyway? Don't send them back to the first page. Send them directly to the second page instead. Quote Link to comment https://forums.phpfreaks.com/topic/317274-redirect-using-special-function/#findComment-1611736 Share on other sites More sharing options...
MushMX Posted September 11, 2023 Author Share Posted September 11, 2023 11 minutes ago, requinix said: Why load the first page at all if you're just going to redirect them immediately anyway? Don't send them back to the first page. Send them directly to the second page instead. requires member id and can only be retrieved from a page first, there's non a static link changes depending on the member id Quote Link to comment https://forums.phpfreaks.com/topic/317274-redirect-using-special-function/#findComment-1611737 Share on other sites More sharing options...
requinix Posted September 11, 2023 Share Posted September 11, 2023 I mean 2 hours ago, MushMX said: Hi i need to perform an automatic redirect. sp when the page loads, automatically redirect to another one by using a special function: That page. The one you're talking about "when it loads". I'm saying, don't load that page. Ones before it fine, but instead of "when the page loads I want them to redirect somewhere else" you should do "don't load that page and instead do the redirect at that moment". If that's not making sense, and there's a good chance it doesn't, then please explain more about what "pages" you're talking about. Quote Link to comment https://forums.phpfreaks.com/topic/317274-redirect-using-special-function/#findComment-1611738 Share on other sites More sharing options...
MushMX Posted September 11, 2023 Author Share Posted September 11, 2023 Just now, requinix said: I mean That page. The one you're talking about "when it loads". I'm saying, don't load that page. Ones before it fine, but instead of "when the page loads I want them to redirect somewhere else" you should do "don't load that page and instead do the redirect at that moment". If that's not making sense, and there's a good chance it doesn't, then please explain more about what "pages" you're talking about. Ill figure out with a javascript function (set on the properly site on the code in order to avoid a infinite loop) This is the solution: Hyper link class with ID name in order to we can call it with a function. The original page loads, and retrieve the ID that we need. Then wild script appears and "click" the link quickly, then load the page automatically performing the redirect and that's all, many thanks for the interest. <a class="color_black" id="btn" href="?dashboard=user&page=member&tab=viewmember&action=view&member_id=<?php echo esc_attr($retrieved_data->ID)?>"> <script> window.onload = function(){ document.getElementById('btn').click(); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/317274-redirect-using-special-function/#findComment-1611739 Share on other sites More sharing options...
Solution requinix Posted September 11, 2023 Solution Share Posted September 11, 2023 Okay yeah no, you're missing the point. Look at this: <a class="color_black" id="btn" href="?dashboard=user&page=member&tab=viewmember&action=view&member_id=<?php echo esc_attr($retrieved_data->ID)?>"> You know what URL you want the user to go to. After all, it's right there in the link. So if you know what the URL is, why even bother having this page at all? Why give the user some HTML page when all you're going to do is trigger some Javascript that immediately sends them somewhere else? It's wasteful. Instead of giving them this page, do the redirect. In case you weren't aware, you can do it with some PHP code. Maybe that was the missing piece in this puzzle? It looks like this: $url = "?dashboard=user&page=member&tab=viewmember&action=view&member_id=" . esc_attr($retrieved_data->ID); header("Location: $url"); You execute that code before making any output at all. None at all. Then you stop executing after that - so no output after it either. And that's how you do a redirect from within PHP. One that doesn't require any HTML or Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/317274-redirect-using-special-function/#findComment-1611740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.