Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- http referer and php header


Mr_Cat - 11:22 am on Feb 10, 2012 (gmt 0)


Hi folks,

I'm having trouble with the final icing on the cake of my little email system I've bashed together.

It's all simple enough code but I can't fathom this one. Funnily the problem lays in my login script, the one bit I never wrote myself, typical.

here's the verify code on top of every page.


// let's call the database connection

// done

session_start();

$user_check = $_SESSION['login_user'];

$ses_query = mysql_query("SELECT member_name, member_ID, member_email FROM members WHERE member_name = '$user_check' ");

$row = mysql_fetch_array($ses_query);

$member_name = $row['member_name'];
$member_ID = $row['member_ID'];
$member_email = $row['member_email'];

if(!isset($member_name))
{
header("Location: http://www.website.com/login/login.php");
}

// they're safe
?>


now login.php


<?php

// let's call the database connection

// done

session_start();

if($_SERVER["REQUEST_METHOD"] == "POST"){

// username and password sent from Form

$myusername = addslashes($_POST['username']);
$mypassword = addslashes($_POST['password']);

$query = "SELECT member_ID FROM members WHERE member_name = '$myusername' and member_pw = '$mypassword'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

$count = mysql_num_rows($result);
$member_ID = $row['member_ID'];


// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
session_register("myusername");
$_SESSION['login_user'] = $myusername;


header("location: http://www.website.com/index.php");
} // end if
else{

$error = "Your Login Name or Password is invalid";
} // end else
} // end if


?>

// login form here


The trouble is if someone post a message at website.com/page2.php, says they want notification of replies, gets a reply in their email and a link saying 'view it at www.website.com/page2.php' they click the link, have to log in and then get directed to the index page. That's a bit rubbish, I need to redirec them to wherever they want to be, which could be page2, page 3 etc.

I've tried setting up a string containing $_SERVER http referer so I can then say header("location: ".$referer.""); but nothing I've tried seems to work...any ideas?


Thread source:: http://www.webmasterworld.com/php/4416217.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com