Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,494 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,708 people online right now. Registration is fast and FREE... Join Now!




Cookies

 
Reply to this topicStart new topic

Cookies, Clueless about cookies

jeansymolanza
5 Mar, 2008 - 12:23 PM
Post #1

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
CODE

<?php require_once('../Connections/ilovephysics.php'); ?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['email'])) {
  $loginUsername=$_POST['email'];
  $pass=$_POST['password'];
  
//encode password
$password = md5($pass);

  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "../buy/user.php";
  $MM_redirectLoginFailed = "loginfail.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_ilovephysics, $ilovephysics);
  
  $LoginRS__query=sprintf("SELECT email, password FROM tbl_users WHERE email='%s' AND password='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  
  $LoginRS = mysql_query($LoginRS__query, $ilovephysics) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>


I am interested in making a session cookie for my site but don't know how to implement it into the above Dreamweaver code. The session cookie needs to be able to use the loginUsername value to find the users details stored in the database and display it to them on the members panel.
From here they edit the values e.g. their passwords. Does anyone have pointers on where I can start? Any help would be much appreciated!

I'm guessing that would mean that the cookie would need to be loaded on the page that login redirects you to. It would also need to be deleted on logout.

Thanking you in advance!
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Cookies
5 Mar, 2008 - 12:36 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(jeansymolanza @ 5 Mar, 2008 - 01:23 PM) *

Does anyone have pointers on where I can start?

Since you are doing this in php, it might not be a bad idea to read their documentation on using cookies available on php.net. It's pretty straight forward.

php.net cookies <-- Link
User is online!Profile CardPM
+Quote Post

SpaceMan
RE: Cookies
5 Mar, 2008 - 01:54 PM
Post #3

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

Got Milk?

i use these funtions.
be careful what you store in them.
i dont use for login info.
you need to call them before any output to browser.(headers_sent)

php

<?
function send_cookie($name, $value) {
if (!headers_sent()) {
// expires in one year
if(isset($_COOKIE['PHPSESSID']))
setcookie($name, $value, time() + 31104000, '/');
}
}

function delete_cookie($name) {
if (!headers_sent() ) {
if(isset($_COOKIE['PHPSESSID']))
setcookie($name, 'bogus', time() - 3600, '/');
}
}
?>


This post has been edited by SpaceMan: 5 Mar, 2008 - 02:00 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:56PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month