proggR Posted October 24, 2011 Share Posted October 24, 2011 I'm wondering if there's any alternatives to redirecting. For example, after the registration process, I have a fully loaded User object with all of the information I need to load the user's profile (the place that logging in/registering takes you to). I can call the profile action of the user controller and pass in the User object and it will display just fine. The problem is that since the URL is still pointing to the register action if the user refreshes their page its going to try sending the previous form again. Alternatively I could redirect to the profile and have it load that way, but then I'm fetching data from the database seemingly unnecessarily since I had all of the data I needed already fetched prior to redirecting. Is there anyway that I could do the first process but change the url and forget the previous form data so that if they refresh its just refreshing the profile and not resending the previous request? Thanks in advance for any help. Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/ Share on other sites More sharing options...
requinix Posted October 24, 2011 Share Posted October 24, 2011 If you don't redirect then the URL will not change, and to make the URL change you must redirect. Alternatively I could redirect to the profile and have it load that way, but then I'm fetching data from the database seemingly unnecessarily since I had all of the data I needed already fetched prior to redirecting. Not a problem. Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1281837 Share on other sites More sharing options...
proggR Posted October 24, 2011 Author Share Posted October 24, 2011 If you don't redirect then the URL will not change, and to make the URL change you must redirect. Alternatively I could redirect to the profile and have it load that way, but then I'm fetching data from the database seemingly unnecessarily since I had all of the data I needed already fetched prior to redirecting. Not a problem. I thought this may be the case. Its unfortunate since its an extra database request that otherwise wouldn't need to be made but if I must I must I suppose. Thanks for clearing that up. Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1281863 Share on other sites More sharing options...
requinix Posted October 24, 2011 Share Posted October 24, 2011 Its unfortunate since its an extra database request that otherwise wouldn't need to be made but if I must I must I suppose. Just a drop in the ocean. If one extra database request per signup was bad then you'd have more problems than just efficient code. Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1281886 Share on other sites More sharing options...
proggR Posted October 25, 2011 Author Share Posted October 25, 2011 Its unfortunate since its an extra database request that otherwise wouldn't need to be made but if I must I must I suppose. Just a drop in the ocean. If one extra database request per signup was bad then you'd have more problems than just efficient code. True enough. The same thing happens on signin and one other type of content creation but nothing major. And ya, one extra request isn't the end of the world, I just figured if there was a more efficient way to do it I'd like to do it that way. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282170 Share on other sites More sharing options...
xyph Posted October 25, 2011 Share Posted October 25, 2011 Slow code for something that gets executed once in a while isn't as bad as slow code for something executed often. Optimize for the majority of your traffic, even if it means slowing down other, lesser used requests. Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282172 Share on other sites More sharing options...
trq Posted October 25, 2011 Share Posted October 25, 2011 to make the URL change you must redirect. Not these days. There is such a thing as pushState(). See https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282212 Share on other sites More sharing options...
requinix Posted October 25, 2011 Share Posted October 25, 2011 Not these days. There is such a thing as pushState(). See https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history Imagine that: yet another way to deceive your users! Why would HTML 5 include such a thing? What good uses does it have that don't involve tricking users into thinking they're in one place when they're actually in another? Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282223 Share on other sites More sharing options...
xyph Posted October 25, 2011 Share Posted October 25, 2011 Web 3.0 demands those features Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282227 Share on other sites More sharing options...
requinix Posted October 25, 2011 Share Posted October 25, 2011 Without trying to rant (but it just comes so easily and I'm really tired right now), why? People won't be able to share URLs because they'll be looking at the wrong one. XSS attacks could change the referrer, redirect someplace malicious, and capture information. Clicking in the address bar and hitting enter won't reload the page but send me somewhere else instead. Are they doing this to try to address the whole reloading-a-POSTed-form issue? There's already a great solution to that and it's been built into HTTP since 1.0. Honestly, what good does this do? What's the use case? What problem is it solving? Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282242 Share on other sites More sharing options...
trq Posted October 26, 2011 Share Posted October 26, 2011 Urls simply point to resources. Just because a url is /foo what about that means you need to be on a page/script named foo? You just need to know that the url points to the resource you want. An awesome example if this is on Github's site. Goto https://github.com/trq/proem, click the lib directory then drill down to wherever. The url changes without an entire page refresh. But guess what? You can now bookmark something like https://github.com/trq/proem/blob/develop/lib/Proem/Application.php. Even though you are really on https://github.com/trq/proem, the resource is easy to locate. Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282277 Share on other sites More sharing options...
requinix Posted October 26, 2011 Share Posted October 26, 2011 That is a good example. 10 points for Gryffindor. I suppose it isn't fair to prevent good use because of potential bad use. It's just that I see so many ways it could be misused and that bothers me. Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282458 Share on other sites More sharing options...
Network_ninja Posted October 27, 2011 Share Posted October 27, 2011 hi... forgive my elementary question. but how should I do that? Can u give some example code? tnx Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282588 Share on other sites More sharing options...
Network_ninja Posted October 27, 2011 Share Posted October 27, 2011 hello... follow up in my previous post.. I just get it on working. but my question is what if the user press F5? that page is not existing it will give a 404 error. what should I do? Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282597 Share on other sites More sharing options...
trq Posted October 27, 2011 Share Posted October 27, 2011 hello... follow up in my previous post.. I just get it on working. but my question is what if the user press F5? that page is not existing it will give a 404 error. what should I do? What are you talking about? Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282601 Share on other sites More sharing options...
Network_ninja Posted October 27, 2011 Share Posted October 27, 2011 if you add this script your foo.html will be replace by bar.html ryt? but bar.html don't really exist in your directory. var stateObj = { foo: "bar" }; history.pushState(stateObj, "page 2", "bar.html"); Quote Link to comment https://forums.phpfreaks.com/topic/249727-alternatives-to-redirect/#findComment-1282608 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.