Jump to content

getting values from cookies


ublapach

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

				<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
Share on other sites

				<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
Share on other sites

<?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:ublapach@gmail.com">Michael LaPach</a></p>
  </div>
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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