Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 8th, 2007, 11:44 AM
rjm rjm is offline
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default My solution to exercise 6, on ch.2 - help

Hi all,

When trying to solve ex. 6, of chapter 2 (p. 82), I got this solution, which I expected to work, but it doesn't. The number of visits is always "1", no matter how many times I access the page.
Can anyone tell me what am I doing wrong?

The code follows:

- file ch2ex4.php:

<?php

setcookie('remember', time()+600);

?>
<html>
<head>
<title>Text formatter</title>
<?php

?>
</head>

<body>
<form method="post" action="ch2ex4_1.php">
  <p>Enter your text:
    <input type="textarea" name="sentence">
  </p>
  <p>Enter color for text:
  </p>
  <p>Black:
    <INPUT TYPE="radio" name="color" value="black">
  </p>
  <p>Red:
    <INPUT TYPE="radio" name="color" value="red">
  </p>
  <p>Do you want to save these preferences for the next time you log in?
    <input type="checkbox" name="pref" value="y">
  </p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
</body>
</html>


... and ch2ex4_1.php:


<?php
session_start();
setcookie('count', time()+60*60*24);
if ($_POST['pref']=='y') {
setcookie('font', $_POST['font'], time()+60);
setcookie('size', $_POST['size'], time()+60);
setcookie('color', $_POST['color'], time ()+60);
}
?>
<html>
<head>
<title>Formated text: </title>
</head>

<body>
<?php
//echo "";
//echo $_POST[sentence];
//echo "";

function counter() {
    $count=$count+1;
    echo "&nbsp;";
    echo "This is your visit number ";
    echo $count;
}

echo "" . $_POST[sentence] . "";

counter();

?>


</body>
</html>



  #2 (permalink)  
Old July 30th, 2008, 10:36 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
have you got the answer to the exercise.please post the solution if you have

  #3 (permalink)  
Old July 28th, 2010, 05:50 PM
Registered User
 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session Variables

Hey,
you have to use a $_SESSION variable to hold the page count.
I suppose after your user is done you can increment the session var to a cookie for future use.
Try this for the page counter:
Code:
<?php
session_start();  
if(isset($_SESSION['views']))
    $_SESSION['views'] = $_SESSION['views']+ 1;
else
    $_SESSION['views'] = 1;

echo "views = ". $_SESSION['views']; 
?>
<html><head><title>Formated text: </title></head>
<body>
<p>This is visit number: <?php echo $_SESSION['views']; ?></p>
</body>
</html>


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 Exercise 3 solution firblazer BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 19th, 2008 07:16 AM
Solution to exercise 7, Chapter 2 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 28th, 2006 04:28 AM
exercise solution uddessjava Java Basics 1 December 29th, 2005 04:57 AM
Exercise Solution jgrat BOOK: Beginning Access VBA 3 October 18th, 2004 04:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.