Russia Posted November 10, 2009 Share Posted November 10, 2009 I have this script, its a login script. Currently after logging in and checking the login it goes to accounts.php Goes on top of the webpage: <?php session_start(); if(!session_is_registered(myusername)){ header("location:accounts-login.php"); } ?> Form: <form autocomplete="off" id="form" method="post" action="checklogin.php"> <h1>Login Form</h1> <p>Please log in to the admin area to view logged accounts.</p> <label>Username <span class="small">Min. size 6 chars</span> </label> <input name="myusername" type="text" id="myusername" size="20" /> <label>Password <span class="small">Min. size 6 chars</span> </label> <input name="mypassword" type="password" id="mypassword" size="20" /> <button name="submitBtn" type="submit"></button> <div class="spacer"></div> </form> checklogin.php <?php require "inc/config.php"; // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM `admin` WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { // Register $myusername, $mypassword and redirect to file "accounts.php" session_register("myusername"); session_register("mypassword"); header("location:accounts.php"); } else { header('Location:accounts-login.php'); } ?> Lets say I was at contact.php, and I had no session, it would redirect me to accounts-login.php after I login it takes me to accounts.php. Accounts.php is like the index of the folder. What I need is for it to take me back to the page I was viewing before. Kind of like in vbulletin, if your viewing a thread and ur not logged in, when u login it takes u back to the thread. Is that possible? Link to comment https://forums.phpfreaks.com/topic/181047-after-login-go-back-to-original-page/ Share on other sites More sharing options...
mrMarcus Posted November 10, 2009 Share Posted November 10, 2009 you can send the page via the URL .. something like this: <?php //user is not logged in, so display a link to the login page; echo '<a href="login.php?return='.urlencode ($_SERVER['REQUEST_URI']).'">Login</a>'; ?> if you don't want to display a login link, just do a header() redirect: <?php header ('Location: login.php?return='.urlencode ($_SERVER['REQUEST_URI'])); exit (0); ?> then, in the login script: <?php //do login stuff; //after successful login .. redirect back; header ('Location: http://www.your-site.com'.urldecode ($_GET['return'])); exit (0); ?> something like that, anyways. Link to comment https://forums.phpfreaks.com/topic/181047-after-login-go-back-to-original-page/#findComment-955284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.