doddsey_65 Posted November 23, 2010 Share Posted November 23, 2010 Ok so a user tries to access a part of the site that requires them to login. So they are taken to the login page. but when they login I want them transfered to the page they were going to. So i thought of something like: <a href="securepage.php" onClick="<?php echo $_SESSION['clicked_link'] = $site_root.'securepage.php'; ?>"> Click Here </a> But when I echo $_SESSION['clicked_link'] not only am i getting the url i am getting the content after. echoed it looks like: http://www.thevault.cz.cc/securepage.php">Click Here So is there a better way to do it? if not what would i need to do to remove everything after the " ? Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/ Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 when the un-logged-in user goes to a page that requires login, set a session variable that saves that URL. after log in, header() them back to the URL saved in the session variable. Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138257 Share on other sites More sharing options...
doddsey_65 Posted November 23, 2010 Author Share Posted November 23, 2010 i am saving the url to a session and when it redirects me to the login page i am echoing thesession for debugging and it looks fine. It displays the url. However when i login the session is destroyed and echoes nothing. Thus my header redirect does nothing. Any ideas why the session is being destroyed? This is an example of a link that you can click which needs you to be logged in. If you arent then you are redirected to the login page where i am echoing the session: <a href="'.$site_root.'/profile.php?user='.$forum_info->user_id.'" title="Visit '.$forum_info->user_username.'\'s Profile" onClick="'.$_SESSION["clicked_link"] = $site_root.'/profile.php?user='.$forum_info->user_id.'">'.$forum_info->user_username.'</a> Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138269 Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 on the page with the link, are you starting the file with session_start()? Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138270 Share on other sites More sharing options...
doddsey_65 Posted November 23, 2010 Author Share Posted November 23, 2010 yes i am using session_start(); could it be something to do with the onClick function? It stores the session fine when i am taken to the login page but when i submit the form it destroys it. Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138274 Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 what does the link HTML look like when you View Source? Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138275 Share on other sites More sharing options...
trq Posted November 23, 2010 Share Posted November 23, 2010 onClick is a client side event. You cannot use it to trigger php because php executes on the server. The only thing you could do would be to send a request back to the server (Ajax). Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138276 Share on other sites More sharing options...
doddsey_65 Posted November 23, 2010 Author Share Posted November 23, 2010 onClick is a client side event. You cannot use it to trigger php because php executes on the server. The only thing you could do would be to send a request back to the server (Ajax). any tips on how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138283 Share on other sites More sharing options...
trq Posted November 23, 2010 Share Posted November 23, 2010 http://api.jquery.com/jQuery.ajax/ Quote Link to comment https://forums.phpfreaks.com/topic/219535-redirect-using-session/#findComment-1138302 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.