eg a login form?
is it possible to get an included file to set a cookie?
i guess it would be hard as it needs to be before anything else is set..
also
heres the go for now...
cant seem to figure it out i think its all kinda working..just doesnt seem to set the logged in cookie.
I can login with the user / pass and its getting through... wrong user / pass gets the sorry wrong user etc error...not sure what the hell is going on
you can see the demo here:-
http://faction306.com/form/home.php
username: test
pass: test
MAIN PAGE
ob_start();
// CONNECT TO MAIN DATABASE
include("cnxt.php");
// SET COOKIES
if ($_POST['cookies'] == "ok"){
include("setcookies.php");
}
// TEST LOGIN DATA
if ($_POST['in'] == "in"){
include("testlogin.php");
}
// IF COOKIE EXISTS YOU ARE LOGGED IN SO SHOW LOGOUT
if ($_COOKIE['loggedin']){
include("logoutform.php");
}
//OTHERWISE SHOW MAIN LOGIN FORM
else {
include("loginform.php");
}
//DESTROYS COOKIES
if ($_POST['logout']){
include("destroy.php");
}
ob_end_flush();
LOGIN FORM
<form name="loginform"action="<?=$PHP_self ?>" method="post">
<input type="hidden" name="in" value="in">
<table cellpadding="2" cellspacing="0" class="formtext">
<tr><td align="right">Login Name :</td>
<td colspan="2"><input type="text" name="username" size="18" class="form"></td>
</tr>
<tr>
<td align="right">Password :</td>
<td colspan="2"><input type="text" name="password" class="form" size="18"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="checkbox" name="remember"> Remember Me <input type="submit" value="Login" class="form"></td>
</tr>
<tr>
<td colspan ="3" align="center"><a href="recover.php">Forgotten Password</a></td>
</tr>
</table>
</form>
LOGOUT FORM
<form name="logout" action="<?=$PHP_self ?>" method="post">
<table class="form">
<tr>
<td align="center">
You are currently logged in as <?Print($_COOKIE['name']);?></td></tr>
<tr>
<td>
<input type="submit" value="Logout" class="form"><br><br>
<a href="http://onstageshirts.com.au/dev">Return</a>
</td>
</tr>
</table>
</form>
TESTLOGIN
ob_start();
$sql = "select * from Control where login ='".$_POST['username']."' and rawpass = '".$_POST['password']."';";
$qry = mysql_query($sql)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows <= 0)
{
Print("<font color=\"red\">Sorry the Login name or Password is incorrect</font>");
$cookies = "bad";
}
else
{
Print("You are now logged in!<br>click <a href=\"http://onstageshirts.com.au/dev\">Here</a> to continue");
$cookies = "ok";
}
ob_end_flush();
DESTROY COOKIES
<?
//destroy cookies
setcookie('loggedin', "", time() - 3600 * 24, '/', '.onstageshirts.com.au');
setcookie('name', "", time() - 3600 * 24, '/', '.onstageshirts.com.au');
setcookie('id', "", time() - 3600 * 24, '/', '.onstageshirts.com.au');
unset($_COOKIE['loggedin'], $_COOKIE['name'], $_COOKIE['id']);
Print("You are now logged out.<br>");
?>
Click <a href="http://www.onstageshirts.com.au/dev">here</a> to return
<?
}
?>