ublapach Posted April 21, 2008 Share Posted April 21, 2008 how do i get a value and display it form a cookie file Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/ Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 $cookie_text = $_COOKIE['cookie_name']; echo $cookie_text Just put in the right cookie name and that's how you retrieve it. Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522419 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 can i just get part of it or does it have to be all Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522432 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 can i just get part of it or does it have to be all What do you mean? If you had a cookie named 'user' and it had 'test' in it, $_COOKIE['user'] would be set to test. What do you mean by "all"? If you need to pull out part of a string, I'm sure I could help you with the functions. Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522436 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 i wrote several values into the cookie at least i think i did and i just want one of them Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522444 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Show me what you mean. You may have written several different cookies. Example code please. Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522446 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 heres my code that authenticate a user when he or she logs in it works fine but i want it to display there name when they move on the the main area <?php require_once "../tracking/db_connx.php"; session_start(); if (isset ($_POST['submit'])) { if (preg_match('/[!@#$%^&*()-+=`~<>,.?}{|]/', $_POST['username'])) { echo "Illegal Characters In Username"; } else { if (preg_match('/[!@#$%^&*()-+=`~<>,.?}{|]/', $_POST['passwd'])) { echo "Illegal Characters In Password"; } else { $username = $_POST['username']; $password = $_POST['passwd']; $sql = "SELECT * FROM webusers WHERE username='$username' AND passwd='$passwd'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); if ($num > 0) { @$_SESSION['username'] = $row['username']; @$_SESSION['fname'] = $row['first_name']; @$_SESSION['lname'] = $row['last_name']; @$_SESSION['email'] = $row['email']; @$_SESSION['accesslvl'] = $row['accesslvl']; @$_SESSION['logged_in'] = TRUE; $cookiename = 'techsico_log'; $cookievalue=rand(100000,999999); $_SESSION['cookieverify'] = $cookievalue; setcookie($cookiename,$cookievalue,time()+3600,"/"); $today=date('r'); mysql_query("UPDATE webusers SET logged_in = '$today' WHERE username = '$username'") or die (mysql_error()); header("Location:../index.php"); exit; } else{echo 'Username or Password are Incorrect';} } else{echo 'Server Error';} } } } else{echo 'Form Not Submitted';} ?> Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522450 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Oh, you aren't setting the first name in a cookie. You're saving it in a session. Even better. <?php /////////////////////////////////////// // Main.php // I'll assume this is the page. // Here's what I'd do. >_> /////////////////////////////////////// session_start(); // Code, or whatever you need to do // When you want to display the first name: echo $_SESSION['fname']; //That's about it. Of course you could do: // echo "Hello"; if (isset($_SESSION['fname'])) { echo ", $_SESSION['fname']"; } ?> Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522470 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 ok thanks will try Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522476 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 now getting error Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /usr/home/jlytal/public_html/newsite/indexin.php on line 84 Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522480 Share on other sites More sharing options...
redarrow Posted April 21, 2008 Share Posted April 21, 2008 Post the code with the line error we havent got our cristal balls sorry........ Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522482 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 now getting error Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /usr/home/jlytal/public_html/newsite/indexin.php on line 84 Post the code on the lines 5 below it and 5 below it also, thanks. Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522485 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 <div class="smallboxtop"></div> <div class="smallbox">Here </div> </div> <div class="thirds"> <div class="smallboxtop"></div> <div class="smallbox">And Here</div> </div> </div> <div id="right"> <div class="boxtop"></div> <div class="box"> <?php echo "Hello"; if (isset($_SESSION['fname'])) { echo ", $_SESSION['fname']"; } ?> <h2>Veiw, Edit, or Update a Project</h2> <a href="../tracking/addressbook/index.php"><h2>Go to Address Book</h2></a> <h2>Create New Project</h2> <h2>Reports</h2> </div> <div class="boxtop"></div> <div class="box"> <p>News Can Go Here!</p> </div> </div> <div class="footer"> Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522491 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 <div class="smallboxtop"></div> <div class="smallbox">Here </div> </div> <div class="thirds"> <div class="smallboxtop"></div> <div class="smallbox">And Here</div> </div> </div> <div id="right"> <div class="boxtop"></div> <div class="box"> <?php echo "Hello"; if (isset($_SESSION['fname'])) { echo ", $_SESSION['fname']"; } ?> <h2>Veiw, Edit, or Update a Project</h2> <a href="../tracking/addressbook/index.php"><h2>Go to Address Book</h2></a> <h2>Create New Project</h2> <h2>Reports</h2> </div> <div class="boxtop"></div> <div class="box"> <p>News Can Go Here!</p> </div> </div> <div class="footer"> Oh, I meant seperate the echo "Hello"; and the if on a separate line, I just didn't feel like typing out all the // for comments in the script. >_> <?php echo "Hello"; if (isset($_SESSION['fname'])) { echo ", $_SESSION['fname']"; } ?> Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522495 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 still same error Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522507 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 <?php echo "Hello"; if (isset($_SESSION['fname'])) { echo ", {$_SESSION['fname']}"; } ?> Fixed. The $_SESSION var needed to be in {} for the statement to work. It should work on one line like that. =) Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522511 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 now not getting the username displayed um does it have to be in the same file as the code that set the session Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522515 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 No, but are you sure you're logged in AND have session_start() on the page? Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522517 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 yes im sure it wouldnt let me veiw the page if i wasnt loged in ......would it Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522519 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 I don't know, I didn't see the whole page. =P Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522520 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 <?php session_start(); if (isset($_COOKIE["stjucc_portal"])) { if($_COOKIE['stjucc_portal']==@$_SESSION['cookieverify']) { if($_SESSION['logged_in'] == TRUE) { $msg = ('Hello $username '); } else{header("Location:indexlog.php");}//not logged in } else{header("Location:indexlog.php");}//validationfailed } else{header("Location:indexlog.php");} //nocookies ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-2" /> <meta name="author" content="Luka Cvrk (www.solucija.com)" /> <link rel="stylesheet" href="style.css" type="text/css" /> <title>CEIS/TECHSICO</title> </head> <body> <div id="content"> <div id="header"> <div id="logo"> <img src="images/techsico banner.gif" height="235" width="900" align="middle" /></div> <div id="tabs"> <ul> <li><a href="#" class="current">Home<br/> </a></li> <li><a href="#">Products</a></li> <li><a href="#">Process</a></li> <li><a href="#">Portfolio</a></li> <li><a href="tracking/bidrequest.php">Bid Form</a></li> <li><a href="#">Request Job</a></li> <li><a href="#" >Track a Job</a></li> <li><a href="#" >Staff</a></li> <li><a href="#" >Contact Us</a></li> </ul> <div id="spacer"> <p></p> </div> </div> <div class="left"> <div class="left_articles"> <p> Envisioned at the turn of the millennium and founded in 2001, CEIS/TECHSICO is a customer-driven company headquartered in Tulsa, Oklahoma and has several remote offices across the continental United States. Over the past several years, we have completed projects in 28 states, the District of Columbia, and Puerto Rico. Our network of associates are ready to be deployed domestically or internationally in response to your company's needs. CEIS/TECHSICO specializes in project engineering and implementation, custom database design, web development, and staff placement. We also coordinate with our customers to handle special projects and individual needs. Our people have extensive knowledge in their fields which has been developed through years of education and experience. We have experience with cutting edge technologies, large-scale operations, and hands-on field work. Our goal is complete turnkey delivery to you, the customer, in a timely manner. We work with you to provide attractive outsourcing opportunities, which has become especially important in the current market. Overall, CEIS/TECHSICO has only one mission: your satisfaction. </p> </div> <div class="thirds"> <div class="smallboxtop"></div> <div class="smallbox">Comments From Users Could Go Here</div> </div> <div class="thirds"> <div class="smallboxtop"></div> <div class="smallbox">Here </div> </div> <div class="thirds"> <div class="smallboxtop"></div> <div class="smallbox">And Here</div> </div> </div> <div id="right"> <div class="boxtop"></div> <div class="box"> <?php echo "Hello"; if (isset($_SESSION['fname'])) { echo ", {$_SESSION['fname']}"; } ?> <h2>Veiw, Edit, or Update a Project</h2> <a href="../tracking/addressbook/index.php"><h2>Go to Address Book</h2></a> <h2>Create New Project</h2> <h2>Reports</h2> </div> <div class="boxtop"></div> <div class="box"> <p>News Can Go Here!</p> </div> </div> <div class="footer"> <p>© <a href="mailto:[email protected]">Michael LaPach</a></p> </div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522524 Share on other sites More sharing options...
redarrow Posted April 21, 2008 Share Posted April 21, 2008 Example only. <?php session_start(); $_SESSION['fname']="redarrow"; echo "Hello"; if (isset($_SESSION['fname'])) { echo"  ".$_SESSION['fname'].""; } ?> Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522527 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Does it display: Hello, Or: Hello ? I need to know. Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-522528 Share on other sites More sharing options...
ublapach Posted April 21, 2008 Author Share Posted April 21, 2008 it just displays hello Link to comment https://forums.phpfreaks.com/topic/102064-getting-values-from-cookies/#findComment-523173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.