PHP Newbie Help

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

PHP Newbie Help

Postposted on Mon May 26, 2003 9:56 pm

I want create a script that shows where the user has been on a webpage. Similar to Amazon.com's site that tells you which items you already looked at on the site. However since I'm not familar with any real web based programming languages I don't know what to do. Below is what someone recommended I do, but again I don't know PHP all that well so can anyone help me out?

You wouldnt really need a db

You session_start(); at the beginning of all your pages, and you assign each page a unique id. Say for home its 1, about us is 2, links is 3. The person visits home, and you get what their current number of visit pages with a quick for loop, add one and set it: $_SESSION['1'] = "1"; They go to your links page and you do the same thing, except you use $_SESSION['2'] = "3";

Like this:

PHP:

// This is for the home page

session_start();

// Check to see if this is their first visit to your site

if (!$_SESSION['1']) { $use = '1'; }

else {

// Run thru to see how many pages they've visited

for ($x = 1;$_SESSION['$x'];$x++) {}

// Increment x one more time so you dont overwrite the last one

$x++;

// set the session variable

$_SESSION['$x'] = "1";

This probably wont work if you use different pages (ie. home.php, links.php, etc); but then again the code might not work at all as I just pulled this out of my head
malebolgia
Gerbil Elite
 
Posts: 973
Joined: Fri Apr 05, 2002 7:00 pm
Location: New Mexico, USA

Postposted on Tue May 27, 2003 3:28 am

That depends. A session may be enough, but isn't a good option if any of the following applies:
1) you want to keep the info for longer than the session
2) the organization of your data is rather complicated

The session is necessary anyway but I'd use a session-DB combination. If some error occurs session data is rather unmaintainable and will make any debugging a cumbersome task. I always try to keep sessions simple.
no sig
muyuubyou
Grand Gerbil Poohbah
 
Posts: 3231
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Postposted on Tue May 27, 2003 3:35 am

All I really want it to do is list in links the pages that they viewed. Someone told me that I didn't have to have a DB in order to do what I want. The problem I see is that I would have to set a limit on the number of printed links to the pages they visited. Otherwise I think it will just keep adding on. Then again I'm not really familiar with DB or PHP.
malebolgia
Gerbil Elite
 
Posts: 973
Joined: Fri Apr 05, 2002 7:00 pm
Location: New Mexico, USA

Postposted on Tue May 27, 2003 11:21 am

Keep the latest 20 or something. If they want more, ask for a "premium" fee ;) HD space, CPU power and most importantly, bandwidth, is not free.
no sig
muyuubyou
Grand Gerbil Poohbah
 
Posts: 3231
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Postposted on Tue May 27, 2003 9:57 pm

All I need to do now is learn enough PHP to do it. I tried reading over the online PHP manual, but got frustrated in the end. I guess I got to look for a book now to help me. Any suggestions?
malebolgia
Gerbil Elite
 
Posts: 973
Joined: Fri Apr 05, 2002 7:00 pm
Location: New Mexico, USA

Postposted on Wed May 28, 2003 2:58 am

The php.net online manual is a reference guide. You have a short tutorial here -> http://www.php.net/manual/en/tutorial.php but that's too little and too basic to get anything useful running You should try some tutorial.

I've done a little browsing for you. This one http://hotwired.lycos.com/webmonkey/99/21/index2a.html is about PHP+mySQL but covers some other basic stuff.

If you don't mind, keep me posted about your progress.

L8r
no sig
muyuubyou
Grand Gerbil Poohbah
 
Posts: 3231
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Postposted on Wed May 28, 2003 5:06 am

Thanks for the help I already got a script that for the most part works. I say for the most part because it requires MySQL and a table. It works on my machine because I have MySQL and Apache, but on the server I'm trying to get this uploaded on doesn't support MySQL so I now have to rewrite using something called flat-text file (PHP Manual), but I'm not sure what to do since I can't really grasp the functions of flat-text. Such as fopen(), fread(), fwrite(), etc.. So now I'm faced with rewriting a script that is depended upon MySQL to something that isn't. Any suggestions on what I should do?
malebolgia
Gerbil Elite
 
Posts: 973
Joined: Fri Apr 05, 2002 7:00 pm
Location: New Mexico, USA

Postposted on Thu May 29, 2003 2:06 am

It doesn't support MySQL? strange. How about PostgreSQL?

Flat text files are OK, but keep in mind that unless you come with something really sophisticated you should keep it rather small. Flat text files are just that: text files. Usually you write the data line by line using some given separator - each line is a row. No indexing or simple indexing at best (that means no complicated queries get done fast). No compression.

If you plan to stick to plain text, use CSV (comma separated values - importable/exportable from/to excel, access, openoffice, mySQL, Oracle, etc). Just store the column names in the first line, separated by commas, and in the following lines do the same with every row (values).
no sig
muyuubyou
Grand Gerbil Poohbah
 
Posts: 3231
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Postposted on Thu May 29, 2003 2:34 am

I'm still awaiting a response from Craig who runs the servers to tell me if I can even get a DB. I'll post his response when I get it. Funny thing is all the servers are running off of FreeBSD. I personally would have gone with OpenBSD but hey not my company.
malebolgia
Gerbil Elite
 
Posts: 973
Joined: Fri Apr 05, 2002 7:00 pm
Location: New Mexico, USA

Postposted on Thu May 29, 2003 8:39 am

No problem with freeBSD. Some of mine are freeBSD. Most of the server stuff is BSD/Linux/Solaris/AIX/HP-UX compatible. Sometimes even NT/OS2 compatible too.

Mind to share pricing+services+bandwidth info with us?
no sig
muyuubyou
Grand Gerbil Poohbah
 
Posts: 3231
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Postposted on Thu May 29, 2003 9:34 pm

I'll have to ask my boss he pays for it. If your interested in who is hosting it here is a link http://www.wordcraftinc.com
malebolgia
Gerbil Elite
 
Posts: 973
Joined: Fri Apr 05, 2002 7:00 pm
Location: New Mexico, USA

Postposted on Fri May 30, 2003 8:42 pm

Well it turns out I will have a MySQL database:

If you don't need a lot of space, I'll set up a MySql database at no additional charge.

Thanks.

Craig.


Next step is getting this script to work (hopefully). I don't want to wait till the service is up so I'm trying to do it on my XP machine at home. Only problem is I'm not sure how to setup a DB with my script.
malebolgia
Gerbil Elite
 
Posts: 973
Joined: Fri Apr 05, 2002 7:00 pm
Location: New Mexico, USA


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 5 guests