Jump to content

Cookies to Session...


eaglelegend

Recommended Posts

??? How do I change my code from cookies to sessions? heres log in code etc.

 

Config:

<?
ob_start();

$host = "HOST";
$user = "USERNAME"; //EDIT
$pass = "PASSWORD; //EDIT
$db = "DATABASE"; //EDIT

mysql_pconnect($host, $user, $pass);
mysql_select_db($db);


$SITEURL = "http://www.eaglelegend.com/"; //EDIT

$items_path = "ROOT/images"; //EDIT

$Z = "";

if($_COOKIE['ipets']) {
$ms = mysql_query("SELECT * FROM `members` WHERE `username`='{$_COOKIE['ipets']}'");
while($mr = mysql_fetch_array($ms)) {
 	$POINTS = $mr["points"];
 	$MONEY = $mr["money"];
}
}

$style_file = "style.css";

$site_title = "Eagle Legend"; //EDIT

$footer = "© Copyright MCMXCVII - MMVIII Eagle Legend. Please Read our Privacy & Cookie Policy before using this site! at www.eaglelegend.com/privacy.php"; //EDIT
?> 

 

Login:

<?php
ob_start();
include("header.php");

$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password) {
$check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`=\"$username\" AND `password`=\"$password\""));

if($check == 1) {
 	if(setcookie("ipets",$username,time()+(3600*24))) {
 	 	Header("Location: index.php");
 	}
 	else {
 	 	print "Cant set cookie";
 	}
}
else {
 	print "Sorry, username/password mismatch!";
}

}
else {
?>
<h2>Login</h2><p>
<form action="login.php" method="post">
Username<br>
<input type="text" name="username" size="20"><p>
Password<br>
<input type="password" name="password" size="20"><p>
<input type="submit" value=" Login "></form>
<? 
}

include("footer.php");
ob_endflush();
?>

 

Logout:

<?php
ob_start();
include("header.php");
include("members.php");

if(setcookie("ipets",null,time()-(3600*99))) {
	Header("Location: index.php");
}
else {
	print "Cant delete cookie";
}

include("footer.php");
ob_endflush();
?>

Link to comment
https://forums.phpfreaks.com/topic/99409-cookies-to-session/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.