Jump to content

Recommended Posts

basically you need to grab the details before redirecting to the login page then when the login is check redirect to that page

basic example

 

<?php
session_start();
//check if the user is logged in
if($isLoggedInn)
{
$_SESSION['page'] = $_SERVER['QUERY_STRING'];
header("Location: login.php");
}
?>

 

 

<?php
session_start();
//blar
//logged in
header("Location: ".$_SESSION['page']);
?>

ok i semi understand haha

rite im using the following codes

 

my check login code is

 

<?php

 

                include ("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 $tbl_name WHERE username='$myusername' and password='$mypassword'";

$result=mysql_query($sql);

$row = mysql_fetch_assoc($result);

$userid = $row['user_id'];

$userav = $row['user_avatar'];

$name = $row['name'];

 

// 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

session_register("myusername");

session_register("mypassword");

$_SESSION['myusername'] = $myusername;

$_SESSION['myuserid'] = $userid;

$_SESSION['myname'] = $name;

$_SESSION['avatar'] = $userav;

header("location:my_account.php");

}

else {

echo "Wrong Username or Password";

}

?>

and to check for my session im usuing this code at the top of each page !!!

 

 

<?php

session_start();

if(!session_is_registered(myusername)){

header("location:registration_page.php");

}

?>

 

how do i intergrate this new code into my existing one then ???

 

Thanks very much by the way !!!

<?php
session_start();
if(!session_is_registered(myusername))
{
$_SESSION['page'] = "http://" . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "/" . $_SERVER['QUERYSTRING'] . "/";
header("location:registration_page.php");
exit();
}
?>

 

and update

      $_SESSION['myusername'] = $myusername;
      $_SESSION['myuserid'] = $userid;
      $_SESSION['myname'] = $name;
      $_SESSION['avatar'] = $userav;
      if(!empty($_SESSION['page'])) header("location:my_account.php");
      header("location: ".$_SESSION['page']);
exit();

if(!empty($_SESSION['page'])) header("location:my_account.php");

 

That's why

i still dont understand????

erm.. me either..

 

anyways update

$_SESSION['page'] = "http://" . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "/" . $_SERVER['QUERYSTRING'] . "/";

to

$_SESSION['page'] = "http://" . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'];
$_SESSION['page'] .=(!empty($_SERVER['QUERYSTRING'])?"/".$_SERVER['QUERYSTRING']."/":"";

 

should solve it,

 

it was just some quick code

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.