Re: [PHP] Simple login form with cookies

2009-07-06 Thread Jason Carson
 On Mon, Jul 6, 2009 at 1:45 AM, Jason Carsonja...@jasoncarson.ca wrote:
 Hello everyone,

 I am trying to create a PHP login script using cookies but am having
 some
 troubles. Here is my setup

     index.php - authenticate.php - admin.php

 I want a login form on index.php that allows me to login with my
 username
 and password and then passes $_POST['username'] and $_POST['password']
 to
 authenticate.php

 Then authenticate.php authenticates against a database of allowed users
 (Which I already have setup and it works fine), if a valid user has
 entered the correct information then admin.php is loaded...

 header(location:admin.php);

 ...the admin.php code would look something like the following..

 Code: [Select]
 ?php
 if (isset($_COOKIE['username'])) {
 echo success!;
 } else {
 echo Failure;
 }
 ?

 So basically I think I need to create a cookie from index.php OR
 authenticate.php and then pass the information to admin.php.
 I set the cookie like this...

 setcookie(Admin, $username);

 Which file(index.php OR authenticate.php) do I create the cookie and
 how
 do I access the information in the cookie on admin.php?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 I finally got it working. I needed to setcookie() in login.php. Also,
 the
 names of the cookies(Using setcookie()) where wrong (The names where
 Admin when they should have been adminuser and adminpass) Once I
 fixed that then the following worked in admin.php...
 ?php
 if (isset($_COOKIE['adminuser'])  isset($_COOKIE['adminpass'])) {
 echo Success;
 } else {
 echo Failed;
 }
 ?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 You're not storing anything usable in the adminpass cookie, are you?
 It sort of sounds like you're storing a password, or even a passhash,
 in the cookie and you might want to rethink what that cookie contains
 to prevent session hijacking.

Yeah, I am storing an unencrypted password in the cookie. Should I encrypt
it, if so how, if not what should I do?

I am new to programming and PHP web development so I am not aware of all
the security problems that can occur.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-06 Thread Eddie Drapkin
On Mon, Jul 6, 2009 at 2:01 AM, Jason Carsonja...@jasoncarson.ca wrote:
 On Mon, Jul 6, 2009 at 1:45 AM, Jason Carsonja...@jasoncarson.ca wrote:
 Hello everyone,

 I am trying to create a PHP login script using cookies but am having
 some
 troubles. Here is my setup

     index.php - authenticate.php - admin.php

 I want a login form on index.php that allows me to login with my
 username
 and password and then passes $_POST['username'] and $_POST['password']
 to
 authenticate.php

 Then authenticate.php authenticates against a database of allowed users
 (Which I already have setup and it works fine), if a valid user has
 entered the correct information then admin.php is loaded...

 header(location:admin.php);

 ...the admin.php code would look something like the following..

 Code: [Select]
 ?php
 if (isset($_COOKIE['username'])) {
 echo success!;
 } else {
 echo Failure;
 }
 ?

 So basically I think I need to create a cookie from index.php OR
 authenticate.php and then pass the information to admin.php.
 I set the cookie like this...

 setcookie(Admin, $username);

 Which file(index.php OR authenticate.php) do I create the cookie and
 how
 do I access the information in the cookie on admin.php?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 I finally got it working. I needed to setcookie() in login.php. Also,
 the
 names of the cookies(Using setcookie()) where wrong (The names where
 Admin when they should have been adminuser and adminpass) Once I
 fixed that then the following worked in admin.php...
 ?php
 if (isset($_COOKIE['adminuser'])  isset($_COOKIE['adminpass'])) {
 echo Success;
 } else {
 echo Failed;
 }
 ?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 You're not storing anything usable in the adminpass cookie, are you?
 It sort of sounds like you're storing a password, or even a passhash,
 in the cookie and you might want to rethink what that cookie contains
 to prevent session hijacking.

 Yeah, I am storing an unencrypted password in the cookie. Should I encrypt
 it, if so how, if not what should I do?

 I am new to programming and PHP web development so I am not aware of all
 the security problems that can occur.



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



That's an enormous question without an easy, or even a correct answer.
 I'd start by googling around for session hijacking.  One of the
things that's probably not PC to say, is don't learn to prevent
session hijacking, learn to hijack sessions.  Once you know how to
hijack a session, you can audit your own code and fix the security
holes.

Although the best advice would probably be to find someone else's
session implementation and use that, seeing as there's no real reason
to recreate such a worn-in wheel.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-06 Thread Jason Carson
 On Mon, Jul 6, 2009 at 2:01 AM, Jason Carsonja...@jasoncarson.ca wrote:
 On Mon, Jul 6, 2009 at 1:45 AM, Jason Carsonja...@jasoncarson.ca
 wrote:
 Hello everyone,

 I am trying to create a PHP login script using cookies but am having
 some
 troubles. Here is my setup

     index.php - authenticate.php - admin.php

 I want a login form on index.php that allows me to login with my
 username
 and password and then passes $_POST['username'] and
 $_POST['password']
 to
 authenticate.php

 Then authenticate.php authenticates against a database of allowed
 users
 (Which I already have setup and it works fine), if a valid user has
 entered the correct information then admin.php is loaded...

 header(location:admin.php);

 ...the admin.php code would look something like the following..

 Code: [Select]
 ?php
 if (isset($_COOKIE['username'])) {
 echo success!;
 } else {
 echo Failure;
 }
 ?

 So basically I think I need to create a cookie from index.php OR
 authenticate.php and then pass the information to admin.php.
 I set the cookie like this...

 setcookie(Admin, $username);

 Which file(index.php OR authenticate.php) do I create the cookie and
 how
 do I access the information in the cookie on admin.php?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 I finally got it working. I needed to setcookie() in login.php. Also,
 the
 names of the cookies(Using setcookie()) where wrong (The names where
 Admin when they should have been adminuser and adminpass) Once I
 fixed that then the following worked in admin.php...
 ?php
 if (isset($_COOKIE['adminuser'])  isset($_COOKIE['adminpass'])) {
 echo Success;
 } else {
 echo Failed;
 }
 ?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 You're not storing anything usable in the adminpass cookie, are you?
 It sort of sounds like you're storing a password, or even a passhash,
 in the cookie and you might want to rethink what that cookie contains
 to prevent session hijacking.

 Yeah, I am storing an unencrypted password in the cookie. Should I
 encrypt
 it, if so how, if not what should I do?

 I am new to programming and PHP web development so I am not aware of all
 the security problems that can occur.



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 That's an enormous question without an easy, or even a correct answer.
  I'd start by googling around for session hijacking.  One of the
 things that's probably not PC to say, is don't learn to prevent
 session hijacking, learn to hijack sessions.  Once you know how to
 hijack a session, you can audit your own code and fix the security
 holes.

 Although the best advice would probably be to find someone else's
 session implementation and use that, seeing as there's no real reason
 to recreate such a worn-in wheel.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


ok, I have two sets of scripts here. One uses setcookie() for logging into
the admin panel and the other uses session_start(). Both are working fine,
is one more secure than the other?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Sudheer Satyanarayana

Govinda wrote:

On Jul 5, 2009, at 2:33 PM, Govinda wrote:


I am confusing myself reading the docs just now.

i.e.:
include_path
basename()
and dirname()

I had thought from many months ago that
?php include '/somedir/somefile.php'; ?
would include
somefile.php
living in
somedir
regardless from where in the site structure I am calling it.

Now it does not seem to be doing that.

What is the safest (portable) way to properly build an include path 
*regardless* from where in my site I am calling the include?
If I understand right I can put includes in a dir/ specified by the 
include_path setting, but I also want to know how to do this from 
just within the root of my virtual server.


-Govinda


in my include statement, I am now successfully using:
/home/metheuser/public_html/
and am not anticipating moving this site..  but still I am thinking 
there must be a way to make the code bullet proof to dir/ name changes 
*after* the virtual server root.

Or do people just stop here?

Define a constant like APPLICATION_PATH in the bootstrap file of your 
application. Once it is defined use the paths relative to this constant. 
This way you can easily move your application around.
http://techchorus.net/constants and http://techchorus.net/include-path 
might be useful to you.




--

With warm regards,
Sudheer. S
Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, 
Personal: http://sudheer.net


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Call to object function, want to PHP interpret returned string

2009-07-06 Thread John Allsopp

Hi

At the top of a webpage I have:

?php
include_once(furniture.php);
$myFurniture = new furniture();
echo $myFurniture-getTop(my company title);
?

to deliver the first lines of HTML, everything in HEAD and the first 
bits of page furniture (menu, etc).


In the furniture object in getTop(), I want to return a string that 
includes the CSS file that I call with an include_once. But the 
include_once isn't interpreted by PHP, it's just outputted. So from:


   $toReturn = !DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 
Transitional//EN' 

   ?php
   include_once('styles3.txt');
   ?
   ...;

   return $toReturn;

I get

?php
include_once('styles3.txt');
?

in my code.

Do I really have to break up my echo $myFurniture-getTop(my company title); call to getTopTop, 
then include my CSS, then call getTopBottom, or can I get PHP to interpret that text that came back?


PS. I may be stupid, this may be obvious .. I don't program PHP every day

Thanks in advance for your help :-)

Cheers
J

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Off Subject / Feedback Needed

2009-07-06 Thread Karl James
 
Team,

http://www.theufl.com/css/corners.css

http://www.theufl.com/indexb.htm

I am trying to get the rounded corners to show in the first row in the HTML
table.
Can someone review the code for me?

I think it has something to do with the images, but I corrected the path and
uploaded images.
 
Karl James
 mailto:karlja...@tampabay.rr.com karlja...@tampabay.rr.com
My Website:  http://www.theufl.com www.theufl.com
 


[PHP] Re: Call to object function, want to PHP interpret returned string

2009-07-06 Thread David Robley
John Allsopp wrote:

 Hi
 
 At the top of a webpage I have:
 
 ?php
 include_once(furniture.php);
 $myFurniture = new furniture();
 echo $myFurniture-getTop(my company title);
 ?
 
 to deliver the first lines of HTML, everything in HEAD and the first
 bits of page furniture (menu, etc).
 
 In the furniture object in getTop(), I want to return a string that
 includes the CSS file that I call with an include_once. But the
 include_once isn't interpreted by PHP, it's just outputted. So from:
 
 $toReturn = !DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0
 Transitional//EN' 
 ?php
 include_once('styles3.txt');
 ?
 ...;
 
 return $toReturn;
 
 I get
 
 ?php
 include_once('styles3.txt');
 ?
 
 in my code.
 
 Do I really have to break up my echo $myFurniture-getTop(my company
 title); call to getTopTop, then include my CSS, then call getTopBottom,
 or can I get PHP to interpret that text that came back?
 
 PS. I may be stupid, this may be obvious .. I don't program PHP every day
 
 Thanks in advance for your help :-)
 
 Cheers
 J

First guess is that your page doing the including doesn't have a filename
with a .php extension, and your server is set to only parse php in files
with a .php extension.



Cheers
-- 
David Robley

If you saw a heat wave, would you wave back?
Today is Boomtime, the 41st day of Confusion in the YOLD 3175. 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Object type determined at runtime

2009-07-06 Thread James Colannino
Hey everyone.  I have a question.  Hopefully it's clear, because I'm not
sure quite how to ask it.  Basically, I have a variety of different
objects that a variable can be instantiated as in the same block of
code, its type being determined at runtime.  I want to be able to do
something like this:

$object = new $objType();

Where $objType is the type of object, which must be determined at
runtime.  I'm sure the syntax I have above is incorrect.  My question
is, is there any way that I can determine the object's type at runtime
and do the same type of thing?

Thanks!

James

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to authnticate and use contents from ${HOME}

2009-07-06 Thread schneider . chantale
Hello,

My name ich Chantale, I am 15years old and in a german Lycee. I like to study 
Informatic in two years and now try to code my first applications. I am new to 
php and like to code my own Intranet Web-Interface which should run on my 
FileServer at home.

I have installed suPHP, but it seems to be not the thing I need, because it 
works only on a VHost.

What I need is, that a ${USER} can login and work on her/his ${HOME}.

How can I archive this?

Thank you
Chantale







#adBox3 {display:none;}



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Object type determined at runtime

2009-07-06 Thread David Otton
2009/7/6 James Colannino ja...@colannino.org

 Hey everyone.  I have a question.  Hopefully it's clear, because I'm not
 sure quite how to ask it.  Basically, I have a variety of different
 objects that a variable can be instantiated as in the same block of
 code, its type being determined at runtime.  I want to be able to do
 something like this:

 $object = new $objType();

 Where $objType is the type of object, which must be determined at
 runtime.  I'm sure the syntax I have above is incorrect.  My question

No, you pretty much got it right:

class A{
public function e() {
echo Hello World;
}
}

$A = 'A';

$a = new $A();

$a-e();

 is, is there any way that I can determine the object's type at runtime
 and do the same type of thing?

You're asking a different thing there, but I'll throw it in for completeness:

http://uk.php.net/oop5.reflection
http://uk.php.net/manual/en/function.get-class.php

(BTW, there's a distinction between classes and objects (random link:
http://www.felgall.com/obj1.htm))

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Object type determined at runtime

2009-07-06 Thread James Colannino
Ah, thanks very much.  That was very helpful!

James



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread Lupus Michaelis

  Hi,

  I would like to know if I am alone to be shoked by this :

== 8 ==
function foo( $bar = null)
{
}

foo() ; // runs
foo(null) ; // raise an error
== 8 ==

  Why the default value to null for a reference is allowed ? Is it a 
bug, a feature ?


  Thanks !
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

Seeking for a position http://lupusmic.org/pro/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Call to object function, want to PHP interpret returned string

2009-07-06 Thread John Allsopp

David Robley wrote:

John Allsopp wrote:

  

Hi

At the top of a webpage I have:

?php
include_once(furniture.php);
$myFurniture = new furniture();
echo $myFurniture-getTop(my company title);
?

to deliver the first lines of HTML, everything in HEAD and the first
bits of page furniture (menu, etc).

In the furniture object in getTop(), I want to return a string that
includes the CSS file that I call with an include_once. But the
include_once isn't interpreted by PHP, it's just outputted. So from:

$toReturn = !DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0
Transitional//EN' 
?php
include_once('styles3.txt');
?
...;

return $toReturn;

I get

?php
include_once('styles3.txt');
?

in my code.

Do I really have to break up my echo $myFurniture-getTop(my company
title); call to getTopTop, then include my CSS, then call getTopBottom,
or can I get PHP to interpret that text that came back?

PS. I may be stupid, this may be obvious .. I don't program PHP every day

Thanks in advance for your help :-)

Cheers
J



First guess is that your page doing the including doesn't have a filename
with a .php extension, and your server is set to only parse php in files
with a .php extension.



Cheers
  
Ah, thanks. It's a PHP object returning a string, I guess the PHP 
interpreter won't see that.


So, maybe my object has to write a file that my calling file then 
includes after the object function call. Doesn't sound too elegant, but 
is that how it's gotta be?


Cheers
J


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread Stuart
2009/7/6 Lupus Michaelis mickael+...@lupusmic.org:
  Hi,

  I would like to know if I am alone to be shoked by this :

 == 8 ==
 function foo( $bar = null)
 {
 }

 foo() ; // runs
 foo(null) ; // raise an error
 == 8 ==

  Why the default value to null for a reference is allowed ? Is it a bug, a
 feature ?

You appear to be using the definition of null that comes from the
world of C. A null in PHP is not the same as a null in C - it's a real
value (of type null), not the absence of a value. So what you're doing
is the equivalent of passing a literal value, something you can't do
when the function is expecting a reference.

See the manual for more info on the null type: http://php.net/null

-Stuart

-- 
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread Lupus Michaelis

Stuart a écrit :


You appear to be using the definition of null that comes from the
world of C.


  I didn't. The point is I'm allowed to set a default value to null for 
a referenced parameter (what I can do in C for a pointer, so I knew it).


  I'm happy PHP raises an error on foo(null) ;
  I'm in trouble when foo() doesn't.

  The actual question is : why PHP doesn't raise an error ?

--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

Seeking for a position http://lupusmic.org/pro/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Call to object function, want to PHP interpret returned string

2009-07-06 Thread Stuart
2009/7/6 John Allsopp j...@johnallsopp.co.uk:
 David Robley wrote:

 John Allsopp wrote:



 Hi

 At the top of a webpage I have:

 ?php
 include_once(furniture.php);
 $myFurniture = new furniture();
 echo $myFurniture-getTop(my company title);
 ?

 to deliver the first lines of HTML, everything in HEAD and the first
 bits of page furniture (menu, etc).

 In the furniture object in getTop(), I want to return a string that
 includes the CSS file that I call with an include_once. But the
 include_once isn't interpreted by PHP, it's just outputted. So from:

        $toReturn = !DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0
 Transitional//EN' 
            ?php
                include_once('styles3.txt');
            ?
            ...;

        return $toReturn;

 I get

 ?php
 include_once('styles3.txt');
 ?

 in my code.

 Do I really have to break up my echo $myFurniture-getTop(my company
 title); call to getTopTop, then include my CSS, then call getTopBottom,
 or can I get PHP to interpret that text that came back?

 PS. I may be stupid, this may be obvious .. I don't program PHP every day

 Thanks in advance for your help :-)

 Cheers
 J


 First guess is that your page doing the including doesn't have a filename
 with a .php extension, and your server is set to only parse php in files
 with a .php extension.



 Cheers


 Ah, thanks. It's a PHP object returning a string, I guess the PHP
 interpreter won't see that.

 So, maybe my object has to write a file that my calling file then includes
 after the object function call. Doesn't sound too elegant, but is that how
 it's gotta be?

You appear to be looking for the eval function: http://php.net/eval

However, in 99.99% of cases using eval is not the right solution. In
your case there are two ways to solve it.

The first way, assuming the thing you're trying to include is a
stylesheet, is to use an external link to a CSS file. That would be
the normal way to include a stylesheet in an HTML page and is far
more efficient that including it inline.

If it's not just a stylesheet that you're including then you'll want
to load the file in the getTop method. For example...

$toReturn = !DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0
Transitional//EN' ;
$toReturn.= file_get_contents('styles3.txt');
$toReturn.= '..';

Simple as that.

-Stuart

-- 
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Call to object function, want to PHP interpret returned string

2009-07-06 Thread David Robley
John Allsopp wrote:

 David Robley wrote:
 John Allsopp wrote:

   
 Hi

 At the top of a webpage I have:

 ?php
 include_once(furniture.php);
 $myFurniture = new furniture();
 echo $myFurniture-getTop(my company title);
 ?

 to deliver the first lines of HTML, everything in HEAD and the first
 bits of page furniture (menu, etc).

 In the furniture object in getTop(), I want to return a string that
 includes the CSS file that I call with an include_once. But the
 include_once isn't interpreted by PHP, it's just outputted. So from:

 $toReturn = !DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0
 Transitional//EN' 
 ?php
 include_once('styles3.txt');
 ?
 ...;

 return $toReturn;

 I get

 ?php
 include_once('styles3.txt');
 ?

 in my code.

 Do I really have to break up my echo $myFurniture-getTop(my company
 title); call to getTopTop, then include my CSS, then call getTopBottom,
 or can I get PHP to interpret that text that came back?

 PS. I may be stupid, this may be obvious .. I don't program PHP every
 day

 Thanks in advance for your help :-)

 Cheers
 J
 

 First guess is that your page doing the including doesn't have a filename
 with a .php extension, and your server is set to only parse php in files
 with a .php extension.



 Cheers
   
 Ah, thanks. It's a PHP object returning a string, I guess the PHP
 interpreter won't see that.
 
 So, maybe my object has to write a file that my calling file then
 includes after the object function call. Doesn't sound too elegant, but
 is that how it's gotta be?
 
 Cheers
 J
I think I misunderstood your explanation :-) Can you show the actual content
of furniture.php? I wonder if there are missing ?php ? tags??



Cheers
-- 
David Robley

And it's only ones and zeros.
Today is Boomtime, the 41st day of Confusion in the YOLD 3175. 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread Stuart
2009/7/6 Lupus Michaelis mickael+...@lupusmic.org:
 Stuart a écrit :

 You appear to be using the definition of null that comes from the
 world of C.

  I didn't. The point is I'm allowed to set a default value to null for a
 referenced parameter (what I can do in C for a pointer, so I knew it).

  I'm happy PHP raises an error on foo(null) ;
  I'm in trouble when foo() doesn't.

  The actual question is : why PHP doesn't raise an error ?

The whole point of default arguments is for it to use that argument if
none is passed.

What makes you think not passing an argument to that function should
raise an error?

-Stuart

-- 
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread Lupus Michaelis

Stuart a écrit :


The whole point of default arguments is for it to use that argument if
none is passed.

  It is not the point too.


What makes you think not passing an argument to that function should
raise an error?
  Maybe because in my example, the provided value is not a valuable 
value for a reference ?


--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

Seeking for a position http://lupusmic.org/pro/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread David Otton
2009/7/6 Lupus Michaelis mickael+...@lupusmic.org:

  I'm happy PHP raises an error on foo(null) ;
  I'm in trouble when foo() doesn't.

  The actual question is : why PHP doesn't raise an error ?

This functionality (default values for passed-by-reference parameters)
was added in PHP5.

The problem is that you can't pass literals by reference (which makes sense):

function f($a) {}
f(45); // error

But default values must be literals (which also makes sense):

function f($a = $_POST) {} // error

So there's some serious impedance mismatch going on there to make both
features to work together. Just think of the default value as
something I can overwrite, eg:

function f($a = 45) { $a = 99; }

So it doesn't really matter if it starts off as 45, 'Hello World' or
null... it's going to get thrown away at the end of the function's
lifetime, anyway.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 64 bit binary ?

2009-07-06 Thread loki

no


Daniel Brown danbr...@php.net wrote in message 
news:ab5568160907051350x530f4efbw96ffc356c15...@mail.gmail.com...

On Sun, Jul 5, 2009 at 15:43, lokiloki5100-newsgr...@yahoo.fr wrote:

Hello

Is it plane to release 64 bit binary for php on windows ?


   Pierre?

--
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread David Otton
2009/7/6 Lupus Michaelis mickael+...@lupusmic.org:

 David Otton a écrit :

 So there's some serious impedance mismatch going on there to make both
 features to work together. Just think of the default value as
 something I can overwrite, eg:

  Thanks for this smart explanation. It shines my day.

np. On reflection, it seems to me that if they were dead-set on
default values for pass-by-reference variables, they should have
dropped the restriction on passing literals by reference at the same
time, and just thrown away the result as happens with default values.
Oh well, it's not my language design.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Function parameter passed by reference with default value to null

2009-07-06 Thread Lupus Michaelis

David Otton a écrit :


So there's some serious impedance mismatch going on there to make both
features to work together. Just think of the default value as
something I can overwrite, eg:


  Thanks for this smart explanation. It shines my day.

--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

Seeking for a position http://lupusmic.org/pro/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Advise on starting a web store site

2009-07-06 Thread Matthew Croud

Hi,

I'm going to start my first e commerce website for a small web shoe  
store.
I think I know enough PHP to keep my head above water, I'm using an  
add on shopping cart package to deal with the transactions.


My question is, what's the best way to design a site where each  
product appears to have its own page.


Is there a way to create the site *without* having each product have a  
physical separate page ?


Is there a method of web design which makes creating new pages simple  
if they all follow the same pattern. i.e thumbnail, description etc.


Thanks guys,

Matt.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 64 bit binary ?

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 06:21, lokiloki5100-newsgr...@yahoo.fr wrote:
 no

Not you.  ;-P

Note that I forwarded the message to the appropriate list --- the
php-windows@ mailing list --- where Pierre Joye hangs out.  He'd be
the one to help you.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Off Subject / Feedback Needed

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 03:03, Karl Jameskarlja...@tampabay.rr.com wrote:
 Team,

 http://www.theufl.com/css/corners.css

 http://www.theufl.com/indexb.htm

 I am trying to get the rounded corners to show in the first row in the HTML
 table.
 Can someone review the code for me?

No, Karl, and please don't ask such questions again on this list.

 I think it has something to do with the images, but I corrected the path and
 uploaded images.

Ask on a CSS or design list instead, please.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Advise on starting a web store site

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 08:15, Matthew Croudm...@obviousdigital.com wrote:
[snip!]

 Is there a way to create the site *without* having each product have a
 physical separate page ?

 Is there a method of web design which makes creating new pages simple if
 they all follow the same pattern. i.e thumbnail, description etc.
[snip!]

Sure, just check Google and look into doing includes, templating,
and using .htaccess with mod_rewrite - an Apache feature and module,
respectively, thus beyond the scope of PHP - to rewrite the URL's.
What this will do, essentially, is create a prettier URL, so
something like:

http://www.example.com/path/to/cart.php?product_id=1234group=987

 could become:

http://www.example.com/p987/1234.html

 or really anything else that you'd like, depending on how you
write your scripts.  Again, though, the full creation of those is
really outside the scope of this list as well, but there are plenty of
open source scripts out there from which you can learn, modify, and
reuse free-of-charge for a commercial webstore.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 02:19, Jason Carsonja...@jasoncarson.ca wrote:

 ok, I have two sets of scripts here. One uses setcookie() for logging into
 the admin panel and the other uses session_start(). Both are working fine,
 is one more secure than the other?

$_COOKIE data is written to a file that is readable/writeable and
stored on the user's side of things.  $_SESSION data is written to the
server, with a cookie stored on the user's side containing just the
PHPSESSID (session ID) string to identify the session file on the
server.

So determining which is better and/or more secure is really a
matter of the data held there and how it's handled.  If storing things
like usernames or you absolutely want to store personal data in an
active session, do so in $_SESSION.  If you're storing a password or
credit card number in the active session, you may as well do it in
$_COOKIE, because you're already using an insecure model.  ;-P

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Lookup domain in directories VS database

2009-07-06 Thread Daniel Brown
2009/7/5 Martin Zvarík mzva...@gmail.com:
 Imagine you are hosting 10.000 subdomains.

Consider it done.

[snip!]

 Everytime visitor hits the page you do:

 @include('t/test-subdomain.freehosting.com/conf.php')

 if (!isset($CONF)) die('such a subdomain does not exist');

 vs

 Everytime visitor hits the page you connect  search in a MySQL table having
 10.000 rows with each domain name and a text field (export_var()) that has
 some parameters you need.

Okay.

 What's better?

This depends on so many external variables that it's really
impossible to give a good answer.  However, while there would be less
overhead to read a small file, I would not give the user the option to
modify a local PHP file (your first solution), which they could do if
it was stored in their local directory.  Conversely, moving it outside
of the user's directory and allowing them to read it from a central
location opens your sites up to some major XSS issues.

So a properly-indexed database would most likely be your best
solution, based upon the limited information we have here so far.  All
in all, if you're running the server as a host with thousands of
sites, you are probably better able to better decide what's in the
best interest of yourself and your users considering the above.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to authnticate and use contents from ${HOME}

2009-07-06 Thread Bastien Koert
Try xamp or one of the preconfigured packages

bastien

On Sunday, July 5, 2009,  schneider.chant...@freenet.de wrote:
 Hello,

 My name ich Chantale, I am 15years old and in a german Lycee. I like to study 
 Informatic in two years and now try to code my first applications. I am new 
 to php and like to code my own Intranet Web-Interface which should run on my 
 FileServer at home.

 I have installed suPHP, but it seems to be not the thing I need, because it 
 works only on a VHost.

 What I need is, that a ${USER} can login and work on her/his ${HOME}.

 How can I archive this?

 Thank you
 Chantale







 #adBox3 {display:none;}



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 

Bastien

Cat, the other other white meat

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Resources for unit tests

2009-07-06 Thread Bob McConnell
I am using Mike Lively's test-harness.php
http://www.digitalsandwich.com/test-harness.php with test-more.php
from Apache::Test for my unit test framework. I have also begun writing
stubs for PostgreSQL functions to run behind that. These tests will be
run on our function libraries as part of the build process just after
code is checked out from the VCS system (Perforce), but before creating
the installation RPMs. i.e. if a unit test fails, report the error and
don't build the RPM.

I am having some difficulty with the Postgres stubs that we don't have
the experience to figure out. Some functions return a resource, which
appears to be a complex form of array. Is there any way to build one
through PHP code, or do I even need to. Since these resources will only
be passed back into a later database call, can I simply replace them in
the stubs with an array? We don't expect to dereference them anyway.

Thank you,

Bob McConnell

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Kim N. Lesmer
On Sun, 5 Jul 2009 14:33:07 -0600
Govinda govinda.webdnat...@gmail.com wrote:

 I am confusing myself reading the docs just now.
 
 i.e.:
 include_path
 basename()
 and dirname()
 
   I had thought from many months ago that
 ?php include '/somedir/somefile.php'; ?
 would include
 somefile.php
 living in
 somedir
 regardless from where in the site structure I am calling it.
 
 Now it does not seem to be doing that.
 
 What is the safest (portable) way to properly build an include path  
 *regardless* from where in my site I am calling the include?
 If I understand right I can put includes in a dir/ specified by the  
 include_path setting, but I also want to know how to do this from
 just within the root of my virtual server.

Like Michael said there is more than one way to deal with this.

I personally prefer to use this:

require_once ($_SERVER['DOCUMENT_ROOT'] . /incl/myfile.php);

Unless the file needs to be kept outside of where the webserver serves
files.

 -Govinda 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


---
Mange venlige hilsner/Best regards

Kim Naim Lesmer
Programmer/Unix systemadministrator

Web: www.bitflop.com
E-mail : k...@bitflop.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] What is this called?

2009-07-06 Thread Miller, Terion
Ok, say you have a database with 16000 records in it, but you only want to
call out say 2000 records at a time as the search/query is performed, then
store the first 2000 in a session and then retrieve the next 2000 etc etc as
a way to minimize server strain?

(I'm tasked to do this and )
1. don't know what this is called to google it...partioning results/data ???

2. Is there a better way to deal with retrieval of large amounts of data
from a large table without choking the server.

3. Is it possible at all

Basically I need to know what it is I'm looking to do, it's not getting
explained in an understandable way herewhich makes google useless

I love my job, I love my jobI love...my job...monday Monday monday



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What is this called?

2009-07-06 Thread Stuart
2009/7/6 Miller, Terion tmil...@springfi.gannett.com:
 Ok, say you have a database with 16000 records in it, but you only want to
 call out say 2000 records at a time as the search/query is performed, then
 store the first 2000 in a session and then retrieve the next 2000 etc etc as
 a way to minimize server strain?

 (I'm tasked to do this and )
 1. don't know what this is called to google it...partioning results/data ???

 2. Is there a better way to deal with retrieval of large amounts of data
 from a large table without choking the server.

 3. Is it possible at all

 Basically I need to know what it is I'm looking to do, it's not getting
 explained in an understandable way herewhich makes google useless

Generally known as paging, and every database server I'm aware of supports it.

MySQL for example...

select * from table limit page,numrows

I would strongly recommend against storing any large dataset in a
session since it will likely be as expensive to load it in as it would
be to do the database query again.

Based on the way you've phrased your question and the 2000 per page
I'm guessing you're not doing this for display purposes. If you're
wanting to lighten the load on the server while you process the 16,000
rows you might want to look into mysql_unbuffered_query which requires
a lot less memory than mysql_query. See the manual for details.

-Stuart

-- 
http://stut.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: What is this called?

2009-07-06 Thread Shawn McKenzie
Miller, Terion wrote:
 Ok, say you have a database with 16000 records in it, but you only want to
 call out say 2000 records at a time as the search/query is performed, then
 store the first 2000 in a session and then retrieve the next 2000 etc etc as
 a way to minimize server strain?
 
 (I'm tasked to do this and )
 1. don't know what this is called to google it...partioning results/data ???
 
 2. Is there a better way to deal with retrieval of large amounts of data
 from a large table without choking the server.
 
 3. Is it possible at all
 
 Basically I need to know what it is I'm looking to do, it's not getting
 explained in an understandable way herewhich makes google useless
 
 I love my job, I love my jobI love...my job...monday Monday monday
 
 

It's called a bad idea.  Instead of doing one query to get your data,
you're going to do eight?

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Govinda

On Jul 5, 2009, at 4:42 PM, Kim N. Lesmer wrote:


Like Michael said there is more than one way to deal with this.

I personally prefer to use this:

require_once ($_SERVER['DOCUMENT_ROOT'] . /incl/myfile.php);

Unless the file needs to be kept outside of where the webserver serves
files.


Kim, this is exactly what I was looking for.  I had been over $_SERVER  
in the docs..  but somehow missed that basic obvious param.  Thanks!

Sudeer, Shawn, Michael,
your efforts were not wasted either.  I absorbed from you all and came  
up with:


define('MY_DOC_ROOT', $_SERVER['DOCUMENT_ROOT']);
set_include_path(MY_DOC_ROOT . PATH_SEPARATOR . get_include_path());
include 'MY_php_functions.inc';

which I call with:
include $_SERVER['DOCUMENT_ROOT'] . '/MY_inc_php/incsInAllPages.inc';

really basic stuff..  humbling for me, coming from other languages/ 
environements where I was more expert.
..lucky me this is such a generous and compassionate group of people  
here.

Thanks again
-Govinda

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What is this called?

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 10:48, Miller,
Teriontmil...@springfi.gannett.com wrote:
 Ok, say you have a database with 16000 records in it, but you only want to
 call out say 2000 records at a time as the search/query is performed, then
 store the first 2000 in a session and then retrieve the next 2000 etc etc as
 a way to minimize server strain?

 (I'm tasked to do this and )
 1. don't know what this is called to google it...partioning results/data ???

As Stuart mentioned, it's known as paging.

 2. Is there a better way to deal with retrieval of large amounts of data
 from a large table without choking the server.

Well, it depends.  You mentioned only that it's a database.  Is it
an SQL database?  If so, what's the engine (MySQL, PostgreSQL,
Informix, SQLite, MSSQL, etc.)?  If not, what's the format?

Also, how frequently will this be called, how large is each row of
data (in bytes or kilobytes), and what other things are running on the
same server at the same time?  Is it a production web server or
internal intranet?  Is it a shared web server?

As you see, there are a ton of other factors and variables involved.  ;-P

 3. Is it possible at all

Absolutely.  Through PHP, al(most al)l things are possible.

 Basically I need to know what it is I'm looking to do, it's not getting
 explained in an understandable way herewhich makes google useless

We all have days like that, Teri.  I have ~365.25 of them each year

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What is this called?

2009-07-06 Thread Wolf

 Miller wrote: 
 Ok, say you have a database with 16000 records in it, but you only want to
 call out say 2000 records at a time as the search/query is performed, then
 store the first 2000 in a session and then retrieve the next 2000 etc etc as
 a way to minimize server strain?
 
 (I'm tasked to do this and )
 1. don't know what this is called to google it...partioning results/data ???
 
 2. Is there a better way to deal with retrieval of large amounts of data
 from a large table without choking the server.
 
 3. Is it possible at all
 
 Basically I need to know what it is I'm looking to do, it's not getting
 explained in an understandable way herewhich makes google useless
 

Basically, go smack whomever told you to load all that stuff into a session.  
It's a paging query that you want to do, but I'd not recommend doing it to 
store it in a session.

You can store all that stuff into a session, but you risk putting a greater 
load on the users session then you would be putting on the database server.

If you are running MySQL, go get a 486, put Fedora on it and use it for the 
heavy queries.  

HTH,
Wolf

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What is this called?

2009-07-06 Thread Miller, Terion



On 7/6/09 10:07 AM, Daniel Brown danbr...@php.net wrote:

On Mon, Jul 6, 2009 at 10:48, Miller,
Teriontmil...@springfi.gannett.com wrote:
 Ok, say you have a database with 16000 records in it, but you only want to
 call out say 2000 records at a time as the search/query is performed, then
 store the first 2000 in a session and then retrieve the next 2000 etc etc as
 a way to minimize server strain?

 (I'm tasked to do this and )
 1. don't know what this is called to google it...partioning results/data ???

As Stuart mentioned, it's known as paging.

 2. Is there a better way to deal with retrieval of large amounts of data
 from a large table without choking the server.

Well, it depends.  You mentioned only that it's a database.  Is it
an SQL database?  If so, what's the engine (MySQL, PostgreSQL,
Informix, SQLite, MSSQL, etc.)?  If not, what's the format?

Also, how frequently will this be called, how large is each row of
data (in bytes or kilobytes), and what other things are running on the
same server at the same time?  Is it a production web server or
internal intranet?  Is it a shared web server?

As you see, there are a ton of other factors and variables involved.  ;-P

 3. Is it possible at all

Absolutely.  Through PHP, al(most al)l things are possible.

 Basically I need to know what it is I'm looking to do, it's not getting
 explained in an understandable way herewhich makes google useless

We all have days like that, Teri.  I have ~365.25 of them each year

--
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig


LOL Daniel I myself have at least 365 days of them too

It seems like Pagination except I already have that in place for all records, 
so maybe I'm just looking for a way to page the search results...
Boss kept referring to partitioning results




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 11:04, Govindagovinda.webdnat...@gmail.com wrote:

 Kim, this is exactly what I was looking for.  I had been over $_SERVER in
 the docs..  but somehow missed that basic obvious param.  Thanks!

And now I'll throw a monkey wrench into the gears and tell you
that, yes, it works, but don't always rely on it.  The path translated
to/from the web server may not be the real path.  And while you could
do your translation with realpath(), instead you should look into:

?php include(dirname(dirname(__FILE__)).'/include/file.php'); ?

The example above uses the always-on reserved constant __FILE__
for the file in which it's written, regardless of how it's accessed
(as an include, etc.).  So consider the following:

/home/user/public_html/index.php
/home/user/public_html/web/home.php
/home/user/public_html/templates/body.tpl.php
/home/user/public_html/include/file.php

In the example above, imagine that you access 'index.php', which
includes 'home.php', which - in turn - includes 'body.tpl.php' and
'file.php'.  Using $_SERVER data will use the information given to it
by the webserver at the point of the call: in this case, from
/home/user/public_html/index.php.  As such, the include path will be
relative to that.  So if you're including a file in ./web/home.php,
you will need to hard-code the adjustment to account for the
difference.

Conversely, using the code example from above (and building upon
it), we know that __FILE__ remains static regardless of the point of
the call.  Thus, it's a better and more reliable method, and is usable
even if $_SERVER data is not available to the script.

With this in mind, it should be quite simple to understand how the
following should work:

?php
// My Name: /home/user/public_html/web/home.php

$file_to_include = dirname(dirname(__FILE__)).'/include/file.php';

if(file_exists($file_to_include)  is_readable($file_to_include)) {
include($file_to_include);
} else {
// Do your error handling here.
}
?

 but to each his/her own!  ;-P

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What is this called?

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 11:15, Miller,
Teriontmil...@springfi.gannett.com wrote:

 It seems like Pagination except I already have that in place for all records, 
 so maybe I'm just looking for a way to page the search results...
 Boss kept referring to partitioning results

By definition, yes, but if you use the term 'partition' in
industry terminology - indeed, in SQL commands - you'll wind up with a
different result.

If you haven't yet come across it, look up 'mysql range
partitioning' on Google.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Michael Shadle
On Mon, Jul 6, 2009 at 8:24 AM, Daniel Brownparas...@gmail.com wrote:

    Conversely, using the code example from above (and building upon
 it), we know that __FILE__ remains static regardless of the point of
 the call.  Thus, it's a better and more reliable method, and is usable
 even if $_SERVER data is not available to the script.

+1 - i use dirname(__FILE__) everywhere. Rasmus said you can just use
./includes/foo.php, why have an extra function call (the dirname) but
i tried that on one of my setups and what is odd is it couldn't find
the files from the forced relative paths which should work just fine.
there could have been other weird voodoo going on too, but i know for
a fact dirname(__FILE__) has been reliable and the best part is it
does not require $_SERVER.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_replace with UTF-8

2009-07-06 Thread Georgi Alexandrov
On Mon, Jul 6, 2009 at 4:54 AM, SleePy sleepingkil...@gmail.com wrote:

 I seem to be having a minor issue with preg_replace not working as expected
 when using UTF-8 strings. So far I have found out that \w doesn't seem to be
 detecting UTF-8 strings.

 This is my test php file:
 ?php
 $data = 'ooo';
 echo 'Data before: ', $data, 'br /';

 $data = preg_replace('~([\w\.]{6})~u', '$1  ', $data);
 echo 'Data After: ', $data;

 // UTF-8 Test
 $data = 'ффф';
 echo 'hr /Data before: ', $data, 'br /';

 $data = preg_replace('~([\w\.]{6})~u', '$1  ', $data);
 echo 'Data After: ', $data;

 ?


 I would expect it to be:
 Data before: ooo
 Data After: oo  oo  oo  o
 ---
 Data before: ффф
 Data After: фф фф фф ф

 But what I get is:
 Data before: ooo
 Data After: oo  oo  oo  o
 ---
 Data before: ффф
 Data After: ффф

 Did I go about this the wrong way or is this a php bug itself?
 I tested this in php 5.3, 5.2.9 and 6.0 (snapshot from a couple weeks ago)
 and received the same results.


Did you tried mb_ereg_replace?





 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] porting C code to php

2009-07-06 Thread Steve Hanselman
Hi,

I've some C code that processes files, I want to port this to PHP and am trying 
to decide the best way to port the structs and unions over so as to still be 
readable?

The files are multi-line files with differing layouts depending on the data 
contained within them, so at present unions of structs work very well for this.

I'm loathe to turn this code into substr's of the input line, has anybody any 
other ideas?

Regards

Steve



The information contained in this email is intended for the personal and 
confidential use
of the addressee only. It may also be privileged information. If you are not 
the intended
recipient then you are hereby notified that you have received this document in 
error and
that any review, distribution or copying of this document is strictly 
prohibited. If you have
received  this communication in error, please notify Brendata immediately on:

+44 (0)1268 466100, or email 'techni...@brendata.co.uk'

Brendata (UK) Ltd
Nevendon Hall, Nevendon Road, Basildon, Essex. SS13 1BX  UK
Registered Office as above. Registered in England No. 2764339

See our current vacancies at www.brendata.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_replace with UTF-8

2009-07-06 Thread SleePy

Thank you Andrew,
That seems to break up UTF-8 strings. So from there I will play with it.

On Jul 6, 2009, at 8:50 AM, Andrew Ballard wrote:

On Sun, Jul 5, 2009 at 9:54 PM, SleePysleepingkil...@gmail.com  
wrote:
I seem to be having a minor issue with preg_replace not working as  
expected
when using UTF-8 strings. So far I have found out that \w doesn't  
seem to be

detecting UTF-8 strings.

This is my test php file:
?php
$data = 'ooo';
echo 'Data before: ', $data, 'br /';

$data = preg_replace('~([\w\.]{6})~u', '$1  ', $data);
echo 'Data After: ', $data;

// UTF-8 Test
$data = 'ффф';
echo 'hr /Data before: ', $data, 'br /';

$data = preg_replace('~([\w\.]{6})~u', '$1  ', $data);
echo 'Data After: ', $data;

?


I would expect it to be:
Data before: ooo
Data After: oo  oo  oo  o
---
Data before: ффф
Data After: фф фф фф ф

But what I get is:
Data before: ooo
Data After: oo  oo  oo  o
---
Data before: ффф
Data After: ффф

Did I go about this the wrong way or is this a php bug itself?
I tested this in php 5.3, 5.2.9 and 6.0 (snapshot from a couple  
weeks ago)

and received the same results.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




From the manual on PCRE syntax:
A 'word' character is any letter or digit or the underscore
character, that is, any character which can be part of a Perl 'word'.
The definition of letters and digits is controlled by PCRE's character
tables, and may vary if locale-specific matching is taking place. For
example, in the 'fr' (French) locale, some character codes greater
than 128 are used for accented letters, and these are matched by \w.

These character type sequences can appear both inside and outside
character classes. They each match one character of the appropriate
type. If the current matching point is at the end of the subject
string, all of them fail, since there is no character to match.

I'm not sure if this is exactly what you want (or if it might let more
things slip past than you intend), but try this:

?php
$data = 'ooo';
echo 'Data before: ', $data, 'br /';

$data = preg_replace('~([\w\pL\.]{6})~u', '$1  ', $data);
echo 'Data After: ', $data;

// UTF-8 Test
$data = 'ффф';
echo 'hr /Data before: ', $data, 'br /';

$data = preg_replace('~([\w\pL\.]{6})~u', '$1  ', $data);
echo 'Data After: ', $data;

?

Andrew



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-06 Thread Jason Carson
 On Mon, Jul 6, 2009 at 02:19, Jason Carsonja...@jasoncarson.ca wrote:

 ok, I have two sets of scripts here. One uses setcookie() for logging
 into
 the admin panel and the other uses session_start(). Both are working
 fine,
 is one more secure than the other?

 $_COOKIE data is written to a file that is readable/writeable and
 stored on the user's side of things.  $_SESSION data is written to the
 server, with a cookie stored on the user's side containing just the
 PHPSESSID (session ID) string to identify the session file on the
 server.

 So determining which is better and/or more secure is really a
 matter of the data held there and how it's handled.  If storing things
 like usernames or you absolutely want to store personal data in an
 active session, do so in $_SESSION.  If you're storing a password or
 credit card number in the active session, you may as well do it in
 $_COOKIE, because you're already using an insecure model.  ;-P

 --
 /Daniel P. Brown
 daniel.br...@parasane.net || danbr...@php.net
 http://www.parasane.net/ || http://www.pilotpig.net/
 Check out our great hosting and dedicated server deals at
 http://twitter.com/pilotpig

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Well I'm a newbie when it comes to PHP and programming. I guess I need to
read up on login security. Do you know of, or recommend, any websites that
will show me how to secure my login model (Using cookies or sessions).



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What is this called?

2009-07-06 Thread Daevid Vincent
 -Original Message-
 From: Wolf [mailto:lonew...@nc.rr.com] 
 Sent: Monday, July 06, 2009 8:10 AM
 
 If you are running MySQL, go get a 486, put Fedora on it and 
 use it for the heavy queries.  

You didn't seriously just tell someone to use an ancient-ass __80486__ PC
for their heavy database queries did you? Aside from the fact that machine
is like 20 years old and not only would hardware be difficult to find, setup
and maintain, it's bound to die at any moment. You're talking ISA (maybe a
PCI if you're lucky), IDE drives, slow RAM that probably maxes at 512MB or
something... No USB ports, so have fun finding an old mouse/keyboard.

A computer with vastly superior technology, reliability and performance can
be had for a hundred bucks and probably even free. I just gave away a 1Ghz
Celleron the other day that was collecting dust. I wouldn't even use THAT as
my database server with hardware as dirt cheap as it is...

Dude.

Save yourself the headaches and just get a modern, NEW barebones PC:

http://www.pricewatch.com/barebones_computers/
http://www.pricewatch.com/computer_systems_no_os/

and throw your favorite Linux distro on it 
(I'm not touching that holy war with a 10' eth0 cord)

Most all distros come with LAMP stacks as an option and you're off and
running in about an hour.

:D:


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] LIMIT and SESSION WAS: What is this called?

2009-07-06 Thread Daevid Vincent
 -Original Message-
 From: Wolf [mailto:lonew...@nc.rr.com] 
 Sent: Monday, July 06, 2009 8:10 AM

 Basically, go smack whomever told you to load all that stuff 
 into a session.  It's a paging query that you want to do, but 
 I'd not recommend doing it to store it in a session.
 
 You can store all that stuff into a session, but you risk 
 putting a greater load on the users session then you would be 
 putting on the database server.

http://dev.mysql.com/doc/refman/5.0/en/select.html

You want to use limit.

As for storing all the results, there most likely isn't a reason to, however
if you must do it that way (perhaps you have a  and  button or something
to step through), then I suggest you save the __row ID's only__ in a
$_SESSION array variable and do a SELECT via the ID (and LIMIT 1 can't
hurt either in case you're storing a SKU_ID or some other unique key but
it's not a primary key) as you're stepping. This way your bulky query is
only done once. This is a more advanced technique however and may be
confusing to you if you don't know what you're doing. 

You can also pull all these items faster on subsequent pages by doing an
WHERE item.id IN ($myarray) type of deal (pseudo code of course). 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-06 Thread PJ
Jason Carson wrote:
 On Mon, Jul 6, 2009 at 02:19, Jason Carsonja...@jasoncarson.ca wrote:
 
 ok, I have two sets of scripts here. One uses setcookie() for logging
 into
 the admin panel and the other uses session_start(). Both are working
 fine,
 is one more secure than the other?
   
 $_COOKIE data is written to a file that is readable/writeable and
 stored on the user's side of things.  $_SESSION data is written to the
 server, with a cookie stored on the user's side containing just the
 PHPSESSID (session ID) string to identify the session file on the
 server.

 So determining which is better and/or more secure is really a
 matter of the data held there and how it's handled.  If storing things
 like usernames or you absolutely want to store personal data in an
 active session, do so in $_SESSION.  If you're storing a password or
 credit card number in the active session, you may as well do it in
 $_COOKIE, because you're already using an insecure model.  ;-P

 --
 /Daniel P. Brown
 daniel.br...@parasane.net || danbr...@php.net
 http://www.parasane.net/ || http://www.pilotpig.net/
 Check out our great hosting and dedicated server deals at
 http://twitter.com/pilotpig

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 
 Well I'm a newbie when it comes to PHP and programming. I guess I need to
 read up on login security. Do you know of, or recommend, any websites that
 will show me how to secure my login model (Using cookies or sessions).

   
Hi Jason,
I'm probably not any wiser than you, but I have just (today) discovered
an interesting site that seems to have some really clear explanations
and tutorials re php, MySsql et al.
It's worth looking at (I'm trying to implement something like what you
are, as well):
http://www.brainbell.com/tutors/php/php_mysql/Authorizing_User_Access.html
HTH,
PJ

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to stop E_DEPRECATED messages in the PHP log?

2009-07-06 Thread Jeff Weinberger

Hi:

I am hoping someone can help me figure this out

I've just upgraded my PHP installation to 5.3.0. Now I am receiving  
thousands of log messages of the form PHP Deprecated: 


I know I have a number of scripts that use now-deprecated functions,  
etc. and I now know what those are, thanks to all the messages.


However, this is now growing to (literally) gigabytes of log entries,  
so I'd like to stop the messages until I have the time to re-write all  
the offending scripts.


I have tried the following error.reporting lines in php.ini:

error_reporting = E_ALL  ~E_DEPRECATED  E_ERROR  E_WARNING   
E_PARSE  E_NOTICE  E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING   
E_USER_NOTICE  E_COMPILE_ERROR  E_COMPILE_WARNING


error_reporting = ~E_DEPRECATED  E_ALL  E_ERROR  E_WARNING   
E_PARSE  E_NOTICE  E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING   
E_USER_NOTICE  E_COMPILE_ERROR  E_COMPILE_WARNING


error_reporting =  E_ALL  E_ERROR  E_WARNING  E_PARSE  E_NOTICE   
E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING  E_USER_NOTICE   
E_COMPILE_ERROR  E_COMPILE_WARNING  ~E_DEPRECATED


error_reporting = E_ERROR  E_CORE_ERROR  E_USER_ERROR   
E_COMPILE_ERROR  E_COMPILE_WARNING  ~E_DEPRECATED


error_reporting = ~E_DEPRECATED  E_ERROR  E_CORE_ERROR   
E_USER_ERROR  E_COMPILE_ERROR  E_COMPILE_WARNING


(as you can tell, I prefer verbose logs, but not that verbose...).

None of these combinations have stopped the  PHP Deprecated: ...  
messages.


System info: Mac OS/X 10.5.7 Client version, PHP 5.3.0 running as a  
CGI under Apache 2.2.11 and as a CLI. Please let me know if there's  
any other info that might help.


php_info() reports error.reporting as 0

Any help or guidance is appreciated!!

Thanks,

--Jeff



No one ever achieved greatness by playing it safe. -Harry Gray


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple login form with cookies

2009-07-06 Thread Jason Carson
 Jason Carson wrote:
 On Mon, Jul 6, 2009 at 02:19, Jason Carsonja...@jasoncarson.ca wrote:

 ok, I have two sets of scripts here. One uses setcookie() for logging
 into
 the admin panel and the other uses session_start(). Both are working
 fine,
 is one more secure than the other?

 $_COOKIE data is written to a file that is readable/writeable and
 stored on the user's side of things.  $_SESSION data is written to the
 server, with a cookie stored on the user's side containing just the
 PHPSESSID (session ID) string to identify the session file on the
 server.

 So determining which is better and/or more secure is really a
 matter of the data held there and how it's handled.  If storing things
 like usernames or you absolutely want to store personal data in an
 active session, do so in $_SESSION.  If you're storing a password or
 credit card number in the active session, you may as well do it in
 $_COOKIE, because you're already using an insecure model.  ;-P

 --
 /Daniel P. Brown
 daniel.br...@parasane.net || danbr...@php.net
 http://www.parasane.net/ || http://www.pilotpig.net/
 Check out our great hosting and dedicated server deals at
 http://twitter.com/pilotpig

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 Well I'm a newbie when it comes to PHP and programming. I guess I need
 to
 read up on login security. Do you know of, or recommend, any websites
 that
 will show me how to secure my login model (Using cookies or sessions).


 Hi Jason,
 I'm probably not any wiser than you, but I have just (today) discovered
 an interesting site that seems to have some really clear explanations
 and tutorials re php, MySsql et al.
 It's worth looking at (I'm trying to implement something like what you
 are, as well):
 http://www.brainbell.com/tutors/php/php_mysql/Authorizing_User_Access.html
 HTH,
 PJ

 --
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


I'll check it out this evening when I have some time. Thanks for the link.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to authnticate and use contents from ${HOME}

2009-07-06 Thread Isaac Dover
Hi Chantale, as Bastien mentioned, a preconfigured package might be the best
way to go. Wikipedia has more information:

http://en.wikipedia.org/wiki/List_of_LAMP_Packages

What are you wanting to build in your interface?

 - Isaac

On Mon, Jul 6, 2009 at 9:14 AM, Bastien Koert phps...@gmail.com wrote:

 Try xamp or one of the preconfigured packages

 bastien

 On Sunday, July 5, 2009,  schneider.chant...@freenet.de wrote:
  Hello,
 
  My name ich Chantale, I am 15years old and in a german Lycee. I like to
 study Informatic in two years and now try to code my first applications. I
 am new to php and like to code my own Intranet Web-Interface which should
 run on my FileServer at home.
 
  I have installed suPHP, but it seems to be not the thing I need, because
 it works only on a VHost.
 
  What I need is, that a ${USER} can login and work on her/his ${HOME}.
 
  How can I archive this?
 
  Thank you
  Chantale
 
 
 
 
 
 
 
  #adBox3 {display:none;}
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

 --

 Bastien

 Cat, the other other white meat

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Govinda

On Jul 6, 2009, at 9:24 AM, Daniel Brown wrote:

On Mon, Jul 6, 2009 at 11:04, Govindagovinda.webdnat...@gmail.com  
wrote:


Kim, this is exactly what I was looking for.  I had been over  
$_SERVER in

the docs..  but somehow missed that basic obvious param.  Thanks!


   And now I'll throw a monkey wrench into the gears and tell you
that, yes, it works, but don't always rely on it.  The path translated
to/from the web server may not be the real path.  And while you could
do your translation with realpath(), instead you should look into:

   ?php include(dirname(dirname(__FILE__)).'/include/ 
file.php'); ?


   The example above uses the always-on reserved constant __FILE__
for the file in which it's written, regardless of how it's accessed
(as an include, etc.).  So consider the following:

   /home/user/public_html/index.php
   /home/user/public_html/web/home.php
   /home/user/public_html/templates/body.tpl.php
   /home/user/public_html/include/file.php

   In the example above, imagine that you access 'index.php', which
includes 'home.php', which - in turn - includes 'body.tpl.php' and
'file.php'.  Using $_SERVER data will use the information given to it
by the webserver at the point of the call: in this case, from
/home/user/public_html/index.php.  As such, the include path will be
relative to that.  So if you're including a file in ./web/home.php,
you will need to hard-code the adjustment to account for the
difference.

   Conversely, using the code example from above (and building upon
it), we know that __FILE__ remains static regardless of the point of
the call.  Thus, it's a better and more reliable method, and is usable
even if $_SERVER data is not available to the script.

   With this in mind, it should be quite simple to understand how the
following should work:

?php
// My Name: /home/user/public_html/web/home.php

$file_to_include = dirname(dirname(__FILE__)).'/include/file.php';

if(file_exists($file_to_include)  is_readable($file_to_include)) {
   include($file_to_include);
} else {
   // Do your error handling here.
}
?

    but to each his/her own!  ;-P


Michael and Dan

this is great, but then I still do not have a solution that will work  
for any level deep of dir/ .

I.e. this-
dirname(dirname(__FILE__))
gives the correct first part of the path to document root like  
$_SERVER['DOCUMENT_ROOT'] does

only when called from a file that is 2 levels deep.
I want something that will work for calling an include from any file  
that lives n levels deep.
Isn't there anything reliable that effectively says, from document  
root??

I do not really understand why
$_SERVER['DOCUMENT_ROOT']
should return the right data at one time and not at another.  (?)

--

Also, what is the difference between a path that starts with /,  
versus the same path but that does not have that leading /, or that  
same path but prefixed with ./?

I.e., this:
/somepath/includes/file.php
versus this:
somepath/includes/file.php
versus this:
./somepath/includes/file.php

(../ I know)

-G

Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Kim N. Lesmer
On Mon, 6 Jul 2009 16:16:55 -0600
Govinda govinda.webdnat...@gmail.com wrote:

 I do not really understand why
 $_SERVER['DOCUMENT_ROOT']
 should return the right data at one time and not at another.  (?)

In general it will always provide the right data, but as the manual
says: The entries in this array ($_SERVER) are created by the web
server. There is no guarantee that every web server will provide any of
these; servers may omit some.

The problem could arise if the script is transfered unto a web server
where the $_SERVER array (or parts of it - in this case the
document_root part) has been disabled.

Take into consideration where the script/program has to run and whether
it is likely to be moved around to different web servers with different
setups.

 Also, what is the difference between a path that starts with /,  
 versus the same path but that does not have that leading /, or
 that same path but prefixed with ./?

 I.e., this:
 /somepath/includes/file.php

This depends on whether the web server is running in a chroot.

If the web server for example has access to all files on the machine
and isn't running in any kind of chroot or limited setup, then
/somepath is located in the very root of the directory on that
particular hard drive (or partition) and /somepath is NOT a sub
directory of another directory.

So you would see something like this (if you are not using Windows):

/var/www/mywebsite.com/
/somepath/includes/file.php
/usr/sbin/
/home/foo/

 versus this:
 somepath/includes/file.php

This depends on where your script is running from. 

If your script is running in: 
/var/www/mywebsite.com/myscript.php

Then the above would become:
/var/www/mywebsite.com/somepath/includes/file.php

If your script is running in: 
/var/www/mywebsite.com/subdirectory/myscript.php

Then the above would become:
/var/www/mywebsite.com/subdirectory/somepath/includes/file.php

 versus this:
 ./somepath/includes/file.php

Its the same as somepath/includes/file.php a ./ means current
working directory.

I hope I make sense.

If you haven't already take a look at:
http://php.net/manual/en/function.include.php

 (../ I know)
 
 -G


---
Mange venlige hilsner/Best regards

Kim Naim Lesmer
Programmer/Unix systemadministrator

Web: www.bitflop.com
E-mail : k...@bitflop.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Daniel Brown
On Mon, Jul 6, 2009 at 18:16, Govindagovinda.webdnat...@gmail.com wrote:

 this is great, but then I still do not have a solution that will work for
 any level deep of dir/ .
 I.e. this-
 dirname(dirname(__FILE__))
 gives the correct first part of the path to document root like
 $_SERVER['DOCUMENT_ROOT'] does
 only when called from a file that is 2 levels deep.
 I want something that will work for calling an include from any file that
 lives n levels deep.

That's where you have to define a variable (or constant) that
tells the system where the web root is located, and then use that to
determine where you are in relation to that.  For example:

?php

function relate_path($me,$root = '/home/pilotpig/public_html') {
if(preg_match('/\/.*\.[a-z0-9]{2,5}$/Ui',$me)) { // If a file with
extension 2-5 alphanum chars
$me = dirname($me); // Strip the filename

// Then loop through the correct number of times.
for($i=0;$i(substr_count($me,'/') - substr_count($root,'/'));$i++) {
$me = dirname($me);
}

return $me; // Returns the resulting path.
}

return false; // If we were unable to get the path.
}

/*
Then use it as follows, presuming this file is
named /home/user/public_html/web/home.php
*/
if(($path = relate_path(__FILE__)) !== false) {
include($path.'/include/config.php');
} else {
// Handle the error for the incorrect inclusion attempt.
}
?

Voila!

 Also, what is the difference between a path that starts with /, versus the
 same path but that does not have that leading /, or that same path but
 prefixed with ./?
 I.e., this:
 /somepath/includes/file.php

 is a true (absolute) path.

 versus this:
 somepath/includes/file.php

 is a relative path from wherever the file is called.

 versus this:
 ./somepath/includes/file.php

 is a relative path from the CWD/PWD (Current Working
Directory/Present Working Directory).


P.S. - The function is untested, just rattled off from my brain
while I cook dinner, so if it doesn't work, at least you should get
the gist of where I'm going but try it anyway.  ;-P

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Govinda
I want something that will work for calling an include from any  
file that

lives n levels deep.


   That's where you have to define a variable (or constant) that
tells the system where the web root is located, and then use that to
determine where you are in relation to that.  For example:

?php

function relate_path($me,$root = '/home/pilotpig/public_html') {
   if(preg_match('/\/.*\.[a-z0-9]{2,5}$/Ui',$me)) { // If a file with
extension 2-5 alphanum chars
   $me = dirname($me); // Strip the filename

   // Then loop through the correct number of times.
   for($i=0;$i(substr_count($me,'/') - substr_count($root,'/')); 
$i++) {

   $me = dirname($me);
   }

   return $me; // Returns the resulting path.
   }

   return false; // If we were unable to get the path.
}

/*
   Then use it as follows, presuming this file is
   named /home/user/public_html/web/home.php
*/
if(($path = relate_path(__FILE__)) !== false) {
   include($path.'/include/config.php');
} else {
   // Handle the error for the incorrect inclusion attempt.
}
?

   Voila!

Also, what is the difference between a path that starts with /,  
versus the
same path but that does not have that leading /, or that same  
path but

prefixed with ./?
I.e., this:
/somepath/includes/file.php


    is a true (absolute) path.


versus this:
somepath/includes/file.php


    is a relative path from wherever the file is called.


versus this:
./somepath/includes/file.php


    is a relative path from the CWD/PWD (Current Working
Directory/Present Working Directory).


   P.S. - The function is untested, just rattled off from my brain
while I cook dinner, so if it doesn't work, at least you should get
the gist of where I'm going but try it anyway.  ;-P


Dan I love to see smart hacks in action!  ..and I believe I get what  
you are doing.
I am just amazed that there is not a SIMPLE (one-liner) reliable way  
of just saying document root without a complex function like that.
I mean what we need here is a global include path for the shared- 
hosted user ..  an include_path that can be set for the virtual server  
user and it 'sticks' (does not have to be set on every page load).
 I think I'll let this all go for now...  I have a lot of basics to  
cover before I trip out too much in any one area.  I'm going to need  
the time and brain juice for some 'real' issues later  ;-)

-G

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Paul M Foster
On Mon, Jul 06, 2009 at 07:15:03PM -0600, Govinda wrote:

snip


 Dan I love to see smart hacks in action!  ..and I believe I get what
 you are doing.
 I am just amazed that there is not a SIMPLE (one-liner) reliable way
 of just saying document root without a complex function like that.
 I mean what we need here is a global include path for the shared-
 hosted user ..  an include_path that can be set for the virtual server
 user and it 'sticks' (does not have to be set on every page load).
  I think I'll let this all go for now...  I have a lot of basics to
 cover before I trip out too much in any one area.  I'm going to need
 the time and brain juice for some 'real' issues later  ;-)

I'm not sure how this could be made simpler.

$site_root = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR;

Call that in any file in the root of *your* web directories, and you
have what is essentially the document root for *your* site.
Presumably, you know the *relative* directories of all your files.
Simply append those relative directories + filenames to the $site_root
variable, and you're done.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Advise on starting a web store site

2009-07-06 Thread Paul M Foster
On Mon, Jul 06, 2009 at 01:15:10PM +0100, Matthew Croud wrote:

 Hi,

 I'm going to start my first e commerce website for a small web shoe
 store.
 I think I know enough PHP to keep my head above water, I'm using an
 add on shopping cart package to deal with the transactions.

 My question is, what's the best way to design a site where each
 product appears to have its own page.

 Is there a way to create the site *without* having each product have a
 physical separate page ?

 Is there a method of web design which makes creating new pages simple
 if they all follow the same pattern. i.e thumbnail, description etc.

Years ago, I used osCommerce for a site like this, and configured it to
present a page full of items in one category. This wasn't done through
PHP but through just configuring osCommerce. I'm not recommending
osCommerce per se (I think it's currently not well maintained), but it
stands to reason that other similar ecommerce suites would allow the
same capability.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] porting C code to php

2009-07-06 Thread Paul M Foster
On Mon, Jul 06, 2009 at 05:24:32PM +0100, Steve Hanselman wrote:

 Hi,
 
 I've some C code that processes files, I want to port this to PHP and am 
 trying to decide the best way to port the structs and unions over so as to 
 still be readable?
 
 The files are multi-line files with differing layouts depending on the data 
 contained within them, so at present unions of structs work very well for 
 this.
 
 I'm loathe to turn this code into substr's of the input line, has anybody any 
 other ideas?

You could get fancy and handle this with different classes for each
different filetype. Build a parent class which is extended for each
child class.

Or you could just use arrays. Since arrays in PHP can store any type of
data in virtually any configuration, they are roughly equivalent to a
struct in C. The union part isn't necessary, since you can simply
redefine an array or define a different array, depending on the
circumstances.

Your last paragraph puzzled me. I'm guessing that you're reading from
the file some header info (to determine the file type) and then reading
the rest of the file one struct at a time? If so, no, you can't do that
in PHP that way. You could use an fread() call, and read in the number
of bytes you want for a given struct/array, but you're still going to
have to parse the bytes to put them into their respective array members.
You might also try fscanf(), but I'm not sure it will understand binary
data in your file (like floats). Also look at pack() and unpack(), as
these will, to some extent, read and write binary values.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to stop E_DEPRECATED messages in the PHP log?

2009-07-06 Thread Paul M Foster
On Mon, Jul 06, 2009 at 02:16:09PM -0700, Jeff Weinberger wrote:

 Hi:

 I am hoping someone can help me figure this out

 I've just upgraded my PHP installation to 5.3.0. Now I am receiving
 thousands of log messages of the form PHP Deprecated: 

 I know I have a number of scripts that use now-deprecated functions,
 etc. and I now know what those are, thanks to all the messages.

 However, this is now growing to (literally) gigabytes of log entries,
 so I'd like to stop the messages until I have the time to re-write all
 the offending scripts.

 I have tried the following error.reporting lines in php.ini:

 error_reporting = E_ALL  ~E_DEPRECATED  E_ERROR  E_WARNING 
 E_PARSE  E_NOTICE  E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING 
 E_USER_NOTICE  E_COMPILE_ERROR  E_COMPILE_WARNING

 error_reporting = ~E_DEPRECATED  E_ALL  E_ERROR  E_WARNING 
 E_PARSE  E_NOTICE  E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING 
 E_USER_NOTICE  E_COMPILE_ERROR  E_COMPILE_WARNING

 error_reporting =  E_ALL  E_ERROR  E_WARNING  E_PARSE  E_NOTICE 
 E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING  E_USER_NOTICE 
 E_COMPILE_ERROR  E_COMPILE_WARNING  ~E_DEPRECATED

 error_reporting = E_ERROR  E_CORE_ERROR  E_USER_ERROR 
 E_COMPILE_ERROR  E_COMPILE_WARNING  ~E_DEPRECATED

 error_reporting = ~E_DEPRECATED  E_ERROR  E_CORE_ERROR 
 E_USER_ERROR  E_COMPILE_ERROR  E_COMPILE_WARNING

 (as you can tell, I prefer verbose logs, but not that verbose...).

 None of these combinations have stopped the  PHP Deprecated: ...
 messages.

 System info: Mac OS/X 10.5.7 Client version, PHP 5.3.0 running as a
 CGI under Apache 2.2.11 and as a CLI. Please let me know if there's
 any other info that might help.

 php_info() reports error.reporting as 0

 Any help or guidance is appreciated!!

Try 

error_reporting(E_ALL ^ E_DEPRECATED);

See http://us2.php.net/manual/en/function.error-reporting.php for more
info and examples.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Clancy
On Sun, 5 Jul 2009 14:33:07 -0600, govinda.webdnat...@gmail.com (Govinda) wrote:

I am confusing myself reading the docs just now.

i.e.:
include_path
basename()
and dirname()

  I had thought from many months ago that
?php include '/somedir/somefile.php'; ?
would include
somefile.php
living in
somedir
regardless from where in the site structure I am calling it.

Now it does not seem to be doing that.

What is the safest (portable) way to properly build an include path  
*regardless* from where in my site I am calling the include?
If I understand right I can put includes in a dir/ specified by the  
include_path setting, but I also want to know how to do this from just  
within the root of my virtual server.

I have developed a quite sophisticated development system, which enables me to 
have
several different websites using the same software, and allows them all to 
share the same
utilities. I know some of you don't like some of the methods I use, but I think 
the
general idea is relevant to this discussion.

Each website has a local directory:
D:Websites/Website_1
D:Websites/Website_2
etc.
I also have an independent directory containing the common utilities for all 
the websites:
D:Utilities

Each website has one or more divisions, corresponding very roughly to photo 
albums. It
also has one directory containing the developmental version of the program, and 
a second
containing the working version of the program e.g.
Dev
Wkg
Album_1
etc.
The remote version of each website only has the directories:
Wkg
Utilities
Album_1
etc.

a new web page is invoked with the command: 
http://localhost/Website_1/index.php
or
http://www.corybas.com/index.php

If I want to ensure that a fresh version is loaded I add the parameter: ?new=1, 
and if I
want to invoke the developmental version, I followed this with the parameter:
local_dir=Dev.

In either case the program index.php is loaded. This has the following code:

?php
$wkg_dir = 'Wkg'; $dev_dir = 'Dev'; // Default working version
$program = 'Mailmerge.php'; // Name 
of main
program 
$new = false; 
if (isset($_GET['new'])){ $new = $_GET['new'];  }   
if ($new == 1)  // Unset $local_dir if 'New' set
{ if (isset($_SESSION['local_dir']))  { 
unset($_SESSION['local_dir']); }
} 

if (!isset($_SESSION['local_dir'])) // Set up session variable 
'local_dir' 
{ $_SESSION['local_dir'] = $wkg_dir; }
$local_dir = $_SESSION['local_dir'];

if (isset($_GET['local_dir']))  // Get local_dir, if passed as 
parameter
{ $local_dir = $_GET['local_dir'];  }
$local_dir = (rtrim($local_dir, /)); // Verify valid directory
//  if (!array_key_exists($local_dir,$dirs)) { $local_dir = $wkg_dir; }
if ($local_dir != $dev_dir) { $local_dir = $wkg_dir; }
// Transfer to real program
include ($local_dir.'/'.$program);
?
The main program begins by checking whether or not it is running on my home PC 
(using a
procedure which caused someone here to say 'Yukk'), but which seems to be both 
logically
sound and reliable.

*   ---
1.00  Check if running on home PC  set up defaults
---*/
$home = strtr(getcwd(),\\,/);  // Ensure Home contains forward 
slashes
if (substr($home,0,2) == 'D:') 
{ 
$is_local = true; 
if ($local_dir == 'Dev') 
{ $util_dir = $local_dir; }
else { $util_dir = 'D:/Websites/Utilities'; }
} 
else 
{ $is_local = false; $util_dir = 'Utilities'; }

include ($util_dir.'/Std_utils.php');   // Load standard utilities
// Start real work:

If the parameter $is_local is set, I have access to a suite of editing 
facilities, and
other private areas. These are not present on the public copy, and there is 
nothing on any
of the menus to suggest that anything is missing.

The parameters $is_local and $local_dir are cached, so they only need to be 
specified when
the page is first loaded.

I never change the working directory (and it has never yet changed by itself), 
so I can
load anything in any subdirectory simply by specifying the local path. I also 
realised
while I was writing this that there is no real reason to have separate Wkg and 
Utilities
directories (other than that if I only had one version of the program for all 
local sites,
it would make the result of any bug that made it to the working version 
potentially that
much more serious).


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Govinda

I'm not sure how this could be made simpler.

$site_root = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR;

Call that in any file in the root of *your* web directories, and you
have what is essentially the document root for *your* site.
Presumably, you know the *relative* directories of all your files.
Simply append those relative directories + filenames to the $site_root
variable, and you're done.

Paul


Paul, you are right.  what you say above is very simple.
I guess I just did a poor job of communicating what I was after.
What I wanted was:
($_SERVER['DOCUMENT_ROOT']
..but an equivelent that would work on any server, even if  
($_SERVER['DOCUMENT_ROOT'] was turned off.
SO that I could build a universal global include path that would not  
break in any page, even if I later moved the page up or down a  
directory.. never requiring editing, despite the page's URL changes.


-G

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to stop E_DEPRECATED messages in the PHP log?

2009-07-06 Thread Jeff Weinberger

On Jul 6, 2009, at 7:47 PM, Paul M Foster wrote:


On Mon, Jul 06, 2009 at 02:16:09PM -0700, Jeff Weinberger wrote:


Hi:

I am hoping someone can help me figure this out

I've just upgraded my PHP installation to 5.3.0. Now I am receiving
thousands of log messages of the form PHP Deprecated: 

I know I have a number of scripts that use now-deprecated functions,
etc. and I now know what those are, thanks to all the messages.

However, this is now growing to (literally) gigabytes of log entries,
so I'd like to stop the messages until I have the time to re-write  
all

the offending scripts.

I have tried the following error.reporting lines in php.ini:

error_reporting = E_ALL  ~E_DEPRECATED  E_ERROR  E_WARNING 
E_PARSE  E_NOTICE  E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING 
E_USER_NOTICE  E_COMPILE_ERROR  E_COMPILE_WARNING

error_reporting = ~E_DEPRECATED  E_ALL  E_ERROR  E_WARNING 
E_PARSE  E_NOTICE  E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING 
E_USER_NOTICE  E_COMPILE_ERROR  E_COMPILE_WARNING

error_reporting =  E_ALL  E_ERROR  E_WARNING  E_PARSE  E_NOTICE 
E_CORE_ERROR  E_USER_ERROR  E_USER_WARNING  E_USER_NOTICE 
E_COMPILE_ERROR  E_COMPILE_WARNING  ~E_DEPRECATED

error_reporting = E_ERROR  E_CORE_ERROR  E_USER_ERROR 
E_COMPILE_ERROR  E_COMPILE_WARNING  ~E_DEPRECATED

error_reporting = ~E_DEPRECATED  E_ERROR  E_CORE_ERROR 
E_USER_ERROR  E_COMPILE_ERROR  E_COMPILE_WARNING

(as you can tell, I prefer verbose logs, but not that verbose...).

None of these combinations have stopped the  PHP Deprecated: ...
messages.

System info: Mac OS/X 10.5.7 Client version, PHP 5.3.0 running as a
CGI under Apache 2.2.11 and as a CLI. Please let me know if there's
any other info that might help.

php_info() reports error.reporting as 0

Any help or guidance is appreciated!!


Try

error_reporting(E_ALL ^ E_DEPRECATED);

See http://us2.php.net/manual/en/function.error-reporting.php for more
info and examples.

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Paul:

Thanks for your suggestion - it would work nicely, except that that is  
a runtime function that is called within a script.


I am trying to get the php.ini setting correct to avoid the Deprecated  
messages.


I tried error_reporting=E_ALL  ~E_DEPRECATED (which I think is the  
php.ini analogy to your suggestion) to no avail - it failed also.


leaving me still confused

--Jeff



The achievements of an organization are the results of the combined effort of each 
individual. -Vincent Thomas Vince Lombardi


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php