Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

login system problem

Links for php scripts

Moderators: macek, egami, gesf

login system problem

Postby meenctg » Wed Jun 20, 2012 6:05 am

I have a login system in my site. But here is a problem that is when a visitor visit a restrict page then he/she get a login form after success login how to i'll redirect him/her last 2 page url. I mean last page visited before page.

my last script is

if($count==1){
// store session data
$row = mysql_fetch_array($result);
//echo $row['name'];
$_SESSION['harun']= $row['email'] ;
//print $row['name'] . "Thanks, Redirecting";
header("location:member_login_success.php");
}
else {
//echo "Wrong Username or Password";
//print "Wrong Username or Password";
header("location:member_login_wrong.php");
}
?>
meenctg
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Jun 20, 2012 5:51 am

Re: login system problem

Postby egami » Wed Jun 20, 2012 8:25 am

if (isset($_SESSION['httpURL'])) {
$url = $_SESSION['httpURL'];
unset($_SESSION['httpURL']);
header("Location: $url");
}


This is how it's done when you go to a book mark that requires a login. The login page appears, you apply credentials, and after a successful authentication, it'll redirect you to the page.. so in theory.. this should be what you want..


Code: Select all
<?php

session_start
();
if (!isset(
$_SESSION['loggedin'])) { 
  
/* If user isn't logged in.. assign the URL to a session variable, force a login and then redirect after success */
  
$_SESSION['httpURL'] = $_SERVER['REQUEST_URI'];
  include (
'loginform.php');
  include (
'footer.php');
  die();

 
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: login system problem

Postby meenctg » Thu Jun 21, 2012 2:46 am

egami wrote:if (isset($_SESSION['httpURL'])) {
$url = $_SESSION['httpURL'];
unset($_SESSION['httpURL']);
header("Location: $url");
}


This is how it's done when you go to a book mark that requires a login. The login page appears, you apply credentials, and after a successful authentication, it'll redirect you to the page.. so in theory.. this should be what you want..


Code: Select all
<?php

session_start
();
if (!isset($_SESSION['loggedin'])) { 
  
/* If user isn't logged in.. assign the URL to a session variable, force a login and then redirect after success */
  $_SESSION['httpURL'] = $_SERVER['REQUEST_URI'];
  include ('loginform.php');
  include ('footer.php');
  die();
}
 
 


Will you give a clear suggestion please?
My check_login.php is
i wanna after login successful a user will redirect last visited page or before 2 page
Code: Select all
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
//$username=""; // Mysql username
$password=""; // Mysql password
//$password=""; // Mysql password
$db_name=""; // Database name
//$db_name="uk"; // Database name
$tbl_name=""; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['email'];
$mypassword=$_POST['password'];

$sql="SELECT * FROM $tbl_name WHERE email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// store session data
$row = mysql_fetch_array($result);
//echo $row['name'];
$_SESSION['harun']= $row['email'] ;
//print $row['name'] . "Thanks, Redirecting";
header("location:member_login_success.php");
}
else {
//echo "Wrong Username or Password";
//print "Wrong Username or Password";
header("location:member_login_wrong.php");
}
?>


actually where will i change for redirect after login successful at before last visited page or before 2 page ?
meenctg
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Jun 20, 2012 5:51 am

Re: login system problem

Postby egami » Thu Jun 21, 2012 6:52 am

That was pretty clear, but you want me to do it for you, and I'm not going to give it away for free. Pitch me 150 bux through paypal, and I'll get your website working.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.