Re: Session Question

From: Date: Sun, 15 Jul 2001 09:04:52 +0000
Subject: Re: Session Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-57925@lists.php.net to get a copy of this message
Tom Malone pressed the little lettered thingies in this order... > I'm new to Apache (and PHP) and was unable to find anything approaching an > answer to this problem in the Apache documentation. In fact, I'm not even > sure if I'm having a problem with Apache or with PHP. I am trying to use > sessions to track users on my site and write information to a file. I'm not > requiring them to login or anything - all I really want to know is which > users are visiting different pages on my site so I can judge the > effectiveness of my design. Anyway the problem is - I'm using the following > script: > > <? > session_start(); > session_register("origin"); > session_register("ip_address"); > session_register("browser"); > session_register("$id"); > $id = session_id(); > $origin = "$HTTP_REFERER"; > $ip_address = "$REMOTE_ADDR"; > $browser = "$HTTP_USER_AGENT"; > $sessn_root = "/***/sessn-log"; //substituted asteriks for actual path here > if(!file_exists("$sessn_root/$id.txt")): > $sessn_data = "$id\n $ip_address\n $browser\n $origin\n"; > else: > $sessn_data = "$origin\n"; > endif; > $fp = fopen("$sessn_root/$id.txt", "a"); > fputs($fp, $sessn_data); > fclose($fp); > $includes = "***/includes"; //substituted asteriks for actual path here > $page = "$includes/index.inc"; include("$includes/template.html.php"); > ?> > > and i get the following error: > > Warning: > fopen("/home/tgmalone/sessn-log/0bbaf33ab1c1f9d714e2244459979ec7.txt","a") > - Permission denied in /home/tgmalone/public_html/index.php on line 17 > > The problem is obvious, but I've been searching, searching and wracking my > inadequate brain for a solution and can't find one - can anyone help me > find a solution/workaround? > The output file (or directory in this case) need to be writable by the web server. This sort of operation is rather insecure, but if you must log to a text file, either make the output directory owned by the web server process (usually "nobody") or make the output directory world writable. If you have root access and your httpd process is owned by "nobody" you can issue the following command from a prompt: chown -R nobody /home/tgmalone/sessn-log You must have root access to use chown. If you do not have root access, you'll need to use chmod to make the directory world writable: chmod -R 777 /home/tgmalone/sessn-log Neither of these solutions is very secure. If you have the option, you should log these entries into a database. Good luck... Christopher Ostmo a.k.a. tech@AppIdeas.com AppIdeas.com Innovative Application Ideas Meeting cutting edge dynamic web site needs since the dawn of Internet time (1995) Business Applications: http://www.AppIdeas.com/ Open Source Applications: http://open.AppIdeas.com/

« previous php.general (#57925) next »