View Full Version : how to pass the user name using cookies

12-29-2008, 12:20 PM
I don't know how to use cookies

please help me in this

I am using the dream weaver cs4

I designed the navigation bar to my page using dream weaver cs4
navigation bar contains Home, Retail Contact Us

In my retail.php when user login he goes to the second.php
but i need to pass this user name using cookies to the second.php

the thing is when user successfully logged in he will be in the second.php now from second.php when the user again clicks on the Retail.php i.e retail tab in the navigation bar with out logging out
then it should display Welcome message instead the old

if the user logouts and clicks on the retail tab then it should display all the input fields again for the user to login newly again

hope u understand my doubt

here is my code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<!--<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />-->
<script type="text/javascript">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
if (event == "init" && args.length > 2) {
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
nbArr[nbArr.length] = img;
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = args[i+1];
nbArr[nbArr.length] = img;
} }
} else if (event == "over") {
document.MM_nbOver = nbArr = new Array();
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
nbArr[nbArr.length] = img;
} else if (event == "out" ) {
for (i=0; i < document.MM_nbOver.length; i++) {
img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
} else if (event == "down") {
nbArr = document[grpName];
if (nbArr)
for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
document[grpName] = nbArr = new Array();
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
nbArr[nbArr.length] = img;
} }

<style type="text/css">
border:5px solid #666;
margin:20px auto 0 100px;


function connect()
$conn= mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'.mysql_error());
return $conn;
function IsEmpty($cuser,$cpass)
echo "$nres";
if ($nRes==0)
echo "<font size='3' face='Garamond' color='red'><b> Missing user Id / Password! </b></font> </br>";
return $nRes;

<body bgcolor="#0a1936" onload="document.form1.cname.focus();""MM_preloadImages('/home_normal.jpg','/home_clicked_down.JPG','/retail_normal.JPG','/retail_clicked_down.JPG','/contact_clicked_down.JPG','/about_clicked_normal.JPG','/about_clicked_down.JPG')">

<table align="center" border="0" cellpadding="0" cellspacing="0">

<td><a href="welcome.html" target="_top" onclick="MM_nbGroup('down','group1','Home','/home_normal.jpg',1)" onmouseover="MM_nbGroup('over','Home','/home_clicked_down.JPG','',1)" onmouseout="MM_nbGroup('out')"><img src="/home_normal.jpg" alt="" name="Home" width="87" height="33" border="0" id="Home" onload="" /></a></td>

<td><a href=<?php "retail.php?uname=".$_COOKIE['cook_user'] ?>target="_top" onclick="MM_nbGroup('down','group1','Retailers','/retail_normal.JPG',1)" onmouseover="MM_nbGroup('over','Retailers','/retail_clicked_down.JPG','',1)" onmouseout="MM_nbGroup('out')"><img src="/retail_normal.JPG" alt="" name="Retailers" width="113" height="33" border="0" id="Retailers" onload="" /></a></td>

<td><a href="contact_us.php" target="_top" onclick="MM_nbGroup('down','group1','contact','/contact_clicked_down.JPG',1)" onmouseover="MM_nbGroup('over','contact','/contact_clicked_down.JPG','',1)" onmouseout="MM_nbGroup('out')"><img src="/contact_normal.jpg" alt="" name="contact" width="134" height="32" border="0" id="contact" onload="" /></a></td>


<div id="container">
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="form1" id="form1">
if (!empty($cuser1))
echo "<font color='white'> Welcome to Hakman & CO... </font>";
<label style="color:#FFFFFF">Email Id: </label>
<input type="text" name="cname" id="cname" height="14px" width="170px"/><br/>
<label style="color:#FFFFFF">Password:</label>
<input type="password" name="cpass" id="cpass" height="14px" width="177px"/>
<input type="image" id="checkme" name="checkme" src="/sign_in_off1.PNG" /><br/><br/><br/>

if (!empty($_POST))

setcookie ("cook_user", $cusername,time()+3600); /* expire in 1 hour */
if ($check>0)
$query = "SELECT user_id,password FROM users where user_id='".$cusername."' AND password='".$cpassword."'";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
if (mysql_num_rows($result) > 0)
//echo"<font size='4' face='Garamond' color='white'><b>hello swetha</b></font></br>";
echo "<script language='Javascript'>window.location='onclick_images.php?uname=$cuserna me';</script>";
echo "<font size='3' face='Garamond' color='white'><b>Oouchh.. you failed to Log In </b></font></br>";



12-31-2008, 03:36 AM
Use sessions.. MUCH easier....