So, when I run this code on xampp, it works and I can see the variables, without the header.

<html>
<head>
</head>
<body>
<?php
$user="";
$server="";
$db="";
$pass="";
$con=mysqli_connect($server,$user,$pass,$db);

$id=$_POST['loginid'];
$password=md5($_POST['password']);

$result=mysqli_query($con,"SELECT * FROM passwords WHERE userid='$id' AND password='$password'");
session_start();
if($row=mysqli_fetch_array($result)){
require('../connect/registerdb.php');
$rresult=mysqli_query($rcon,"SELECT * FROM registration WHERE userid='$id'");
while($rrow=mysqli_fetch_array($rresult)){

$_SESSION['name']=$rrow['name'];
$_SESSION['dob']=$rrow['dob'];
$_SESSION['userid']=$rrow['userid'];
$_SESSION['sex']=$rrow['sex'];
$_SESSION['family']=$rrow['family'];
$_SESSION['describe']=$rrow['describe'];
$_SESSION['pic']=$rrow['pic'];
$_SESSION['visibility']=$rrow['visibility'];
$_SESSION['registeredon']=$rrow['registeredon'];
$_SESSION['lastlogin']=$rrow['lastlogin'];
require('../connect/emaildb.php');
$eresult=mysqli_query($econ,"SELECT email FROM emaillist WHERE userid='$id'");
while($erow=mysqli_fetch_array($eresult)){
$_SESSION['email']=$erow['email'];
}
}
header('Location:../mainpage.php');
}
?>
</body>
</html>

When I add the header, I get:

Notice: Undefined index: loginid in C:\xampp\htdocs\website\session\session.php on line 12

Notice: Undefined index: password in C:\xampp\htdocs\website\session\session.php on line 13

Why does it work without the header but not with the header?

session_start() needs to be before any variable declarations/html. Try putting

<?php
    session_start();
?>

at the top of the page, and delete your line 16.

No, sorry. It didn't fix it.

Alright, it works on my live site but not on XAMPP. Must be an XAMPP problem.

Ahh ok, this seems like one of those cases where with all the "*AMP" localhost servers, it could just be a matter of setting specific permissions and allowing certain mods to be run on your localhost

Don't forget to mark this thread solved if you got what you need :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.