php-general Digest 20 Aug 2004 09:49:40 -0000 Issue 2947

Topics (messages 194287 through 194311):

Re: How do I use sessions if cookies are turned off in the browser?
        194287 by: Matt M.
        194288 by: Jake Stonebender
        194289 by: John Holmes

Re: download file question...
        194290 by: Torsten Roehr

Re: arrays() current() next() who to use
        194291 by: Torsten Roehr
        194293 by: Vern
        194296 by: Curt Zirzow
        194297 by: Vern
        194298 by: Michal Migurski

Re: oop too slow
        194292 by: Krzysztof Gorzelak

Re: PHP Security Workbook
        194294 by: Chris Shiflett
        194295 by: Chris Ditty

Nueva web necesita enlaces php
        194299 by: webmaster.rutaweb.com
        194300 by: Matt M.

PHP, over javascript code simple \n
        194301 by: Louie Miranda
        194302 by: Louie Miranda
        194303 by: Curt Zirzow
        194311 by: aRZed

Storing, formatting and displaying data
        194304 by: Octavian Rasnita
        194305 by: raditha dissanayake
        194306 by: Xongoo!com: Central unit

make an old extention work with php5
        194307 by: Alawi albaity

Re: Cannot Load DLLs (WinXP, Apache 2, PHP 5)
        194308 by: Rory McKinley
        194309 by: Lester Caine

file permissions
        194310 by: Petr Tvaroha

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
On Thu, 19 Aug 2004 16:50:28 -0400, Don <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I have a PHP file containing the code below.  It works great when all
> default setting exist in IE; each time I click on refresh, the session
> variable is incremented and displays on the screen.  If I change my browsers
> setting to block all cookies, my session variable appears not to increment
> and refreshing the screen displays the same text all the time.
> 
> Q1. Is this because sessions use session cookies and IE blocks these at high
> security?
> 
> Q2. I was told that if cookies are turned off, there is a way to use the
> session ID variable to accomplish what I want instead of cookies.  How can I
> do this OR please point me to an easy tutorial.

rtm
http://us4.php.net/session

session.use_trans_sid

SID

--- End Message ---
--- Begin Message ---
On Thu, 19 Aug 2004 16:50:28 -0400, Don <[EMAIL PROTECTED]> wrote:
> Q1. Is this because sessions use session cookies and IE blocks these at high
> security?
> 
> Q2. I was told that if cookies are turned off, there is a way to use the
> session ID variable to accomplish what I want instead of cookies.  How can I
> do this OR please point me to an easy tutorial.

Basically, in order for your session to work, you have to let the page
that you're viewing know what the session id is.  Let's look at your
code.

> ====== Start of code ======
> <?PHP
> session_start();
> header("Cache-control: private"); //IE 6 Fix
> if(!$_SESSION['count']){
>     $_SESSION['count'] = 1;
> } else {
>     $_SESSION['count']++;
> }
> ?>
> You have visited <? echo $_SESSION['count']; ?> pages so far!
> ======= End of code =======

Looking at this code, there's no link to another page, so there's no
way of letting the web server (and PHP in this case) know what the
session id is.  If your php.ini hasn't been changed, you could see the
session in action by adding a link that points to the same page.  Say
for example, the name of this file is 'session.php'.  Add the
following line to your page:

<a href="session.php">See the session in action!</a>

PHP will rewrite this to:

<a href="session.php?SID=12345678123456781234567812345678">See the
session in action!</a>

Clicking on the link will then show $_SESSION['count'] incrementing. 
You should have seen something similar even if you have cookies the
first time you start your browser (assuming your only using session
cookies) since PHP hasn't received any session information from the
browser.

--- End Message ---
--- Begin Message --- Don wrote:
If I change my browsers
setting to block all cookies, my session variable appears not to increment
and refreshing the screen displays the same text all the time.

You need to pass the session id in the URL if cookies are off. There is a constant, SID, that you may be able to use, or otherwise create it with session_name() and session_id().


$link = 'http://www.yourdomain.com/page.php?'.SID;

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
--- End Message ---
--- Begin Message ---
"Bruce" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> hi...
>
> i can allow files to be uploaded to my app. are there corresponding
> scripts/code to allow files to be downloaded to the user via the browser??
>
> just occurred to me that i'll want to do this...
>
> nothing jumps out at me searching google/php.net for this...
>
> thanks

What about pointing a link to the file?!?:
<a href="/path/to/your/file.pdf">link</a>

If the file is outside of the webroot root or in a protected directory you
can use PEAR's HTTP_Download:
http://pear.php.net/package/HTTP_Download

Regards, Torsten Roehr

--- End Message ---
--- Begin Message ---
"Vern" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Problem with that is it sorts according the results of the recordset
range.
>
> For instance:
>
> It will show the user 1 trhough 10 sorted by miles then 20 - 30 sorted by
> miles, however, in 1 through 10 could have a range of 0 to 1000 miles and
> the next set will have 5 to 200 miles. What I need is to sort them all by
> miles first. The only way I know to do that is to do the way I set it up.
So
> if I create an array, sort that array by the miles then use that array.
> However the array is different that the recordset and thus does not use
> LIMIT.

What about this:
SELECT * FROM table ORDER BY miles LIMIT 0, 10

Then pass the offset to your query function and exchange it with 0:
SELECT * FROM table ORDER BY miles LIMIT $offset, 10

Of course you have to properly validate that $offset is an integer before
using it in the query.

Regards, Torsten Roehr

--- End Message ---
--- Begin Message ---
The miles are being caluculated during the loop that is created using the
recordset not in the database.

First I create a do..while loop to get the miles

do {
 $k = 0;

 //SET FIRST ARRAY OF ONLINE USERS AND CALCULATE MILES
  do {
    //GEOZIP
   $zip2 = $row_rsUSERIDID['zip'];
   $coor1=mycoors($zip1);
   $coor2=mycoors($zip2);
   $line1=split("\|",$coor1);
   $line2=split("\|",$coor2);
   $totaldist=distance($line1[0],$line1[1],$line2[0],$line2[1],"mi");

 //SET NEW ARRAY WITH MILES
   $z['username'][$k] = $row_rsUSERIDID['uname'];
   $z['distance'][$k++] = $totaldist;
  } while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID));


  //SET NEW ARRAY
  $z['user'] = $z['username'];

  //SORT BY DISTANCES
  natsort ($z['distance']);
  reset ($z['distance']);

//DISPLAY USER INFORMATION SORTED BY MILES
  foreach($z['distance'] as $k => $v){
  $newuser = $z['user'][$k];
  echo $newuser . " - " . $v . "<br>";
 }

} while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID));

I now what to display this info 10 records at a time.

--- End Message ---
--- Begin Message ---
* Thus wrote Vern:
> I'm setting up an array based on recordset that does a loop as follows:
> 
> do {
> //SET ARRAYS
>         $z['username'][$k] = $row_rsUSERIDID['uname'];
>         $z['distance'][$k++] = $totaldist;
> } while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID));
> 
>...
> 
> How can I now get this output displyed in groups of 10 so that I can display
> them 10 at a time on a page then click a next button to dispaly they next 10
> and so forth?

Well, this is the hard way to do things, and very inefficient but:

 foreach(array_slice($z['distance'], $start, 10) {
   //...
 }


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

--- End Message ---
--- Begin Message ---
> Well, this is the hard way to do things, and very inefficient but:
>
>  foreach(array_slice($z['distance'], $start, 10) {
>    //...
>  }

If you think there's a better way of doing it I would like to hear it.

However this is resulting in an Parse error on the foreach line:

  foreach(array_slice($z['distance'], $start, 10)) {
  $newuser = $z['user'][$k];
  echo $newuser . " - " . $v . "<br>";
   }

--- End Message ---
--- Begin Message ---
> If you think there's a better way of doing it I would like to hear it.
>
> However this is resulting in an Parse error on the foreach line:
>
>   foreach(array_slice($z['distance'], $start, 10)) {
>   $newuser = $z['user'][$k];
>   echo $newuser . " - " . $v . "<br>";
>    }

"foreach" needs an "as", probably that was meant to say:
        foreach(array_slice($z['distance'], $start, 10) as $k => $v) { ...

---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca            http://mike.teczno.com/contact.html

--- End Message ---
--- Begin Message ---
U�ytkownik "Jason Davidson" <[EMAIL PROTECTED]> napisa� w wiadomo�ci
news:[EMAIL PROTECTED]
> When i have many many objects of the same type to build, i do something
> like this...
>
> function getEvents($sql = '') {
> $events = $this->dbh->query("
> SELECT cols, cols, FROM table,table
> WHERE blah blah balh ($sql ? " AND $sql" : ''),'rows_array');
>
> $rv = array();
> foreach($events as $event) {
> $rv[] = new CalendarEvent($event);
> }
>
> return $rv;
> }
>
> my event class takes an array of data and uses phps list function to
> load its members.  In this case, i save 100s and 100s of queries ,
> using just 1.  Its a massive improvment if it fits your scheme.  To get
> one event, i create a method called getEvent($id) that is a wrapper to
> getEvents, and only uses the first record.. of coarse, there is only
> one record.. but ya.. cheers
>
> Jason
>
> Marcus Bointon <[EMAIL PROTECTED]> wrote:
> >
> > on 19/8/04 9:49, Krzysztof Gorzelak at [EMAIL PROTECTED] wrote:
> >
> > > Hi
> > > I'm trying my new php5 script, but it takes about 1.2s to generate my
page.
> > > That is, how my oop model looks like :
> > >
> > > [category]
> > >   |        |                |
> > > [photo]  [desc]   [products]
> > >
> > >
> > > [products]
> > > |
> > > [product]
> > > |            |            |
> > > [photo] [desc] [keys]
> > >
> > >
> > > [keys]
> > > |
> > > [key]
> > > |
> > > [values]
> > > |
> > > [value]
> > >
> > >   Each object gets data from mysql by itself. The generation time of 1
> > > category [30 products, 10 keys, 5 values ~= 300 mysql queries] takes
as I
> > > said more than a 1s (on quite fast machine). How can this model be
improved?
> > > Do I create too many objects ? What are the oop solutions for such
problem ?
> >
> > This is something that I've wrestled with too. If you make each item you
> > deal with a clean, self-sufficient object, with self-storage, data
hiding
> > etc, it is inevitable that you run into this problem. It is a symptom of
a
> > fundamental clash between Relational DB and OO points of view. The only
> > trick I have found to work around it that is OO-clean is to use factory
> > methods or objects that create multiple objects from a single DB query,
so
> > as well as having a 'get' method that populates an object from a DB,
make
> > another means of creating an object from local data that has been
obtained
> > from a larger query that returned sufficient values to populate multiple
> > items.
> >
> > > I also use an extra table to create many-to-many relation betwean a
product
> > > and a key. Is this the only way in mysql ?
> > >
> > > [product]
> > > |
> > > [product_id, key_id]
> > >                   |
> > >                   [key]
> >
> > Yes, that's the correct way to represent a M:M relation in a relational
DB.
> > The join table is an artefact of a relational model, rather than an OO
one,
> > so the answer is to hide the existence of this table within the objects
at
> > either end - so have product and key objects, but not product_key
objects.
> > Each object should have a method that retrieves instances of all the
related
> > objects of the other kind. This is really a different manifestation of
the
> > first problem.
> >
> > Ultimately the trick is to create separate factory objects or
higher-level
> > methods inside the existing objects that can create multiple instances
from
> > a single database query. Having said that, it's difficult to spot the
best
> > places to do this. For example, you might normally create multiple
product
> > objects from an array of database IDs like so:
> >
> > foreach($productids as $id)
> >     $products[] = new product($id);
> >
> > You can see that this would cause a query for each instantiation.
> >
> > With a product factory class, you might do this instead:
> >
> > $products = product_factory::get($productids);
> >
> > Which achieves the same result, but using only a single DB query (hidden
> > inside the factory class, which does NOT call the product class in the
same
> > way!). The next problem is keeping your product_factory and product
classes
> > in sync - I'm sure there must be a nice pattern to deal with that
somewhere.
> >
> > Marcus
> > --

Thanks a lot, after your replies I made a little google search on 'factory
class' and found a great article:
http://www.phppatterns.com/index.php/article/articleview/49/1/1/. My objects
are still too slow (0,3s) but now I'm going to try Advanced PHP Debugger.

Krzysztof Gorzelak

--- End Message ---
--- Begin Message ---
--- John Nichel <[EMAIL PROTECTED]> wrote:
> Chris Shiflett wrote:
> > This news is a bit old, but I have made the workbook for my
> > OSCON tutorial freely available from this URL:
> > 
> > http://shiflett.org/php-security.pdf
> > 
> > It's a 55 page PDF that has a lot of information (more than
> > the slides) about some of the more important security topics.
> > 
> > I hope you find it helpful.
> > 
> > Chris
> 
> I printed this out the day you sent it, but it had been sitting
> on my desk, unread, until today. Just got finished with it.
> Very helpful methods. I thank you sir.

No problem - thanks for the kind feedback. :-) I'm glad you find it
helpful.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
     Coming Fall 2004
HTTP Developer's Handbook - Sams
     http://httphandbook.org/
PHP Community Site
     http://phpcommunity.org/

--- End Message ---
--- Begin Message ---
Thanks for the article Chris.  Printing it out now and will read it later.

Chris

--- End Message ---
--- Begin Message ---
Apreciados colegas, estoy desarrollando una web en  php que si bien no es muy 
complicada espero sea �til.

Se trata de http://www.rutaweb.com/

La web principalmente est� dedicada a enlaces de calidad pero en breve estrenar� 
secci�n de PHP con tutoriales y scripts. 

De momento agradecer�a que le echarais un ojo y me hicieseis alguna sugerencia, 
observaci�n, etc.

Adem�s estoy buscando ENLACES DE CALIDAD de los temas que se muestran en el portal, si 
crees que hay alg�n enlace que deberia aparecer decidmelo!

Saludos y gracias


--- End Message ---
--- Begin Message ---
On Fri, 20 Aug 2004 03:30:28 +0200, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Apreciados colegas, estoy desarrollando una web en  php que si bien no es muy 
> complicada espero sea �til.
> 
> Se trata de http://www.rutaweb.com/
> 
> La web principalmente est� dedicada a enlaces de calidad pero en breve estrenar� 
> secci�n de PHP con tutoriales y scripts.
> 
> De momento agradecer�a que le echarais un ojo y me hicieseis alguna sugerencia, 
> observaci�n, etc.
> 
> Adem�s estoy buscando ENLACES DE CALIDAD de los temas que se muestran en el portal, 
> si crees que hay alg�n enlace que deberia aparecer decidmelo!


me llamo matt

try this list: http://news.php.net/group.php?group=php.general.es

--- End Message ---
--- Begin Message ---
Im having problems. Because my javascript is inside a PHP code.
Now below are 1 line code of a print function that display this on the
html header.
i must put "\n" after the Firstname. But PHP actually reads \n so when
i view it on a browser the js code moves down. Which is wrong, because
it wont work anymore.. what i want is js should use the \n instead. is
there any alternative for \n? so it can display properly on php?



<?php
print("
if (document.rpcjs_louie.ColCustName.value == \"\") { walangfield +=
\"Missing: Firstname\n\"; }
");
?>

-- 
Louie Miranda
http://www.axishift.com

--- End Message ---
--- Begin Message ---
Got it.

use ' and not "

because php reads if its under "

On Fri, 20 Aug 2004 11:10:24 +0800, Louie Miranda <[EMAIL PROTECTED]> wrote:
> Im having problems. Because my javascript is inside a PHP code.
> Now below are 1 line code of a print function that display this on the
> html header.
> i must put "\n" after the Firstname. But PHP actually reads \n so when
> i view it on a browser the js code moves down. Which is wrong, because
> it wont work anymore.. what i want is js should use the \n instead. is
> there any alternative for \n? so it can display properly on php?
> 
> <?php
> print("
> if (document.rpcjs_louie.ColCustName.value == \"\") { walangfield +=
> \"Missing: Firstname\n\"; }
> ");
> ?>
> 
> --
> Louie Miranda
> http://www.axishift.com
> 


-- 
Louie Miranda
http://www.axishift.com

--- End Message ---
--- Begin Message ---
* Thus wrote Louie Miranda:
> Im having problems. Because my javascript is inside a PHP code.
> Now below are 1 line code of a print function that display this on the
> html header.
> i must put "\n" after the Firstname. But PHP actually reads \n so when
> i view it on a browser the js code moves down. Which is wrong, because
> it wont work anymore.. what i want is js should use the \n instead. is
> there any alternative for \n? so it can display properly on php?
> 
> 
> 
> <?php
> print("
> if (document.rpcjs_louie.ColCustName.value == \"\") { walangfield +=
> \"Missing: Firstname\n\"; }
> ");
> ?>

I'd only print() javascript only if absolutely necessary. otherwise
simply break out of php:

<?php
// php code
?>
if (document.rpcjs_louie.ColCustName.value == "") {
  walangfield += "Missing: Firstname\n"; 
}
<?php
?>


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

--- End Message ---
--- Begin Message ---
<?php
print("
if (document.rpcjs_louie.ColCustName.value == \"\") { walangfield +=
\"Missing: Firstname\n\"; }
");
?>

try simply escaping the "\" before the "n" with an additional "\" or in other words: use "\\n" instead of "\n". PHP will interpret "\\" as an "\".

--- End Message ---
--- Begin Message ---
Hi all,

I would like to create a program that allow users to insert text into a
database, than that text to appear in a web page formatted as HTML.
It is simple to replace the end of line with <br />\n in order to format
that text as html, but I don't know how I could let the users to create
bulleted lists, tables, etc.

Lets say that the users are admins that I can trust, but they don't know
HTML at all, however, they want to insert a table, or a list, etc.

Are there any solutions for this?
I am thinking to something like inserting
<table>
COL1##COL2##COL3
CEL1##CEL2##CEL3
</table>

...for the tables, or something like that, then to make the program
transform this in a true table.

But maybe there are better solutions.

Thanks for any ideas.

Teddy

--- End Message ---
--- Begin Message ---
Octavian Rasnita wrote:

Hi all,

I would like to create a program that allow users to insert text into a
database, than that text to appear in a web page formatted as HTML.
It is simple to replace the end of line with <br />\n in order to format
that text as html, but I don't know how I could let the users to create
bulleted lists, tables, etc.



What you are looking for is a web based html editor - but they do not usually have a database plugged in at the back end. For that you will need to look at a wiki, a CMS or a blogging tool that combines an html editor. Media Wiki is one such project.


--
Raditha Dissanayake.
------------------------------------------------------------------------
http://www.radinks.com/sftp/         | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 128 KB | with progress bar.

--- End Message ---
--- Begin Message ---
Use WISIWYG editor, integrate it into your forms
and presto, for example, from
www.interactivetools.com, that does not work with
tables, but you can find one, I think.

--
Tadas Talaikis
[EMAIL PROTECTED]
http://www.xongoo.com

----- Original Message -----
From: "Octavian Rasnita" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 20, 2004 8:14 AM
Subject: [PHP] Storing, formatting and displaying
data


> Hi all,
>
> I would like to create a program that allow
users to insert text into a
> database, than that text to appear in a web page
formatted as HTML.
> It is simple to replace the end of line with <br
/>\n in order to format
> that text as html, but I don't know how I could
let the users to create
> bulleted lists, tables, etc.
>
> Lets say that the users are admins that I can
trust, but they don't know
> HTML at all, however, they want to insert a
table, or a list, etc.
>
> Are there any solutions for this?
> I am thinking to something like inserting
> <table>
> COL1##COL2##COL3
> CEL1##CEL2##CEL3
> </table>
>
> ...for the tables, or something like that, then
to make the program
> transform this in a true table.
>
> But maybe there are better solutions.
>
> Thanks for any ideas.
>
> Teddy

--- End Message ---
--- Begin Message ---
Is there any possibility to make an old exention that created for work with
php 4 to work with php 5 if the extention is not yet converted to work with
php 5 ?

If yes then how ?


--- End Message ---
--- Begin Message ---
Philip Olson wrote:
<snip>
New installation instructions exist that recommend never copying any
files to the Windows system directory.  It's preferred to leave all files
in the PHP directory and make it (the PHP folder) available to the systems
PATH by editing the appropriate system environment variable.  People copy
files into the Windows system directory because it's in the PATH so no
additional setup is required.  Do not fall into this trap.  Add the PHP
directory to your PATH as doing so will make the world a better place.
The updated manual is as follows:

 http://php.net/manual/en/install.windows.manual.php

If setup this way the above problem would not exist, PHP will find
libmysql.dll.  A FAQ on editing the systems path is here:
<snip>

Sorry Philip, but I have to disagree

I did an install on Wednesday of this week. I placed an entry for my PHP folder in the PATH and it made no difference. Only once I had overwritten the libmysql.dll in the Windows system folder with the version that ships with PHP5 did I get everything to play nicely together.

Regards

--
Rory McKinley
Nebula Solutions
+27 21 555 3227 - office
+27 21 551 0676 - fax
+27 82 857 2391 - mobile
www.nebula.co.za
====================

This e-mail is intended only for the person to whom it is addressed and
may contain confidential information which may be legally privileged.
Nebula Solutions accepts no liability for any loss, expense or damage
arising from this e-mail and/or any attachments.

--- End Message ---
--- Begin Message ---
Rory McKinley wrote:

Sorry Philip, but I have to disagree

I did an install on Wednesday of this week. I placed an entry for my PHP folder in the PATH and it made no difference. Only once I had overwritten the libmysql.dll in the Windows system folder with the version that ships with PHP5 did I get everything to play nicely together.

What was the order in your PATH entry?
I suspect that the copy in the system folder was being found first.
PATH is very badly managed now in windows, it's fine if you only have one copy of a file, but you can not rely on it if old copies exist elsewhere in the PATH.


--
Lester Caine
-----------------------------
L.S.Caine Electronic Services

--- End Message ---
--- Begin Message ---
Hi, I have a question concerning file permissions on the server.

When i try to use fopen($file,"w") i am said i am not permitted to do so
unless i set the file permissions manualy (FTP) to 666 (cannot use chmod()
as well).

Well i am asking how big risk it is to leave files with 666 (or dirs with
777) file permissions on the public server when php scripts of other users
have open_basedir in effect.

Thanks in advance,
Petr

--- End Message ---

Reply via email to