LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2003, 12:08 PM   #1
Swift&Smart
Member
 
Registered: Jan 2003
Location: Hong Kong,China
Distribution: Slackware,OpenSUSE
Posts: 472

Rep: Reputation: 30
Angry It ain't working.


I am an enthusiastic guy who loves PHP very much.So I bought a pretty expensive wrox Professional PHP4 programming book to learn.However,some code seems like having error. ...I hope you guys will point out the error and tell me why while I have no experience about PHP 4. (It doesn't accumulate 1 in order to keep track the visit time!)
************************************************************************
<?php
$accesses++;
setcookie("accesses",$accesses,time()+3600,"","",0);
?>

<html>
Thank you for visiting my site.You've seen this page

<?php
echo($accesses);
if ($accesses==1) {
echo(" time!");
}
else {
echo(" times");
}
?>

</html>
************************************************************************

And more,I cannot run this script on Windows while I can run it on Linux.How comes???Any suggestions are appreciated!
 
Old 04-10-2003, 03:00 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I don't know much about PHP but try this:
Code:
<?php
$num = 1 + $_COOKIE["accesses"];
setcookie("accesses",$num,time()+3600,"","",0);
?>

<html>
Thank you for visiting my site.You've seen this page

<?php
echo($num);
if ($num==1) {
echo(" time!");
}
else {
echo(" times");
}
?>

</html>
 
Old 04-10-2003, 10:29 PM   #3
Swift&Smart
Member
 
Registered: Jan 2003
Location: Hong Kong,China
Distribution: Slackware,OpenSUSE
Posts: 472

Original Poster
Rep: Reputation: 30
Talking It works!

Thank you very much,it works fine!I found that this book(WROX professional PHP 4 programming) has many errata.......Some of the errata is disastrous.
 
Old 04-11-2003, 02:30 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
In my opinion PHP is still in its infancy and is only useful for web based interfaces. Hence the reason I use perl - it can be used for system tasks and web based scripting.
 
Old 04-13-2003, 09:38 AM   #5
Shak
Member
 
Registered: May 2002
Location: Huddersfield
Distribution: Redhat (7.2, 7.3, 8.0), Debian, Slackware, Gentoo, FreeBSD
Posts: 169

Rep: Reputation: 30
Agreed, PHP is much better for web based anything than CGI will ever be. Just the setup required for CGI makes it rubbish.

Perl however is much better than PHP for anything system based.

Shak
 
Old 04-15-2003, 07:25 AM   #6
Unseen
Member
 
Registered: Feb 2003
Distribution: debian
Posts: 56

Rep: Reputation: 15
Just a thought. Is it really necessary for you to use cookies on your site? You might want to just look into using the session properties of php.

Basically all you need to do is have session_start(); as the first line on on your php page and you can then use the $_SESSION array to store/retrieve values from.

These values will persist from page to page.
 
Old 04-15-2003, 07:42 AM   #7
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Have you tried going to the publisher's website? It is possible that they will have a list of errata there - Sybex does this and it was helpful to me.
 
Old 04-15-2003, 08:38 AM   #8
Swift&Smart
Member
 
Registered: Jan 2003
Location: Hong Kong,China
Distribution: Slackware,OpenSUSE
Posts: 472

Original Poster
Rep: Reputation: 30
It's an error,I think.

I never think that this post has many replies...It's great.

By the way,I know session is better than cookies while it will be stored at the server rather than user's hard drive.(And no user permission to do so )However,I just read that topic so I followed the tutorial.

And XavierP,I've checked out the errata page of this book(Professional PHP 4 from WROX),they don't include this errata.I definitely think that if you want to publish a book,you must check it again and again to see whether there are any error.Because it's a waste of time to check the errata from their website....

I appreciated every help,opinion from you guys.

Last edited by Swift&Smart; 04-15-2003 at 08:39 AM.
 
Old 04-15-2003, 09:02 AM   #9
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
I knowthat this is of no real help now (as you have already forked out the cash), but O'Reilly books seem to be the better ones ATM. Oh, and Linux Format magazine regularly review books like this and problems like the ones you've had are often flagged up.

Like I said, of no real help to you now, but.....

Hope you get your PHP probs sorted.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Intel sound not working, usb modem not working. siriusb Linux - Hardware 8 03-04-2006 10:16 PM
After Online update: Hard drive working and working dacosta SUSE / openSUSE 6 11-06-2004 12:14 AM
F1 - F10 not working when F13 - F20 working in Linux haivinay Linux - General 0 09-20-2004 07:31 AM
Link/Applet not working in all Linux browsers, but working in IE MasterPatricko Linux - Software 6 09-04-2004 03:39 AM
cannot download files in mozilla -save dialog not working, galeon not working cmisip Linux - General 0 08-03-2003 03:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration