You are here: Re: Best way to customize content per user « PHP Language « IT news, forums, messages
Re: Best way to customize content per user

Posted by Geoff Berrow on 11/15/47 11:23

I noticed that Message-ID: <11fg5721h0r8d56@corp.supernews.com> from
Mark ??;-) contained the following:

>I am redesigning a web site (and pretty much a PHP newb) and something that
>I would like to do is have a section that either displays a list of user
>selected favorites or the last 5 or so pages within the site that a specific
>user has accessed. I would prefer to not require the users to log in for
>this to happen so it appears my option is to use cookies. I am open to
>suggestions, example pages, or anything else that will help to make the
>water more muddy.

two example pages

//remember.php http://www.ckdog.co.uk/phpcourse/Lesson6/remember.php

<?php

error_reporting(E_ALL);

if (isset($_POST['submit'])){
$value=$_POST['name'];
setcookie("name",$value, time()+3600*24);

}
if (isset($_POST['reset'])){
$value="";
setcookie("name",$value, time()-1);
}
?>

<html>
<head>
<title>Remember me</title>
</head>
<body>
<?php
if (!isset($_COOKIE['name']) && empty($_COOKIE['name']))
{

?>

<form method="post" action="">
<table border="0">
<tr><td>Who are you?</td><td><input type="textbox"name="name"></td></tr>

<tr><td><input type="submit" name="submit"
value="Submit"></td><td></td></tr>
</table>
</form>
<a href="remember2.php">Link to next page</a>
<?php
if (isset($_POST['name'])&&!empty($_POST['name'])){
print "<br>I'll remember you for a day, ".$_POST['name']."<br>";
}

}
else{
print "Welcome back ".$_COOKIE['name'];

print "<br><br><a href=\"remember2.php\">Link to page 2</a>";
}
?>



</body>
</html>
//end of remember.php


//remember2.php http://www.ckdog.co.uk/phpcourse/Lesson6/remember2.php
<?php

error_reporting(E_ALL);


if (isset($_POST['reset'])){
$value="";
setcookie("name",$value, time()-1);


print "I've forgotten you already<br>";
print "<a href=\"remember.php\">Back</a>";
exit();

}
?>

<html>
<head>
<title>Remember me 2</title>
</head>
<body>
<?php
if (!isset($_COOKIE['name']) || empty($_COOKIE['name']))
{
?>
I don't know you yet, why not tell me your name?<br>
<a href="remember.php">Back</a>
<?php

}
else{
print "Welcome to page 2, ".$_COOKIE['name'];
print "<br><form method=\"post\" action=\"\"><input type=\"submit\"
name=\"reset\" value=\"Clear cookie\"></form>";
print "<br><a href=\"remember.php\">Back</a>";
}
?>



</body>
</html>

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация