kapz22 Posted February 20, 2010 Share Posted February 20, 2010 Hi all, i need some help. basiclly i am making a view page which has a an id in the URL i.e view.php?id=1 if no id is included in the url, it errors. I fixed that by inserting the following code: if (!isset($_GET["id"])){ $_GET["id"] = ""; } but it still loads the page and has errors. how do i need to change this code so that if ?id= is not in the url, it doesnt load the page? i.e. takes the user to the prvious page they were at. Quote Link to comment https://forums.phpfreaks.com/topic/192765-_get-issue/ Share on other sites More sharing options...
premiso Posted February 20, 2010 Share Posted February 20, 2010 if (!isset($_GET['id'])) { echo "The page you are viewing requires a valid ID to be passed. None given."; exit; } Would be one way, not the neatest but would work. Quote Link to comment https://forums.phpfreaks.com/topic/192765-_get-issue/#findComment-1015434 Share on other sites More sharing options...
kapz22 Posted February 20, 2010 Author Share Posted February 20, 2010 im sure it can be done though, as i have seen it on websites, where if the url is not correct ie not containing the variables, it wont load the page at all. Quote Link to comment https://forums.phpfreaks.com/topic/192765-_get-issue/#findComment-1015437 Share on other sites More sharing options...
kapz22 Posted February 20, 2010 Author Share Posted February 20, 2010 can this be done another way? Quote Link to comment https://forums.phpfreaks.com/topic/192765-_get-issue/#findComment-1015438 Share on other sites More sharing options...
premiso Posted February 20, 2010 Share Posted February 20, 2010 im sure it can be done though, as i have seen it on websites, where if the url is not correct ie not containing the variables, it wont load the page at all. You can make it 404 out if you want to, by including a custom 404 page. Not really sure what you are after. If you want it to be "blank" just remove my echo and it will just be a blank page. But the page will always load to check something, no matter what. It is the directions you give the code that make it "seem" like it does not load. Quote Link to comment https://forums.phpfreaks.com/topic/192765-_get-issue/#findComment-1015439 Share on other sites More sharing options...
kapz22 Posted February 20, 2010 Author Share Posted February 20, 2010 maybe this is not done by setting the $_GET variable.... here is an example of what i am trying to achieve: http://www.beyondsport.org/the-awards/entries/view.php?Id=435 if you remove the ?Id=435 the browser goes to the last page you visited. Quote Link to comment https://forums.phpfreaks.com/topic/192765-_get-issue/#findComment-1015440 Share on other sites More sharing options...
premiso Posted February 21, 2010 Share Posted February 21, 2010 They are most likely setting a session variable with the last id viewed or last page viewed. Then if no id is passed it reverts back to the session. Whether this was "coded" that way or not I do not know, as it may have been a mistake on their part in that they have register_globals turned on and if they stored the id in session, it would be set then. Either way, using sessions you can easily achieve this. Quote Link to comment https://forums.phpfreaks.com/topic/192765-_get-issue/#findComment-1015466 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.