473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to pass the user name using cookies

hello,
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Untitled Document</title>
  7. <!--<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
  8. <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />-->
  9. <script type="text/javascript">
  10. <!--
  11. function MM_preloadImages() { //v3.0
  12.  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  13.   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  14.   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  15. }
  16.  
  17. function MM_findObj(n, d) { //v4.01
  18.  var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  19.   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  20.  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  21.  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  22.  if(!x && d.getElementById) x=d.getElementById(n); return x;
  23. }
  24.  
  25. function MM_nbGroup(event, grpName) { //v6.0
  26.  var i,img,nbArr,args=MM_nbGroup.arguments;
  27.  if (event == "init" && args.length > 2) {
  28.   if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
  29.    img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
  30.    if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
  31.    nbArr[nbArr.length] = img;
  32.    for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
  33.     if (!img.MM_up) img.MM_up = img.src;
  34.     img.src = img.MM_dn = args[i+1];
  35.     nbArr[nbArr.length] = img;
  36.   } }
  37.  } else if (event == "over") {
  38.   document.MM_nbOver = nbArr = new Array();
  39.   for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
  40.    if (!img.MM_up) img.MM_up = img.src;
  41.    img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
  42.    nbArr[nbArr.length] = img;
  43.   }
  44.  } else if (event == "out" ) {
  45.   for (i=0; i < document.MM_nbOver.length; i++) {
  46.    img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  47.  } else if (event == "down") {
  48.   nbArr = document[grpName];
  49.   if (nbArr)
  50.    for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
  51.   document[grpName] = nbArr = new Array();
  52.   for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
  53.    if (!img.MM_up) img.MM_up = img.src;
  54.    img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
  55.    nbArr[nbArr.length] = img;
  56.  } }
  57. }
  58. //-->
  59. </script>
  60.  
  61. <style type="text/css">
  62.               #container
  63.               {
  64.                 float:left;
  65.                 border:5px solid #666; 
  66.                 position:relative; 
  67.                 width:770px; 
  68.                 height:450px; 
  69.                 margin:20px auto 0 100px;
  70.                 top:-20px;
  71.               }             
  72.  
  73.               </style>    
  74.  
  75. </head>
  76. <?php
  77.       function connect()
  78.       {
  79.        $dbhost='aaa';
  80.        $dbuser='aaa';
  81.        $dbpass='aaaaa'; 
  82.        $conn= mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'.mysql_error());
  83.     $dbname='aaaaa';
  84.        mysql_select_db($dbname);
  85.  return $conn;
  86.       }
  87. function IsEmpty($cuser,$cpass)
  88. {
  89. $str1=strlen($cuser);
  90. $str2=strlen($cpass);
  91. $nRes=min($str1,$str2);
  92. echo "$nres";
  93. if ($nRes==0)
  94. {
  95.  echo "<font size='3' face='Garamond' color='red'><b> Missing user Id / Password! </b></font> </br>";
  96. }  
  97. return $nRes;
  98. }
  99. ?>
  100.  
  101. <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')">
  102.  
  103. <table align="center" border="0" cellpadding="0" cellspacing="0">
  104. <tr>
  105.  
  106. <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>
  107.  
  108.  
  109.   <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>
  110.  
  111.  
  112.   <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>
  113.  
  114. </tr>
  115. </table>
  116.  
  117. <div id="container">
  118. <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="form1" id="form1">
  119. <?php
  120. $cuser1=$_GET['uname'];
  121. if (!empty($cuser1))
  122. {
  123. echo "<font color='white'> Welcome to Hakman & CO... </font>";
  124. }
  125. else
  126. {
  127. ?>
  128. <label style="color:#FFFFFF">Email Id: </label>
  129. <input type="text" name="cname" id="cname" height="14px" width="170px"/><br/>
  130. <label style="color:#FFFFFF">Password:</label>
  131. <input type="password" name="cpass" id="cpass" height="14px" width="177px"/>
  132. <input type="image" id="checkme" name="checkme" src="/sign_in_off1.PNG" /><br/><br/><br/>
  133.  
  134.  <?php
  135. if (!empty($_POST))
  136. {
  137. $cusername=$_POST['cname'];
  138. $cpassword=$_POST['cpass'];
  139.  
  140. setcookie ("cook_user", $cusername,time()+3600); /* expire in 1 hour */ 
  141. $check=IsEmpty($cusername,$cpassword);
  142. if ($check>0)
  143. {
  144. $c=connect(); 
  145. $query = "SELECT user_id,password FROM users where user_id='".$cusername."' AND password='".$cpassword."'";
  146. $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
  147. if (mysql_num_rows($result) > 0)
  148. {                                
  149. //echo"<font size='4' face='Garamond' color='white'><b>hello swetha</b></font></br>";
  150.  //header('Location:spry_styles.php'); 
  151.  echo "<script language='Javascript'>window.location='onclick_images.php?uname=$cusername';</script>"; 
  152. }
  153. else 
  154. {
  155. echo "<font size='3' face='Garamond' color='white'><b>Oouchh.. you failed to Log In </b></font></br>";
  156. }
  157. }
  158. }
  159. ?>
  160.  
  161. </form>
  162. </div>
  163.  
  164. </body>
  165. </html>
  166.  
  167.  
Dec 29 '08 #1
3 2373
xNephilimx
213 Expert 100+
It would be pretty extensive to explain that here, your answer comes right out a book or the php site, learn how to use sessions:
PHP: Sessions - Manual
Dec 29 '08 #2
Atli
5,058 Expert 4TB
I wrote an article about how to use session a while back.
Perhaps that can help you.

http://bytes.com/topic/php/insights/644923-php-sessions
Dec 29 '08 #3
Never mind, i didnt read the 2nd post
Jan 3 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: vishal | last post by:
when a user clicks on a hyperlink i want to pass data to linked page. but what i want is that this data should not be visible to user. i mean is there any way that i can pass data except get method...
5
by: Carl | last post by:
Hi, I want to pass the value of the cookie created in VB to ASP. This doesn't work. Any idea? Thanks Carl .... <script language=vbscript> document.cookie="mycookie" '...
18
by: | last post by:
Please help. After a number of wrong turns and experiments I need advice on login management system to secure our web pages without inconveniencing our visitors or our internal staff. What I...
4
by: Fred | last post by:
Hi, i know how to pass a value from Javascript to ASP with a hidden field into a form and submitting it, or with cookies, but here i have to pass a lot of data in an array. There is a list of...
5
by: Ryan Ternier | last post by:
Hey! We need a solution for a problem. We're designing a site where users hate... absolutly hate... with a passion to sign in with a user name / password system. They want to sign in once, and...
17
by: Rabbit | last post by:
Hi, On my 1st page, i have a function which gets a new ID value and need to transfer to another immediately. which I want to get in 2nd page using Request.form("txtID"), but doesn't work, the...
4
by: igotyourdotnet | last post by:
Is there a way to pass data from page to page without the use of a Session Variable or queryString? I need to pass drop down box selections from page to page and have the drop downs on the page be...
5
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, Is there an easier way to handle that? I used Javascript to handle this when our two domains are hosted on two different servers(on different networks) and our search engine marketing...
2
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
I'm creating a XBAP application and want it take some input from webpage dynamically? what is the best way? how to do it? Best Regards Steven -- ======================= Steven Tang SYWWUYU)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.