php-general Digest 10 Sep 2009 16:21:47 -0000 Issue 6332

2009-09-10 Thread php-general-digest-help

php-general Digest 10 Sep 2009 16:21:47 - Issue 6332

Topics (messages 297849 through 297869):

Re: Performance of while(true) loop
297849 by: Eddie Drapkin
297850 by: APseudoUtopia
297851 by: Eddie Drapkin
297852 by: Ben Dunlap

header problem
297853 by: A.a.k
297854 by: George Langley
297857 by: A.a.k
297858 by: Marcus Gnaß
297859 by: Ashley Sheridan
297860 by: Sándor Tamás (HostWare Kft.)
297861 by: Ashley Sheridan
297862 by: Arno Kuhl

upgrade php4 to php5
297855 by: madunix
297856 by: Eddie Drapkin

Hoping for a hand with a login script
297863 by: Watson Blair
297864 by: Tommy Pham
297865 by: Tommy Pham
297866 by: Tony Marston
297867 by: Watson Blair
297868 by: Tommy Pham
297869 by: Ben Dunlap

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia apseudouto...@gmail.com wrote:
 Hey list,

 I have a php cli script that listens on a UDP socket and, when data is
 sent to the socket, the script inserts it into a database. I'm using
 the real BSD socket functions, not fsock.

 The script runs socket_create(), then socket_bind(). Then it starts a
 while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have
 it running 24/7 inside a screen window.

 I'm curious as to the cpu/memory/etc usage of a while(true) loop. The
 `top` command shows that the process is in the sbwait state (the OS is
 FreeBSD). I'm contemplating adding a usleep or even a sleep inside to
 loop. Would this be beneficial? I'm not too sure of how the internals
 of PHP work in terms of loops and such.

 Thanks.

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



Is your socket blocking?  If so, what's the timeout?

while(true) {

//wait for socket timeout

}

is the same as:

while(true) {

//read nothing from socket and sleep

}

Without the usleep(), the loop is going to loop as fast as your CPU
will let it - meaning 100% CPU usage, all the time, at least in linux,
although I'm pretty sure BSD would behave the same.

As far as I'm aware, sockets in PHP behave almost identically to the
way that they behave in C.  I had an asynchronous TCP server written
with the socket_* functions and noticed that the while(true) loop used
100% of the CPU because of the nonblocking sockets in use, but a
usleep() solved that quite easily.  Using blocking sockets with
socket_select and a sane timeout relieved the high CPU usage as well.
---End Message---
---BeginMessage---
On Wed, Sep 9, 2009 at 10:39 PM, Eddie Drapkinoorza...@gmail.com wrote:
 On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia apseudouto...@gmail.com 
 wrote:
 Hey list,

 I have a php cli script that listens on a UDP socket and, when data is
 sent to the socket, the script inserts it into a database. I'm using
 the real BSD socket functions, not fsock.

 The script runs socket_create(), then socket_bind(). Then it starts a
 while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have
 it running 24/7 inside a screen window.

 I'm curious as to the cpu/memory/etc usage of a while(true) loop. The
 `top` command shows that the process is in the sbwait state (the OS is
 FreeBSD). I'm contemplating adding a usleep or even a sleep inside to
 loop. Would this be beneficial? I'm not too sure of how the internals
 of PHP work in terms of loops and such.

 Thanks.

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



 Is your socket blocking?  If so, what's the timeout?

 while(true) {

 //wait for socket timeout

 }

 is the same as:

 while(true) {

 //read nothing from socket and sleep

 }

 Without the usleep(), the loop is going to loop as fast as your CPU
 will let it - meaning 100% CPU usage, all the time, at least in linux,
 although I'm pretty sure BSD would behave the same.

 As far as I'm aware, sockets in PHP behave almost identically to the
 way that they behave in C.  I had an asynchronous TCP server written
 with the socket_* functions and noticed that the while(true) loop used
 100% of the CPU because of the nonblocking sockets in use, but a
 usleep() solved that quite easily.  Using blocking sockets with
 socket_select and a sane timeout relieved the high CPU usage as well.


I believe it is blocking. Here's my socket_recvfrom:
$Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port);

So I think the the MSG_WAITALL is causing it to block until incoming
data connection is closed (it never reaches the 512 byte mark before
it echos the 

[PHP] header problem

2009-09-10 Thread A.a.k

hello
I recentrly uploaded my project from localhost to a hosting and found many 
errors and warnings which didnt have in local. one of the most annoying one 
is header('Location xxx').
I have used header to redirect users from pages, and kinda used it alot. i 
know about the whitespace causing warning, but most of the pages i'm sending 
users got html and php mixed so i'm confused about how to remove whitespace 
in a html/php file. the error is :

Warning: Cannot modify header information - headers already sent by 
here is a simple example, user update page :
if($valid)
   {
   $msg='111';
   $user-dbupdate();
header(Location: /admin/index.php?msg=$msg);

   }
   else
   {
foreach($errors as $val)
   echo 'p id=error'.$val.'/p';
   }

and on admin index i get $msg and display it.
html
..
//lots of stuff
  ?php
  $msg = $_GET['msg'];
  switch($msg){
  case '111'   echo 'p /p';
   break;
 case '421':...
   }
?
//  more html and php

how can i fix this? 



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



Re: [PHP] header problem

2009-09-10 Thread George Langley
	Hi Blueman. As soon as ANYTHING has been drawn to the browser, you  
cannot use a header command. So you need to work through all of your  
code, and ensure that all of your logic that could result in a header  
call is run BEFORE you send any html code. Is going to be tricky if  
mixing html and php calls.


George


On 10-Sep-09, at 12:27 AM, A.a.k wrote:


hello
I recentrly uploaded my project from localhost to a hosting and  
found many errors and warnings which didnt have in local. one of the  
most annoying one is header('Location xxx').
I have used header to redirect users from pages, and kinda used it  
alot. i know about the whitespace causing warning, but most of the  
pages i'm sending users got html and php mixed so i'm confused about  
how to remove whitespace in a html/php file. the error is :
Warning: Cannot modify header information - headers already sent  
by 

here is a simple example, user update page :
   if($valid)
  {
  $msg='111';
  $user-dbupdate();
   header(Location: /admin/index.php?msg=$msg);

  }
  else
  {
   foreach($errors as $val)
  echo 'p id=error'.$val.'/p';
  }

and on admin index i get $msg and display it.
html
..
//lots of stuff
 ?php
 $msg = $_GET['msg'];
 switch($msg){
 case '111'   echo 'p /p';
  break;
case '421':...
  }
?
//  more html and php

how can i fix this?

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




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



[PHP] upgrade php4 to php5

2009-09-10 Thread madunix
how can i upgrade my php4 to php5?

[r...@intra /]# uname -a
Linux intra 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686
i386 GNU/Linux
/usr/local/apache/bin/apachectl stop
cd /downloads/
cd php-4.4.3
./configure --with-apxs2=/usr/local/apache/bin/apxs
--with-mysql=/usr/local/mysql --with-zlib-dir=/usr/lib/
--enable-versioning --enable-track-vars=yes
--enable-url-includes--enable-sysvshm=yes --enable-sysvsem=yes
--with-gettext --enable-mbstring --enable-ftp --enable-calendar
--with-config-file-path=/etc --with-oci8=$ORACLE_HOME  --enable-soap
--with-gd  --enable-xml --with-xml  --enable-sysvsem --enable-sysvshm
--enable-sysvmsg --with-regex=system --with-png --with-ttf=/usr/lib
--with-freetype=/usr/lib --enable-sigchild --with-openssl --with-iconv
--with-dom
make
make install
/usr/local/apache/bin/apachectl start


what would be the best way to upgrade to php5?
any modification should be done on php.ini?

your input would be really appreciated?

Thanks
-mu

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



Re: [PHP] upgrade php4 to php5

2009-09-10 Thread Eddie Drapkin
On Thu, Sep 10, 2009 at 2:51 AM, madunix madu...@gmail.com wrote:
 how can i upgrade my php4 to php5?

 [r...@intra /]# uname -a
 Linux intra 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686
 i386 GNU/Linux
 /usr/local/apache/bin/apachectl stop
 cd /downloads/
 cd php-4.4.3
 ./configure --with-apxs2=/usr/local/apache/bin/apxs
 --with-mysql=/usr/local/mysql --with-zlib-dir=/usr/lib/
 --enable-versioning --enable-track-vars=yes
 --enable-url-includes--enable-sysvshm=yes --enable-sysvsem=yes
 --with-gettext --enable-mbstring --enable-ftp --enable-calendar
 --with-config-file-path=/etc --with-oci8=$ORACLE_HOME  --enable-soap
 --with-gd  --enable-xml --with-xml  --enable-sysvsem --enable-sysvshm
 --enable-sysvmsg --with-regex=system --with-png --with-ttf=/usr/lib
 --with-freetype=/usr/lib --enable-sigchild --with-openssl --with-iconv
 --with-dom
 make
 make install
 /usr/local/apache/bin/apachectl start


 what would be the best way to upgrade to php5?
 any modification should be done on php.ini?

 your input would be really appreciated?

 Thanks
 -mu

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




This might help:
http://php.net/manual/en/faq.migration5.php

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



Re: [PHP] header problem

2009-09-10 Thread A.a.k

is there any alternative to header() for redirect users?

George Langley george.lang...@shaw.ca wrote in message 
news:b1b897d4-7448-4b71-bffc-3addc27ce...@shaw.ca...
Hi Blueman. As soon as ANYTHING has been drawn to the browser, you  cannot 
use a header command. So you need to work through all of your  code, and 
ensure that all of your logic that could result in a header  call is run 
BEFORE you send any html code. Is going to be tricky if  mixing html and 
php calls.


George


On 10-Sep-09, at 12:27 AM, A.a.k wrote:


hello
I recentrly uploaded my project from localhost to a hosting and  found 
many errors and warnings which didnt have in local. one of the  most 
annoying one is header('Location xxx').
I have used header to redirect users from pages, and kinda used it  alot. 
i know about the whitespace causing warning, but most of the  pages i'm 
sending users got html and php mixed so i'm confused about  how to remove 
whitespace in a html/php file. the error is :

Warning: Cannot modify header information - headers already sent  by 
here is a simple example, user update page :
   if($valid)
  {
  $msg='111';
  $user-dbupdate();
   header(Location: /admin/index.php?msg=$msg);

  }
  else
  {
   foreach($errors as $val)
  echo 'p id=error'.$val.'/p';
  }

and on admin index i get $msg and display it.
html
..
//lots of stuff
 ?php
 $msg = $_GET['msg'];
 switch($msg){
 case '111'   echo 'p /p';
  break;
case '421':...
  }
?
//  more html and php

how can i fix this?

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






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



Re: [PHP] header problem

2009-09-10 Thread Marcus Gnaß
A.a.k wrote:
 is there any alternative to header() for redirect users?

As far as I know there isn't.

Is the header-error the first error on the page? If not, the other error
message itself is the reason for the header-error and will be solved if
you solve the other error.

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



Re: [PHP] header problem

2009-09-10 Thread Ashley Sheridan
On Thu, 2009-09-10 at 08:57 +0200, A.a.k wrote:
 is there any alternative to header() for redirect users?
 
 George Langley george.lang...@shaw.ca wrote in message 
 news:b1b897d4-7448-4b71-bffc-3addc27ce...@shaw.ca...
  Hi Blueman. As soon as ANYTHING has been drawn to the browser, you  cannot 
  use a header command. So you need to work through all of your  code, and 
  ensure that all of your logic that could result in a header  call is run 
  BEFORE you send any html code. Is going to be tricky if  mixing html and 
  php calls.
 
  George
 
 
  On 10-Sep-09, at 12:27 AM, A.a.k wrote:
 
  hello
  I recentrly uploaded my project from localhost to a hosting and  found 
  many errors and warnings which didnt have in local. one of the  most 
  annoying one is header('Location xxx').
  I have used header to redirect users from pages, and kinda used it  alot. 
  i know about the whitespace causing warning, but most of the  pages i'm 
  sending users got html and php mixed so i'm confused about  how to remove 
  whitespace in a html/php file. the error is :
  Warning: Cannot modify header information - headers already sent  by 
  here is a simple example, user update page :
 if($valid)
{
$msg='111';
$user-dbupdate();
 header(Location: /admin/index.php?msg=$msg);
 
}
else
{
 foreach($errors as $val)
echo 'p id=error'.$val.'/p';
}
 
  and on admin index i get $msg and display it.
  html
  ..
  //lots of stuff
   ?php
   $msg = $_GET['msg'];
   switch($msg){
   case '111'   echo 'p /p';
break;
  case '421':...
}
  ?
  //  more html and php
 
  how can i fix this?
 
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
  
 
 

Several:

  * Javascript - not always available on your target system, or
blocked by script blocking plugins
  * Meta refresh tags - should be honored by the user agent, but may
not always be.

The problem you have is not that you need to work around this 'problem'
in PHP, but you need to fix your broken code. This problem often comes
up on the list, and is usually because of extra whitespace in include
files, or errors being output to the browser which force the headers to
be sent.

Thanks,
Ash
http://www.ashleysheridan.co.uk




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



Re: [PHP] header problem

2009-09-10 Thread HostWare Kft.
Usually, when I have to redirect the user AFTER headers has been sent (like 
showing an error message), I write this:


SCRIPTlocation=page_to_send.html/SCRIPT

But this will redirect the user at once. If you want the user to read the 
page, you should do something in Javascript with setTimeout(func,timeout) 
function.


BR,
SanTa

- Original Message - 
From: George Langley george.lang...@shaw.ca

To: php-general@lists.php.net
Sent: Thursday, September 10, 2009 8:39 AM
Subject: Re: [PHP] header problem


Hi Blueman. As soon as ANYTHING has been drawn to the browser, you  cannot 
use a header command. So you need to work through all of your  code, and 
ensure that all of your logic that could result in a header  call is run 
BEFORE you send any html code. Is going to be tricky if  mixing html and 
php calls.


George


On 10-Sep-09, at 12:27 AM, A.a.k wrote:


hello
I recentrly uploaded my project from localhost to a hosting and  found 
many errors and warnings which didnt have in local. one of the  most 
annoying one is header('Location xxx').
I have used header to redirect users from pages, and kinda used it  alot. 
i know about the whitespace causing warning, but most of the  pages i'm 
sending users got html and php mixed so i'm confused about  how to remove 
whitespace in a html/php file. the error is :

Warning: Cannot modify header information - headers already sent  by 
here is a simple example, user update page :
   if($valid)
  {
  $msg='111';
  $user-dbupdate();
   header(Location: /admin/index.php?msg=$msg);

  }
  else
  {
   foreach($errors as $val)
  echo 'p id=error'.$val.'/p';
  }

and on admin index i get $msg and display it.
html
..
//lots of stuff
 ?php
 $msg = $_GET['msg'];
 switch($msg){
 case '111'   echo 'p /p';
  break;
case '421':...
  }
?
//  more html and php

how can i fix this?

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




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




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



Re: [PHP] header problem

2009-09-10 Thread Ashley Sheridan
On Thu, 2009-09-10 at 09:04 +0200, Sándor Tamás (HostWare Kft.) wrote:
 Usually, when I have to redirect the user AFTER headers has been sent (like 
 showing an error message), I write this:
 
 SCRIPTlocation=page_to_send.html/SCRIPT
 
 But this will redirect the user at once. If you want the user to read the 
 page, you should do something in Javascript with setTimeout(func,timeout) 
 function.
 
 BR,
 SanTa
 
 - Original Message - 
 From: George Langley george.lang...@shaw.ca
 To: php-general@lists.php.net
 Sent: Thursday, September 10, 2009 8:39 AM
 Subject: Re: [PHP] header problem
 
 
  Hi Blueman. As soon as ANYTHING has been drawn to the browser, you  cannot 
  use a header command. So you need to work through all of your  code, and 
  ensure that all of your logic that could result in a header  call is run 
  BEFORE you send any html code. Is going to be tricky if  mixing html and 
  php calls.
 
  George
 
 
  On 10-Sep-09, at 12:27 AM, A.a.k wrote:
 
  hello
  I recentrly uploaded my project from localhost to a hosting and  found 
  many errors and warnings which didnt have in local. one of the  most 
  annoying one is header('Location xxx').
  I have used header to redirect users from pages, and kinda used it  alot. 
  i know about the whitespace causing warning, but most of the  pages i'm 
  sending users got html and php mixed so i'm confused about  how to remove 
  whitespace in a html/php file. the error is :
  Warning: Cannot modify header information - headers already sent  by 
  here is a simple example, user update page :
 if($valid)
{
$msg='111';
$user-dbupdate();
 header(Location: /admin/index.php?msg=$msg);
 
}
else
{
 foreach($errors as $val)
echo 'p id=error'.$val.'/p';
}
 
  and on admin index i get $msg and display it.
  html
  ..
  //lots of stuff
   ?php
   $msg = $_GET['msg'];
   switch($msg){
   case '111'   echo 'p /p';
break;
  case '421':...
}
  ?
  //  more html and php
 
  how can i fix this?
 
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
  
 
 
Don't use a timer to redirect if you want the user to read a message, as
this assumes that the visitor is a good reader. This is forgetting all
of those visitors with reading difficulties (i.e. Dyslexia), those users
who have attention problems who can't focus on text for long periods
(i.e. ADHD) and any users who rely on things such as screen readers
(which are slower than reading text yourself (if you're an average
reader!) ) or a Braille browser.

In cases such as these, it's best to let the visitor move at their own
pace and not redirect until they want to.

Thanks,
Ash
http://www.ashleysheridan.co.uk




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



RE: [PHP] header problem

2009-09-10 Thread Arno Kuhl
-Original Message-
From: A.a.k [mailto:blue...@gmail.com] 
Sent: 10 September 2009 08:27 AM
To: php-general@lists.php.net
Subject: [PHP] header problem

hello
I recentrly uploaded my project from localhost to a hosting and found many
errors and warnings which didnt have in local. one of the most annoying one
is header('Location xxx').
I have used header to redirect users from pages, and kinda used it alot. i
know about the whitespace causing warning, but most of the pages i'm sending
users got html and php mixed so i'm confused about how to remove whitespace
in a html/php file. the error is :
Warning: Cannot modify header information - headers already sent by 
here is a simple example, user update page :
 if($valid)
{
$msg='111';
$user-dbupdate();
 header(Location: /admin/index.php?msg=$msg);

}
else
{
 foreach($errors as $val)
echo 'p id=error'.$val.'/p';
}

and on admin index i get $msg and display it.
html
..
//lots of stuff
   ?php
   $msg = $_GET['msg'];
   switch($msg){
   case '111'   echo 'p /p';
break;
  case '421':...
}
?
//  more html and php

how can i fix this? 
--

It's possible that on your localhost you have output_buffering set on either
in php.ini or in a .htaccess, which would avoid the displayed error about
headers. If it's switched on locally and off for your host server then
you'll get the problem you reported. Check that this is off locally (use
phpinfo) so that you can be sure your code is working properly before you
upload.

Alternatively if you want to be able to do a redirect after you've already
started your output (this is sometimes done for error handling) you could
use ob_start() to start output buffering, ob_end_clean() to clear the output
buffer and start again, and ob_flush() to send the output buffer. If you
want to continue using output buffering after an ob_end_clean() you'll have
to do an ob_start() again.

Cheers
Arno


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



[PHP] Hoping for a hand with a login script

2009-09-10 Thread Watson Blair
Hey guys,This is a simple issue I'm sure, however I'm having one hell of a
time seeing my way clear of it. I appreciate any support you guys could
throw my way.

So I'm trying to set up a small website that includes a store (
www.rareintaglio.com), i have all of my HTML hammed out and now I'm working
on creating an admin login for the sites owner to input data from a back
end. I have it set up so that he goes to /adminlogin.php, enters his info
and gains access to the back end of the website using Session variables
(valid vs. invalid) however i keep getting this reply when i try to run the
script:

Results: SELECT * FROM adminlog WHARE username = 'gourmet28e' AND password =
'***'
Query failed: Query was empty
here's the /adminlogin script:

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
?php

  session_start ;

?
head
link rel=stylesheet type=text/css href=intaglio.css /
  title/title
  meta http-equiv=content-type content=text/html;charset=UTF-8 /
/head
bodycenter
div id=body
 div id=header/div
 div id=navbody
 div id=nav
   ul
  lia href=/index.htmlHome/a/li
  lia href=/shop.htmlStore/a/li
  lia href=/about.htmlAbout/a/li
  /ul
  /div
/div
 div id=cbody

 ?php

 if ($_SESSION['user'] == invalid)
{
echo 'Invalid Username or Password, please try again';
}
if ($_SESSION['user'] == valid)
{
header (Location: http://www.rareintaglio.com/member.php;);
}
?
 form method=post action=/session.php
   table border=0
trtdAdmin Name: /td/tr
   trtdinput type=text name=username size=30 maxlength=20/
/td/tr
trtdPassword:/td/tr
trtdinput type=password name=password size=30 maxlength=20/
 /td/tr
trtdinput type=submit value=Login /  /td/tr
/table
/div
div id=footerpAll Pages and Images Copyright @ 2009, Devour.tv Ltd.
All Rights Reserved/p/div
/body
/html


and /session.php goes a little like:
?php
$host=Rareintag.db.4159106.hostedresource.com; // Host name
$username=Rareintag; // Mysql username
$password=**; // Mysql password
$db_name=Rareintag; // Database name
$tbl_name=adminlog; // Table name

// Connect to server and select databse.
mysql_connect($host, $username, $password)or die(cannot connect);
mysql_select_db($db_name)or die(cannot select DB);

// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];
$qury = SELECT * FROM adminlog WHARE username = '$username' AND password =
'$password';
echo 'br /';
echo Query:  . $query;
echo 'br /';
echo Results:  . $result;
echo $qury;
echo 'br /';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

if($result == 0){
$_SESSION['user'] = invalid ;
header(Location: http://www.rareintaglio.com/adminlogin.php;);
}
else
{
$_SESSION['user'] = valid  ;
header(Location: http://www.rareintaglio.com/members.php;);
}
?

However as I mentioned above i keep getting an error,
does anyone know where I took a wrong turn?
Thanks,
Watson


Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Tommy Pham
--- On Thu, 9/10/09, Watson Blair bestudios...@gmail.com wrote:

 From: Watson Blair bestudios...@gmail.com
 Subject: [PHP] Hoping for a hand with a login script
 To: php-general@lists.php.net
 Date: Thursday, September 10, 2009, 4:06 AM
 Hey guys,This is a simple issue I'm
 sure, however I'm having one hell of a
 time seeing my way clear of it. I appreciate any support
 you guys could
 throw my way.
 
 So I'm trying to set up a small website that includes a
 store (
 www.rareintaglio.com), i have all of my HTML hammed out and
 now I'm working
 on creating an admin login for the sites owner to input
 data from a back
 end. I have it set up so that he goes to /adminlogin.php,
 enters his info
 and gains access to the back end of the website using
 Session variables
 (valid vs. invalid) however i keep getting this reply when
 i try to run the
 script:
 
 Results: SELECT * FROM adminlog WHARE username =
 'gourmet28e' AND password =
 '***'
 Query failed: Query was empty
 here's the /adminlogin script:
 
 !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01
 Transitional//EN
 html
 ?php
 
   session_start ;
 
 ?
 head
 link rel=stylesheet type=text/css
 href=intaglio.css /
   title/title
   meta http-equiv=content-type
 content=text/html;charset=UTF-8 /
 /head
 bodycenter
 div id=body
  div id=header/div
  div id=navbody
  div id=nav
    ul
   lia
 href=/index.htmlHome/a/li
   lia
 href=/shop.htmlStore/a/li
   lia
 href=/about.htmlAbout/a/li
   /ul
   /div
 /div
  div id=cbody
 
  ?php
 
  if ($_SESSION['user'] == invalid)
 {
 echo 'Invalid Username or Password, please try again';
 }
 if ($_SESSION['user'] == valid)
 {
 header (Location: http://www.rareintaglio.com/member.php;);
 }
 ?
  form method=post action=/session.php
    table border=0
 trtdAdmin Name: /td/tr
    trtdinput type=text
 name=username size=30 maxlength=20/
 /td/tr
 trtdPassword:/td/tr
 trtdinput type=password
 name=password size=30 maxlength=20/
  /td/tr
 trtdinput type=submit value=Login
 /  /td/tr
 /table
     /div
 div id=footerpAll Pages and Images
 Copyright @ 2009, Devour.tv Ltd.
 All Rights Reserved/p/div
 /body
 /html
 
 
 and /session.php goes a little like:
 ?php
 $host=Rareintag.db.4159106.hostedresource.com; // Host
 name
 $username=Rareintag; // Mysql username
 $password=**; // Mysql password
 $db_name=Rareintag; // Database name
 $tbl_name=adminlog; // Table name
 
 // Connect to server and select databse.
 mysql_connect($host, $username, $password)or
 die(cannot connect);
 mysql_select_db($db_name)or die(cannot select DB);
 

You need to read the manual more carefully.
http://www.php.net/manual/en/function.mysql-connect.php


 // username and password sent from form
 $username=$_POST['username'];
 $password=$_POST['password'];
 $qury = SELECT * FROM adminlog WHARE username =
 '$username' AND password =
 '$password';
 echo 'br /';
 echo Query:  . $query;
 echo 'br /';
 echo Results:  . $result;

http://www.php.net/manual/en/function.mysql-query.php

 echo $qury;
 echo 'br /';
 $result = mysql_query($query) or die('Query failed: ' .
 mysql_error());
 
 if($result == 0){
 $_SESSION['user'] = invalid ;
 header(Location: http://www.rareintaglio.com/adminlogin.php;);
 }
 else
 {
 $_SESSION['user'] = valid  ;
 header(Location: http://www.rareintaglio.com/members.php;);
 }
 ?
 
 However as I mentioned above i keep getting an error,
 does anyone know where I took a wrong turn?
 Thanks,
 Watson


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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Tommy Pham
--- On Thu, 9/10/09, Tommy Pham tommy...@yahoo.com wrote:

 From: Tommy Pham tommy...@yahoo.com
 Subject: Re: [PHP] Hoping for a hand with a login script
 To: php-general@lists.php.net
 Date: Thursday, September 10, 2009, 4:13 AM
 --- On Thu, 9/10/09, Watson Blair
 bestudios...@gmail.com
 wrote:
 
  From: Watson Blair bestudios...@gmail.com
  Subject: [PHP] Hoping for a hand with a login script
  To: php-general@lists.php.net
  Date: Thursday, September 10, 2009, 4:06 AM
  Hey guys,This is a simple issue I'm
  sure, however I'm having one hell of a
  time seeing my way clear of it. I appreciate any
 support
  you guys could
  throw my way.
  
  So I'm trying to set up a small website that includes
 a
  store (
  www.rareintaglio.com), i have all of my HTML hammed
 out and
  now I'm working
  on creating an admin login for the sites owner to
 input
  data from a back
  end. I have it set up so that he goes to
 /adminlogin.php,
  enters his info
  and gains access to the back end of the website using
  Session variables
  (valid vs. invalid) however i keep getting this reply
 when
  i try to run the
  script:
  
  Results: SELECT * FROM adminlog WHARE username =
  'gourmet28e' AND password =
  '***'
  Query failed: Query was empty
  here's the /adminlogin script:
  
  !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01
  Transitional//EN
  html
  ?php
  
    session_start ;
  
  ?
  head
  link rel=stylesheet type=text/css
  href=intaglio.css /
    title/title
    meta http-equiv=content-type
  content=text/html;charset=UTF-8 /
  /head
  bodycenter
  div id=body
   div id=header/div
   div id=navbody
   div id=nav
     ul
    lia
  href=/index.htmlHome/a/li
    lia
  href=/shop.htmlStore/a/li
    lia
  href=/about.htmlAbout/a/li
    /ul
    /div
  /div
   div id=cbody
  
   ?php
  
   if ($_SESSION['user'] == invalid)
  {
  echo 'Invalid Username or Password, please try
 again';
  }
  if ($_SESSION['user'] == valid)
  {
  header (Location: http://www.rareintaglio.com/member.php;);
  }
  ?
   form method=post
 action=/session.php
     table border=0
  trtdAdmin Name:
 /td/tr
     trtdinput type=text
  name=username size=30 maxlength=20/
  /td/tr
  trtdPassword:/td/tr
  trtdinput type=password
  name=password size=30 maxlength=20/
   /td/tr
  trtdinput type=submit
 value=Login
  /  /td/tr
  /table
      /div
  div id=footerpAll Pages and Images
  Copyright @ 2009, Devour.tv Ltd.
  All Rights Reserved/p/div
  /body
  /html
  
  
  and /session.php goes a little like:
  ?php
  $host=Rareintag.db.4159106.hostedresource.com; //
 Host
  name
  $username=Rareintag; // Mysql username
  $password=**; // Mysql password
  $db_name=Rareintag; // Database name
  $tbl_name=adminlog; // Table name
  
  // Connect to server and select databse.
  mysql_connect($host, $username, $password)or
  die(cannot connect);
  mysql_select_db($db_name)or die(cannot select
 DB);
  
 
 You need to read the manual more carefully.
 http://www.php.net/manual/en/function.mysql-connect.php
 
 
  // username and password sent from form
  $username=$_POST['username'];
  $password=$_POST['password'];
  $qury = SELECT * FROM adminlog WHARE username =
  '$username' AND password =
  '$password';

You might want to learn the basics of SQL syntax.

  echo 'br /';
  echo Query:  . $query;
  echo 'br /';
  echo Results:  . $result;
 
 http://www.php.net/manual/en/function.mysql-query.php
 
  echo $qury;
  echo 'br /';
  $result = mysql_query($query) or die('Query failed: '
 .
  mysql_error());
  
  if($result == 0){
  $_SESSION['user'] = invalid ;
  header(Location: http://www.rareintaglio.com/adminlogin.php;);
  }
  else
  {
  $_SESSION['user'] = valid  ;
  header(Location: http://www.rareintaglio.com/members.php;);
  }
  ?
  
  However as I mentioned above i keep getting an error,
  does anyone know where I took a wrong turn?
  Thanks,
  Watson
 


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



[PHP] Re: Hoping for a hand with a login script

2009-09-10 Thread Tony Marston
You are constructing your query in $qury yet you are trying to read it 
from $query. Because they have different spellings they are treated as 
different variables.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org


Watson Blair bestudios...@gmail.com wrote in message 
news:28f3c0b00909100206o20e8ba9cr7a326e9e68f7d...@mail.gmail.com...
 Hey guys,This is a simple issue I'm sure, however I'm having one hell of a
 time seeing my way clear of it. I appreciate any support you guys could
 throw my way.

 So I'm trying to set up a small website that includes a store (
 www.rareintaglio.com), i have all of my HTML hammed out and now I'm 
 working
 on creating an admin login for the sites owner to input data from a back
 end. I have it set up so that he goes to /adminlogin.php, enters his info
 and gains access to the back end of the website using Session variables
 (valid vs. invalid) however i keep getting this reply when i try to run 
 the
 script:

 Results: SELECT * FROM adminlog WHARE username = 'gourmet28e' AND password 
 =
 '***'
 Query failed: Query was empty
 here's the /adminlogin script:

 !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
 html
 ?php

  session_start ;

 ?
 head
 link rel=stylesheet type=text/css href=intaglio.css /
  title/title
  meta http-equiv=content-type content=text/html;charset=UTF-8 /
 /head
 bodycenter
 div id=body
 div id=header/div
 div id=navbody
 div id=nav
   ul
  lia href=/index.htmlHome/a/li
  lia href=/shop.htmlStore/a/li
  lia href=/about.htmlAbout/a/li
  /ul
  /div
 /div
 div id=cbody

 ?php

 if ($_SESSION['user'] == invalid)
 {
 echo 'Invalid Username or Password, please try again';
 }
 if ($_SESSION['user'] == valid)
 {
 header (Location: http://www.rareintaglio.com/member.php;);
 }
 ?
 form method=post action=/session.php
   table border=0
 trtdAdmin Name: /td/tr
   trtdinput type=text name=username size=30 maxlength=20/
 /td/tr
 trtdPassword:/td/tr
 trtdinput type=password name=password size=30 maxlength=20/
 /td/tr
 trtdinput type=submit value=Login /  /td/tr
 /table
/div
 div id=footerpAll Pages and Images Copyright @ 2009, Devour.tv Ltd.
 All Rights Reserved/p/div
 /body
 /html


 and /session.php goes a little like:
 ?php
 $host=Rareintag.db.4159106.hostedresource.com; // Host name
 $username=Rareintag; // Mysql username
 $password=**; // Mysql password
 $db_name=Rareintag; // Database name
 $tbl_name=adminlog; // Table name

 // Connect to server and select databse.
 mysql_connect($host, $username, $password)or die(cannot connect);
 mysql_select_db($db_name)or die(cannot select DB);

 // username and password sent from form
 $username=$_POST['username'];
 $password=$_POST['password'];
 $qury = SELECT * FROM adminlog WHARE username = '$username' AND password 
 =
 '$password';
 echo 'br /';
 echo Query:  . $query;
 echo 'br /';
 echo Results:  . $result;
 echo $qury;
 echo 'br /';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());

 if($result == 0){
 $_SESSION['user'] = invalid ;
 header(Location: http://www.rareintaglio.com/adminlogin.php;);
 }
 else
 {
 $_SESSION['user'] = valid  ;
 header(Location: http://www.rareintaglio.com/members.php;);
 }
 ?

 However as I mentioned above i keep getting an error,
 does anyone know where I took a wrong turn?
 Thanks,
 Watson
 



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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Watson Blair
Hey Tommy,Thanks for the link, I found a few typos in my variables, and
Query. but now it's returning:

Results: Resource id #2
*Warning*: Cannot modify header information - headers already sent by
(output started at /home/content/i/n/t/intag/html/session.php:16) in *
/home/content/i/n/t/intag/html/session.php* on line *29*
*
*
*line 29 reads:*
*header(Location: http://www.rareintaglio.com/members.php;);*
*
*
so ya, I'm a little confused... I'm more than willing to do the
reading necessary, could you point me in the correct direction? Ive looked
at a fair amount of documentation on Resources id#2, but I'm having some
trouble making heads or tails of it as it applies to my script.
Thanks for the pointers,
Watson
*
*
*
*


Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Tommy Pham
-- On Thu, 9/10/09, Watson Blair bestudios...@gmail.com wrote:

 From: Watson Blair bestudios...@gmail.com
 Subject: Re: [PHP] Hoping for a hand with a login script
 To: Tommy Pham tommy...@yahoo.com
 Cc: php-general@lists.php.net
 Date: Thursday, September 10, 2009, 4:31 AM
 Hey Tommy,Thanks for the link, I found
 a few typos in my variables, and Query. but now it's
 returning:
 Results: Resource id #2
 
 Warning: Cannot modify header information - headers
 already sent by (output started at
 /home/content/i/n/t/intag/html/session.php:16)
 in /home/content/i/n/t/intag/html/session.php on
 line 29
 
 line 29
 reads:
 header(Location: http://www.rareintaglio.com/members.php;);
 
 so ya,
 I'm a little confused... I'm more than willing to do
 the reading necessary, could you point me in the correct
 direction? Ive looked at a fair amount of documentation
 on Resources id#2, but I'm having some trouble making
 heads or tails of it as it applies to my
 script.
 Thanks for the
 pointers,Watson
 
 
Read the entire thread of Include files in HTML:
http://marc.info/?l=php-generalw=2r=1s=include+files+in+htmlq=b


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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Ben Dunlap
 So I'm trying to set up a small website that includes a store (
 www.rareintaglio.com), i have all of my HTML hammed out and now I'm working
 on creating an admin login for the sites owner to input data from a back

I would really strongly advise against building your own
authentication system. I'm currently regretting the fact that I did
the same, a few years ago, for a couple of systems I still support.
There are just too many things that can go wrong, especially if you're
new to PHP and MySQL in general. Just to begin with, the code you
posted currently suffers from a really basic SQL injection
vulnerability and your database is likely be compromised within hours
of your site getting any kind of significant traffic. That's
completely distinct from the more basic syntax trouble.

Perhaps paradoxically, the more experience you gain with these things,
the less inclined you will be, most likely, to try to roll your own
AAA.

There are lots of open-source PHP frameworks out there that should be
able to take care of authentication and access-control for you --
CodeIgniter, Zend Framework, and Solar come immediately to mind as
packages that I've either heard good things about, or suspect are
solid because of the authors involved. I'm sure there are several
other good ones also.

http://codeigniter.com/
http://framework.zend.com/
http://www.solarphp.com/

Ben

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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Robert Cummings



Ben Dunlap wrote:

So I'm trying to set up a small website that includes a store (
www.rareintaglio.com), i have all of my HTML hammed out and now I'm working
on creating an admin login for the sites owner to input data from a back


I would really strongly advise against building your own
authentication system. I'm currently regretting the fact that I did
the same, a few years ago, for a couple of systems I still support.
There are just too many things that can go wrong, especially if you're
new to PHP and MySQL in general. Just to begin with, the code you
posted currently suffers from a really basic SQL injection
vulnerability and your database is likely be compromised within hours
of your site getting any kind of significant traffic. That's
completely distinct from the more basic syntax trouble.

Perhaps paradoxically, the more experience you gain with these things,
the less inclined you will be, most likely, to try to roll your own
AAA.

There are lots of open-source PHP frameworks out there that should be
able to take care of authentication and access-control for you --
CodeIgniter, Zend Framework, and Solar come immediately to mind as
packages that I've either heard good things about, or suspect are
solid because of the authors involved. I'm sure there are several
other good ones also.


I find the more experienced I get, the more I have to wrap/plug into 
various authentication systems with custom authentication (MediaWiki, 
WordPress, PHPMyAdmin, Mantis, SquirrelMail, etc, etc). In some cases 
it's a straight up plugin process, in others it's wrapping with my own 
AccessControls management system.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



RE: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Bob McConnell
From: Ben Dunlap
 
 So I'm trying to set up a small website that includes a store (
 www.rareintaglio.com), i have all of my HTML hammed out and now I'm
working
 on creating an admin login for the sites owner to input data from a
back
 
 I would really strongly advise against building your own
 authentication system. I'm currently regretting the fact that I did
 the same, a few years ago, for a couple of systems I still support.
 There are just too many things that can go wrong, especially if you're
 new to PHP and MySQL in general. Just to begin with, the code you
 posted currently suffers from a really basic SQL injection
 vulnerability and your database is likely be compromised within hours
 of your site getting any kind of significant traffic. That's
 completely distinct from the more basic syntax trouble.
 
 Perhaps paradoxically, the more experience you gain with these things,
 the less inclined you will be, most likely, to try to roll your own
 AAA.
 
 There are lots of open-source PHP frameworks out there that should be
 able to take care of authentication and access-control for you --
 CodeIgniter, Zend Framework, and Solar come immediately to mind as
 packages that I've either heard good things about, or suspect are
 solid because of the authors involved. I'm sure there are several
 other good ones also.
 
 http://codeigniter.com/
 http://framework.zend.com/
 http://www.solarphp.com/

While I have not looked at the last two, there is one thing that bothers
me about your recommendation of codeigniter. Authentication is a basic
function that should be used for any web site with interactive features.
There is such a universal need for this function that there should be
several packages available to provide it. But I believe that telling
someone to adopt a complete portal system like CI just to get basic
authentication is gross overkill. There has to be a better way to
provide this core functionality without installing a monster package
that will be 95% superfluous to their needs.

Yes, I have installed codeigniter. I am still trying to figure out why I
would want to use it.

Bob McConnell

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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Bastien Koert
On Thu, Sep 10, 2009 at 12:21 PM, Ben Dunlap bdun...@agentintellect.com wrote:
 So I'm trying to set up a small website that includes a store (
 www.rareintaglio.com), i have all of my HTML hammed out and now I'm working
 on creating an admin login for the sites owner to input data from a back

simple folder protection should work well and be very simple to implement



-- 

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] Performance of while(true) loop

2009-09-10 Thread Jim Lucas
APseudoUtopia wrote:
 Hey list,
 
 I have a php cli script that listens on a UDP socket and, when data is
 sent to the socket, the script inserts it into a database. I'm using
 the real BSD socket functions, not fsock.
 
 The script runs socket_create(), then socket_bind(). Then it starts a
 while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have
 it running 24/7 inside a screen window.
 
 I'm curious as to the cpu/memory/etc usage of a while(true) loop. The
 `top` command shows that the process is in the sbwait state (the OS is
 FreeBSD). I'm contemplating adding a usleep or even a sleep inside to
 loop. Would this be beneficial? I'm not too sure of how the internals
 of PHP work in terms of loops and such.
 
 Thanks.
 


Here is something I wrote a few years ago.  I still have this running on
my system today...

#!/usr/local/bin/php -q
?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');

// Set time limit to indefinite execution
set_time_limit(0);

// Set the ip and port we will listen on
define('LISTEN_IP', 'x.x.x.x'); // IP to listin on
define('LISTEN_PORT',   28000); // Port number to listen on
define('PACKET_SIZE',   512);   // 512 bytes
define('SOCKET_TIMOUT', 2); // In Seconds

/* Open a server socket to port 1234 on localhost */
if ( $socket = @stream_socket_server('udp://'.LISTEN_IP.':'.LISTEN_PORT,
$errno, $errstr, STREAM_SERVER_BIND) ) {

  echo Running!!!\n;

  while ( true ) {

// Output something to the screen to indicate that it is running
echo '.';

/* Get the exact same packet again, but remove it from the buffer
 * this time.
 */
$buff = stream_socket_recvfrom($socket, PACKET_SIZE, 0, $remote_ip);

# Checking to see if someone is sending an invalid packet to my
# server
# Minimum packet size is 4 bytes
if ( strlen($buff) = 4 ) {
  continue;
}
print_r($buff);
  }
  fclose($socket);
}
echo Done!!!\n;

###END

Until recently, I was using screen also, but I have now switched over to
a new start/stop script.  I run OpenBSD 4.3  4.5 on most of my boxes.

Once configured, this shell script can start/stop/status the given process.

I have been told that this does not start a /true/ daemon.  But for me
it is close enough.

change the 4 variables at the top, just under the set -e line, and you
should have it.

Let me know if you have any problems.

#! /bin/ksh
#
# tms_daemon
#
# Starts a listening daemon that acts as a Tribes Master Server
#
# Author:  Jim Lucas jlu...@cmsws.com
#
# Version:  0.0.1
#

set -e

DESC=Name of service
DAEMON=/path/to/file.php
PIDFILE=/var/run/NAME.pid
SCRIPTNAME=tms_daemon

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

#
#  Function that starts the daemon/service.
#
d_start() {
  if [ -f $PIDFILE ]; then
echo $DESC already running: PID# `cat $PIDFILE`
exit 1
  else
echo -n Starting $DESC
nohup $DAEMON 21 1/dev/null 
sleep 0.5
ps aux | grep $DAEMON | grep -v grep | awk -F' ' '{print $2} ' 
$PIDFILE
echo . [`cat $PIDFILE`]
  fi
}

#
#  Function that stops the daemon/service.
#
d_stop() {
  if [ -f $PIDFILE ]; then
echo -n Stopping $DESC
kill `cat $PIDFILE`
rm $PIDFILE
echo .
  else
echo $DESC is not running
exit 1
  fi
}

case $1 in
  start)
d_start
  ;;
  stop)
d_stop
  ;;
  status)
if [ -f $PIDFILE ]; then
  echo $DESC is running: PID# `cat $PIDFILE`
else
  echo $DESC is not running
fi
  ;;
  cleanup)
PID=`ps aux | grep $DAEMON | grep -v grep | awk -F' ' '{print $2}'`
kill $PID
rm $PIDFILE
  ;;
  restart|force-reload)
d_stop
sleep 0.5
d_start
  ;;
  *)
echo Usage: $SCRIPTNAME {start|stop|restart|force-reload} 2
exit 1
  ;;
esac

exit 0

##END


Jim Lucas


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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Ben Dunlap
 several packages available to provide it. But I believe that telling
 someone to adopt a complete portal system like CI just to get basic
 authentication is gross overkill. There has to be a better way to
 provide this core functionality without installing a monster package
 that will be 95% superfluous to their needs.

I mentioned CI because it got the second-most votes on a very popular
Stack Overflow question asking for PHP-framework recommendations. The
most-upvoted answer discussed Zend Framework, although it's hard to
tell whether it was a good review of ZF, or a negative one, on
balance:

http://stackoverflow.com/questions/2648/what-php-framework-would-you-choose-for-a-new-application-and-why

Without knowing more about the OP's requirements, it's hard to say
whether CI's other functionality would be largely superfluous. You
might be right, though, and I guess my point was just to recommend
that the OP look at existing, mature, free, open-source solutions
before possibly reinventing the wheel.

I would recommend this to anyone looking to build any sort of web app.
Could be that nothing out there will end up serving your purposes, but
just the experience of looking at existing frameworks, seeing how
they're structured, reviewing some of their code, etc., is still
likely to be valuable.

Ben

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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Ben Dunlap
 I would recommend this to anyone looking to build any sort of web app.
 Could be that nothing out there will end up serving your purposes, but

... and, on further investigation, it looks like CI, surprisingly
enough, doesn't actually have pre-built authentication and access
control (although it does do session management). Solar and ZF do seem
to have their own auth/access-control, though.

Ben

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



[PHP] Reading files in PHP 5.3.0

2009-09-10 Thread Steve Brown
I've been beating my head against a wall all day and can't figure this
one out.  The code below worked perfectly in PHP5.2.4.  However, I
recently upgraded to PHP5.3.0 and this code no longer works.

The function below accepts the path to a text file containing headers
from a cUrl session (example attached).  Basically this function opens
to log file, looks for certain headers and captures some information
from that line.  When called on the attached file (or any log file for
that matter), the following is output:

array(2) {
  [ResponseCode]=
  NULL
  [ErrorMessage]=
  NULL
}

Which means that nothing is getting read from the file.

Now, I'm going to qualify all of this by saying I'm running OSX Snow
Leopard, so I'm fully prepared to believe that Apple fucked something
up in it, as they have done to third party packages on other occasions
in the past.  Well... to be fair, they don't usually fuck up third
party packages, rather they introduce enhancements to the OS that
prevents certain packages from working correctly and could care less
that they broke it.

So did anything change in PHP5.3.0 that would preclude the code below
from working?  Am I going crazy?  Or did Apple f...@# something up in
this release?

Thanks,
Steve

BEGIN CODE
==
function parseResponseHeaders($header_file) {
$http_found = $error_found = false;
$http_reponse = $error_message = NULL;

$response = array();
$response['ResponseCode'] = NULL;
$response['ErrorMessage'] = NULL;

if (!is_file($header_file) || !is_readable($header_file)) {
return $response;
}

$fin = fopen($header_file, 'r');
while ($line = fgets($fin)) {
var_dump($line);

if (substr($line, 0, 4) == 'HTTP') {
$line_explode = explode(' ', $line);
$response['ResponseCode'] = preg_replace('/\D/', '', 
$line_explode[1]);
if ($response['ResponseCode'] != 100) {
$http_found = true;
}
}

if (substr($line, 0, 16) == 'X-Error-Message:') {
$line_explode = explode(' ', $line);
array_shift($line_explode);
$response['ErrorMessage'] = join(' ', $line_explode);
$error_found = true;
}
}
fclose($fin);

var_dump($response);
return $response;
}
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Thu, 10 Sep 2009 20:57:43 GMT
Server: Apache/2.2.6 (Unix) mod_ssl/2.2.6  PHP/5.2.8
X-Powered-By: PHP/5.2.8
Vary: Accept-Encoding
Content-Length: 1630
Content-Type: text/html

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

[PHP] RE: [Formaldehyde] The Most Basic Ajax - PHP Error Debugger

2009-09-10 Thread Andrea Giammarchi

Being something nobody thought before I was expecting some comment ... zero 
Ajax developers here?
Anyway, to make things even more simple I have released the Zero Config client 
side file, which works with most known browsers, IE included, and it does not 
require a single change in existent code, libraries included.

Enjoy (if any) http://code.google.com/p/formaldehyde/

From: an_...@hotmail.com
To: php-general@lists.php.net
Subject: [Formaldehyde] The Most Basic Ajax - PHP Error Debugger
Date: Sat, 5 Sep 2009 19:41:53 +0200








Hi everybody,
I'd love to receive your feedback about my last zero dependencies, easily 
integrable, scalable, fast, lightweight, etc etc Ajax / PHP debugger.

The project has Mit Style License and it is hosted in Google Code:
http://code.google.com/p/formaldehyde/

While this is my blog announcement:
http://webreflection.blogspot.com/2009/09/formaldehyde-ajax-php-error-debugger.html

I hope you'll appreciate the code, the concept, and the simplicity, but here I 
am to know your concerns, or generally speaking, your opinion.

Best Regards,
Andrea Giammarchi
 
With Windows Live, you can organize, edit, and  share your photos.
_
Share your memories online with anyone you want.
http://www.microsoft.com/middleeast/windows/windowslive/products/photos-share.aspx?tab=1

[PHP] Creating alphanumeric id for a table

2009-09-10 Thread aveev

I want to create user generated id like this :
AAA0001
AAA0002
...
AAA0009
AAA0010

where the id consists of 3 alphanumeric characters and 4 numerical digits in
the beginning (for numerical digit, it can grow like this AAA10001). I try
to use php script to generate id like this, where I use the following
script.

?
function generate_id($num) {
$start_dig = 4;
$num_dig = strlen($num);

$id = $num;
if($num_dig = $start_dig) {
$num_zero = $start_dig - $num_dig;

for($i=0;$i $num_zero; $i++) {
$id = '0' . $id;
}
}
$id = 'AAA' . $id;
return $id;
}

$app_id = generate_id(1);
  
?

I assume that I can get increment value/sequence from db  (I used harcoded
increment value  in the code above (generate_id(1))),
but I don't know how I can get this incremental value from db.I use mysql
5.0.
Or has anyone had another solution to create this alphanumeric id  ?

Any help would be much appreciated
Thanks
-- 
View this message in context: 
http://www.nabble.com/Creating-alphanumeric-id-for-a-table-tp25391939p25391939.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] Creating alphanumeric id for a table

2009-09-10 Thread Ben Dunlap
 I assume that I can get increment value/sequence from db  (I used harcoded
 increment value  in the code above (generate_id(1))),
 but I don't know how I can get this incremental value from db.I use mysql
 5.0.

If you're thinking of retrieving the newest value of an AUTO_INCREMENT
column, immediately after inserting a row, there are different ways to
do this depending on how you're connecting to MySQL.

PDO, for example, has a method called lastInsertId():
http://us2.php.net/manual/en/pdo.lastinsertid.php

And the mysql_* family of functions has mysql_insert_id(), etc.

Ben

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



Re: [PHP] Reading files in PHP 5.3.0

2009-09-10 Thread Tommy Pham
--- On Thu, 9/10/09, Steve Brown sbrow...@gmail.com wrote:

 From: Steve Brown sbrow...@gmail.com
 Subject: [PHP] Reading files in PHP 5.3.0
 To: php-general@lists.php.net
 Date: Thursday, September 10, 2009, 4:13 PM
 I've been beating my head against a
 wall all day and can't figure this
 one out.  The code below worked perfectly in
 PHP5.2.4.  However, I
 recently upgraded to PHP5.3.0 and this code no longer
 works.
 
 The function below accepts the path to a text file
 containing headers
 from a cUrl session (example attached).  Basically
 this function opens
 to log file, looks for certain headers and captures some
 information
 from that line.  When called on the attached file (or
 any log file for
 that matter), the following is output:
 
 array(2) {
   [ResponseCode]=
   NULL
   [ErrorMessage]=
   NULL
 }
 
 Which means that nothing is getting read from the file.
 
 Now, I'm going to qualify all of this by saying I'm running
 OSX Snow
 Leopard, so I'm fully prepared to believe that Apple fucked
 something
 up in it, as they have done to third party packages on
 other occasions
 in the past.  Well... to be fair, they don't usually
 fuck up third
 party packages, rather they introduce enhancements to the
 OS that
 prevents certain packages from working correctly and could
 care less
 that they broke it.
 
 So did anything change in PHP5.3.0 that would preclude the
 code below
 from working?  Am I going crazy?  Or did Apple
 f...@# something up in
 this release?
 
 Thanks,
 Steve
 
 BEGIN CODE
 ==
 function parseResponseHeaders($header_file) {
     $http_found = $error_found = false;
     $http_reponse = $error_message = NULL;
 
     $response = array();
     $response['ResponseCode'] = NULL;
     $response['ErrorMessage'] = NULL;
 
     if (!is_file($header_file) ||
 !is_readable($header_file)) {
         return $response;
     }
 
     $fin = fopen($header_file, 'r');
     while ($line = fgets($fin)) {
         var_dump($line);
 
What does var_dump($line); tell you?

Regards,
Tommy

         if (substr($line, 0,
 4) == 'HTTP') {
            
 $line_explode = explode(' ', $line);
            
 $response['ResponseCode'] = preg_replace('/\D/', '',
 $line_explode[1]);
             if
 ($response['ResponseCode'] != 100) {
            
     $http_found = true;
             }
         }
 
         if (substr($line, 0,
 16) == 'X-Error-Message:') {
            
 $line_explode = explode(' ', $line);
            
 array_shift($line_explode);
            
 $response['ErrorMessage'] = join(' ', $line_explode);
            
 $error_found = true;
         }
     }
     fclose($fin);
 
     var_dump($response);
     return $response;
 }
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

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



Re: [PHP] String scrambling

2009-09-10 Thread Eddie Drapkin
On Thu, Sep 10, 2009 at 8:57 PM, Ron Piggott ron@actsministries.org wrote:
 Is there a function in PHP which scrambles strings?

 Example:

 $string = Hello;

 Output might be: ehlol

 Ron

http://www.php.net/manual/en/function.str-shuffle.php

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



Re: [PHP] Hoping for a hand with a login script

2009-09-10 Thread Paul M Foster
On Thu, Sep 10, 2009 at 01:00:19PM -0400, Bob McConnell wrote:

 From: Ben Dunlap

snip

  
  http://codeigniter.com/
  http://framework.zend.com/
  http://www.solarphp.com/
 
 While I have not looked at the last two, there is one thing that bothers
 me about your recommendation of codeigniter. Authentication is a basic
 function that should be used for any web site with interactive features.
 There is such a universal need for this function that there should be
 several packages available to provide it. But I believe that telling
 someone to adopt a complete portal system like CI just to get basic
 authentication is gross overkill. There has to be a better way to
 provide this core functionality without installing a monster package
 that will be 95% superfluous to their needs.
 
 Yes, I have installed codeigniter. I am still trying to figure out why I
 would want to use it.

Moreover, I'm using CI right now, and as far as I know, it does *no*
user authentication. I had to write my own routines, using their session
class to save the user data.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Creating alphanumeric id for a table

2009-09-10 Thread Phpster
Note that this approach has risks around race conditions. Anytime you  
have a construct for the id you run the risk of having it create  
duplicate ids. You will need to handle that.


Bastien

Sent from my iPod

On Sep 10, 2009, at 6:49 PM, Ben Dunlap bdun...@agentintellect.com  
wrote:


I assume that I can get increment value/sequence from db  (I used  
harcoded

increment value  in the code above (generate_id(1))),
but I don't know how I can get this incremental value from db.I use  
mysql

5.0.


If you're thinking of retrieving the newest value of an AUTO_INCREMENT
column, immediately after inserting a row, there are different ways to
do this depending on how you're connecting to MySQL.

PDO, for example, has a method called lastInsertId():
http://us2.php.net/manual/en/pdo.lastinsertid.php

And the mysql_* family of functions has mysql_insert_id(), etc.

Ben

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



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