Hi,
I am creating a login system for clients to view their site on our test servers. I have a login consisting of a form for username and password.
I then query the client db to check if the user exists and if the password is correct for the user, then I create a sesssion and register the var's and then redirect to the test site. This all works great but the problem I have is that the session variables aren't carrying over to the subdomain.
Is this possible and how do I do it?
=================My PHP code is as follows===============
Checking db and creating session:
<?php
session_start();
$host = "localhost";
$username = "user";
$password = "pass";
$db_name = "db_name";
$table_name = "table_name";
$connect = mysql_connect("$host","$username","$password"
;
mysql_select_db("$db_name",$connect);
$sql = "SELECT * FROM `$table_name` WHERE `user` = '" . $_POST["username"] . "' AND `pass` = '" . $_POST["password"] . "'";
$query = mysql_query ($sql);
$num_rows = mysql_num_rows($query);
mysql_close($connect);
if ($num_rows > 0)
{
$user = $_POST["username"];
$pass = $_POST["password"];
session_register("user", "pass"
;
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://" . $user . ".mainframe-webdesign.com\">";
}
else
{
echo "error"; //re-login etc
}
?>
The subdomain site checks to see if there are variables present:
<?php
session_start();
if ($user == "username" && $pass == "password"
{
// show the site
}
else
{
echo "you are not authorized to view this site";
}
?>
Thanks alot!
Keep up to date with my 2003 NHL Playoffs Wallpaper
I am creating a login system for clients to view their site on our test servers. I have a login consisting of a form for username and password.
I then query the client db to check if the user exists and if the password is correct for the user, then I create a sesssion and register the var's and then redirect to the test site. This all works great but the problem I have is that the session variables aren't carrying over to the subdomain.
Is this possible and how do I do it?
=================My PHP code is as follows===============
Checking db and creating session:
<?php
session_start();
$host = "localhost";
$username = "user";
$password = "pass";
$db_name = "db_name";
$table_name = "table_name";
$connect = mysql_connect("$host","$username","$password"

mysql_select_db("$db_name",$connect);
$sql = "SELECT * FROM `$table_name` WHERE `user` = '" . $_POST["username"] . "' AND `pass` = '" . $_POST["password"] . "'";
$query = mysql_query ($sql);
$num_rows = mysql_num_rows($query);
mysql_close($connect);
if ($num_rows > 0)
{
$user = $_POST["username"];
$pass = $_POST["password"];
session_register("user", "pass"

echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://" . $user . ".mainframe-webdesign.com\">";
}
else
{
echo "error"; //re-login etc
}
?>
The subdomain site checks to see if there are variables present:
<?php
session_start();
if ($user == "username" && $pass == "password"

{
// show the site
}
else
{
echo "you are not authorized to view this site";
}
?>
Thanks alot!

Keep up to date with my 2003 NHL Playoffs Wallpaper