[PHP] PHP 5.1.1 still slower than PHP 4.x

2005-12-03 Thread Brian Moon
I had run the numbers a while back when 5.0 came out and found that it 
was slower than the 4.x releases at that time.  It seems that 5.1.1 does 
not change this.  Even very simple scripts take longer.  Phorum does not 
use any OO code, so, maybe that is the deal.  Did OO get a big jump in 
speed?  I hope they did, because the folks that like procedural code got 
no speed that I can find.


See my results here: http://phorum.org/phorum5/read.php?14,52162

Brian Moon
Phorum Dev Team

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



Re: [PHP] xml-load via dom and http authentication

2005-12-03 Thread Curt Zirzow
On Thu, Dec 01, 2005 at 11:31:45AM -0800, jonathan wrote:
 i'm loading a dynamically generated xml file like this:
 
 
 $xml=new DomDocument();
 $xml-load(menu_render.php?menu_id=$menu_idformat=xml);
 
 The problem is that this file is in a directory that requires http  
 authentication (via the .htpasswds file).
 
 How could I specify the uname and pwd loading this? I'm using php5  
 and apache 1.3.33

I'm assuming you actually have something like:
  $xml-load(http://hostname/menu_render.php?menu_id=$menu_idformat=xml;);

Just specify the username and pass in the url:
  http://username:[EMAIL PROTECTED]/menu_render.php?...');

Curt.
-- 
cat .signature: No such file or directory

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



Re: [PHP] Mail SMTP settings

2005-12-03 Thread Curt Zirzow
On Sat, Dec 03, 2005 at 12:45:24AM -0700, Dan wrote:
 I have a PHP 4.x install on an Apache server.  I have a PHP  
 application and a call to the mail function.  I have 2 static IP's on  
 the server and I have one web server and one instance of postfix for  
 each IP to basically separate the two sites.  The only issue I have  
 right now is sending mail via PHP.
 
 I have tried to set the SMTP server and reply address via a php_value  
 in my httpd.conf file and via the ini_set function for my site in  
 question.  Regardless of these setting mail is sent from the www user  
 at my main site domain:

The ini setting is called 'sendmail_from'. or you can use the 5th
argument in the mail command.

Curt.
-- 
cat .signature: No such file or directory

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



[PHP] need session_start() to recall session data.

2005-12-03 Thread Matt Monaco
I have the following two methods as part of a class I'm using to transport 
data between pages.

static function pack($object)
{
if (session_id() == ) {
session_start();
}

$class = get_class($object);
$_SESSION[cmsSessionArray][$class] = serialize($object);
}

static function unpack($strObject)
{
session_start();
return unserialize($_SESSION[cmsSessionArray][$strObject]);
}

the pack() method is called by the destructor of the objects I want to save 
like:
function __destruct()
{
parent::pack($this);
}

On subsequent pages the session data is not available until I do a 
session_start().  Regardless of the fact that I think the session shouldn't 
need to be restarted, I don't like the fact that if indeed it has been 
closed that a session_start() on another page will bring back the data. 
(Note, fortunately this doesn't not occur if the browser window has been 
closed, at that point all session data is definitely lost as expected.)

Are session supposed to work this way? 

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



Re: [PHP] Newline character problem...

2005-12-03 Thread tg-php
In addition to what was mentioned below, you can also wrap your text in 
PRE/PRE tags to have it output exactly as you've formatted it:

echo PRE\n;
echo one\n;
echo two\n;
echo /PRE\n;

Actually, I don't think either of these methods is going to output what you 
want.  Even though \n is newline, it's still interpreted as newline/carriage 
return.   Unix, Mac and DOS/Windows PC's all use something different for a 
newline character.  I believe Unix was \n, Mac was \r at some point and 
DOS/Windows PC's used \n\r.  Think my old Amiga used \r as well.  Goofy.

Anyway, it's proably because of this that you can't just do \n and expect it to 
be represented as just a newline (sans carriage return).

If you use the PRE tag, then you can manually do what you want to do:

echo PRE\n;
echo one\n;
echotwo;
echo /PRE\n;


If you don't use the PRE tag, there's an HTML entity that you can use for a 
hard space..  nbsp;   Unfortunately in HTML, if you stack a bunch of spaces, 
it compresses them to one space.

echo onetwo;
..and..
echo one two;

Will both result in:
one two

If you use nbsp; instead of spaces, it'll space it out further:

echo onenbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;two;

Ugly but it works.

Unfortunately (again), if you don't use the PRE tags, you'll have to remember 
to set a monospace font face or you won't get the text alignment you might want.


One other side nugget related to this (formatted and spaces and all that 
nonsense), you can use the NOBR/NOBR tag to tell HTML not to word-wrap the 
text within it.  Comes in handy when you want to force a column heading to be 
one line even though it's got a space in it and your browser wants to wrap the 
line.

Good luck! Hope this helped a little.

-TG

= = = Original message = = =

Robert napisal(a):
 I'm new to PHP but not programming in general. I have used C++ for a while
 and I'm familiar with the newline character as it's basically the same in
 PHP.
 This is the most basic of examples:
 print 'one' ;
 print \n ;
 print 'two' ;
 
 The output of this when accessed on my server is: one two
 It should be: one
two

Hi
well this isn't apache or php related, as it's webbrowser related, and 
even more, it's correct.

The thing is, what You see in Your browser is an interpreted version of 
the html outputed by the php (obvious?), so if You do a html file, and put:
one
two
in there, and view it with Your browser, it will still look like this:
one two
to get the expected (as in C/C++) result, You need to add a br or any 
other line breaking method in there (pone/pptwo/p is another one)
Now, if You'd see the generated source code, You'd notice that there is 
in fact the line break as it should be :)
so it is good to use '\n' to get the output code clear to read, for 
debugging and so..

Best wishes
?ukasz Hejnak


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



Re: [PHP] need session_start() to recall session data.

2005-12-03 Thread Curt Zirzow
On Sat, Dec 03, 2005 at 01:28:21PM -0500, Matt Monaco wrote:
 I have the following two methods as part of a class I'm using to transport 
 data between pages.
 
 static function pack($object)
 {
 if (session_id() == ) {
 session_start();

I wouldn't put a random session_start() in places like this.

 }
 
 $class = get_class($object);
 $_SESSION[cmsSessionArray][$class] = serialize($object);
 }
 ...
 
 the pack() method is called by the destructor of the objects I want to save 
 like:
 function __destruct()
 {
 parent::pack($this);
 }
 

 On subsequent pages the session data is not available until I do a 
 session_start().  Regardless of the fact that I think the session shouldn't 
 need to be restarted, I don't like the fact that if indeed it has been 
 closed that a session_start() on another page will bring back the data. 
 (Note, fortunately this doesn't not occur if the browser window has been 
 closed, at that point all session data is definitely lost as expected.)

I'm not sure what you mean by restarting a session or what 'indeed
has been closed'

btw, your pack and unpack aren't really needed.  All you have to do
is in your __destruct() function is put something like:

  $_SESSION['cmsSessionArray'][__CLASSNAME__] = $this;

And when you pull it out of the session:
  $obj = $_SESSION['cmsSessionArray']['someClass'];

You'll have an instance of that class; you're really causing more
work than needed.

Curt.
-- 
cat .signature: No such file or directory

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



Re: [PHP] need session_start() to recall session data.

2005-12-03 Thread Matt Monaco
Yes, I actually changed the destructors to handle the session as you 
indicated a few minutes after I posted, however I still have no clue as to 
why I would need to do a session_start() to get data from the session.


Curt Zirzow [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On Sat, Dec 03, 2005 at 01:28:21PM -0500, Matt Monaco wrote:
 I have the following two methods as part of a class I'm using to 
 transport
 data between pages.

 static function pack($object)
 {
 if (session_id() == ) {
 session_start();

 I wouldn't put a random session_start() in places like this.

 }

 $class = get_class($object);
 $_SESSION[cmsSessionArray][$class] = serialize($object);
 }
 ...

 the pack() method is called by the destructor of the objects I want to 
 save
 like:
 function __destruct()
 {
 parent::pack($this);
 }


 On subsequent pages the session data is not available until I do a
 session_start().  Regardless of the fact that I think the session 
 shouldn't
 need to be restarted, I don't like the fact that if indeed it has been
 closed that a session_start() on another page will bring back the data.
 (Note, fortunately this doesn't not occur if the browser window has been
 closed, at that point all session data is definitely lost as expected.)

 I'm not sure what you mean by restarting a session or what 'indeed
 has been closed'

 btw, your pack and unpack aren't really needed.  All you have to do
 is in your __destruct() function is put something like:

  $_SESSION['cmsSessionArray'][__CLASSNAME__] = $this;

 And when you pull it out of the session:
  $obj = $_SESSION['cmsSessionArray']['someClass'];

 You'll have an instance of that class; you're really causing more
 work than needed.

 Curt.
 -- 
 cat .signature: No such file or directory 

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



Re: [PHP] Re: A basic question

2005-12-03 Thread Unknown Unknown
Yeah, Apache (or other web server) just gives the HTML page to the web
browser without really doing anything, if a page has a .php extension Apache
gives the page to PHP which proccesses it and returns it to Apache and
Apache gives it to the client. You could do what Matt Monaco says and let
every HTML and PHP page be parsed by PHP but it makes load time slower for
HTML pages with no PHP in them
On 11/27/05, Matt Monaco [EMAIL PROTECTED] wrote:

 In your server configuration file (httpd.conf for apache) you specify
 which
 extensions are parsed by the php module.  It is perfectly acceptable for
 you
 to specify .html in addition to .php as a parsed extension.

 Oil Pine [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Hi,
 
  I am new to php scripting and would like to ask you a basic question.
 
  Could you kindly explain to me why time.php works but time.html does
  not?
 
  pine
 
 
 
  time.php
  --
  ?php
 
  $serverdate = date(l, d F Y h:i a);
  print ($serverdate);
  print ( nbsp; p);
 
  ?
  -
 
 
  time.html
  ---
  !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
  http://www.w3.org/TR/html4/loose.dtd;
  html
 
  head
   titleLocal Time/title
   meta name=GENERATOR content=Text Editor
   meta http-equiv=Content-Type content=text/html; charset=utf-8
  /head
  body
  pThis is a test./p
  ?php
  $serverdate = date(l, d F Y h:i a);
  print ($serverdate);
  print ( nbsp; br);
  ?
  p/ppThis is the end./p
  /body
  /html
  ---

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




--
Hi Everyone, I am running PHP 5 on Windosws XP SP2 with MySQL5, Bye Now!


Re: [PHP] hi everyone

2005-12-03 Thread Unknown Unknown
Quiet? you GOTTA be kidding me, i got like 400 PHP email's here, I don't
have to time to read em all

On 12/1/05, Mehmet Fatih AKBULUT [EMAIL PROTECTED] wrote:

 hi.
 me is registered but till now have had no crucial questions to ask :p
 but soon will need professional help on php ldap functions :)
 then will ask for help from you masters :p
 Regards.
 Bye for now.




--
Hi Everyone, I am running PHP 5 on Windosws XP SP2 with MySQL5, Bye Now!


Re: [PHP] javascript, forms and php

2005-12-03 Thread Unknown Unknown
DO NOT validate anything important with javascript, the user can easily
bypass the javascript by creating his own HTML page or disabling javascript
on his browser. if you *Absouloutly* need to use javascript, check the last
page the browser visited with Javascript or PHP and either allow or deny
access, still, even that is insecure. Now, for your main question, this is a
PHP board, not a Javascript board post this on a javascript list



On 12/1/05, Brent Baisley [EMAIL PROTECTED] wrote:

 You should have posted this to a javascript board, it has nothing to
 do with PHP. That said, if the form field name contains special
 characters, like [], you can reference it like this:
 document.formname.elements['checkbox1[]'].

 Use the elements[] reference style.

 On Dec 1, 2005, at 12:42 PM, Kelly Meeks wrote:

  Hi all,
 
 
 
  I'm hoping someone can help me with this problem.
 
 
 
  I'm using javascript for some client side field validation in a form
  (method=post) that gets managed via php.
 
 
 
  This particular form makes extensive use of checkboxes.  I've
  always like
  how when named properly (field name of checkbox1[ ]), php will
  pass that
  variable as an array that contains all the values selected in the
  form.
  Very handy.  BUT,
 
 
 
  How do you then reference that variable via javascript to do any
  client-side
  validation?  The code I use makes reference to the field's id, and
  it still
  doesn't seem to check things properly.
 
 
 
  Is there any way around this, or what am I missing?
 
 
 
  TIA,
 
 
 
  Kelly
 
 
  --
  This message has been scanned for viruses and
  dangerous content by MailScanner, and is
  believed to be clean.
 

 --
 Brent Baisley
 Systems Architect
 Landover Associates, Inc.
 Search  Advisory Services for Advanced Technology Environments
 p: 212.759.6400/800.759.0577

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




--
Hi Everyone, I am running PHP 5 on Windosws XP SP2 with MySQL5, Bye Now!


[PHP] Security/$_REQUEST vars... How do you do it?

2005-12-03 Thread Michael Hulse

Hello,

This is my first time posting to the list... I hope this question is 
not too silly, I am definitely not a guru at PHP.


Anyway, in one of my latest projects, I find myself using this bit of 
code quite a bit:


if((isset($_REQUEST['sub']))  (!empty($_REQUEST['sub']))) {
... code here...
}

Can I write a function that would make my life easier? Maybe something 
like this (not tested):


 function security_check():
function security_check($x) {
$error = false;
if((isset($x))  (!empty($x))) {
$error = false;
return $error;
} else {
$error = true;
return $error;
}
}

Or, is it perfectly valid and secure to use @, like so:

@... code here...

I know that it completely depends on the what one is trying to 
accomplish in ones scripts, but any guidance and/or suggestions would 
be greatly appreciated.


Thanks, I really appreciate your time.
Cheers,
Micky
--
¸.·´¯`·.¸¸(((º`·.¸¸.·´¯`·.¸¸º
·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸º
`·.¸º¸.·´¯`·.¸¸º

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



Re: [PHP] Security/$_REQUEST vars... How do you do it?

2005-12-03 Thread comex
 if((isset($_REQUEST['sub']))  (!empty($_REQUEST['sub']))) {
empty is a language construct, not a function, so that is not
necessary.  You can just do !empty(...).


 $error = false;
  return $error;
In your security_check function, you set $error to false in the
beginning for no reason; in fact, you don't need to use it all.  You
could return false or return true, or simply
return !empty($x);

However, that doesn't actually work because when you call the
function, it assumes that $_REQUEST[whatever] is defined and could
cause a notice if it isn't; and $x will always be defined, even if set
to null.

Since your variables are coming from REQUEST anyway, you could write
it like this:
function security_check($x) {
 return !empty($_REQUEST[$x]);
}

Then, if(!security_check('sub')) { ... }

Of course, there are people who can be more helpful and will probably
tell you to do more than just check if the variable exists.

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



Re: [PHP] Security/$_REQUEST vars... How do you do it?

2005-12-03 Thread Michael Hulse

Hi Comex, thanks for the quick response, I really appreciate it.  :)

On Dec 3, 2005, at 3:29 PM, comex wrote:

empty is a language construct, not a function, so that is not 
necessary.  You can just do !empty(...).


Oh, do you mean that I should do this instead:

if((isset($_REQUEST['sub']))  !empty($_REQUEST['sub'])) {


You could return false or return true, or simply return !empty($x);


Ahhh, great point!

However, that doesn't actually work ... and could cause a notice if it 
isn't; and $x will always be defined, even if set to null.


Yes, I actually just realized this via testing/experimenting...  :(

Since your variables are coming from REQUEST anyway, you could write 
it like this:

function security_check($x) {
 return !empty($_REQUEST[$x]);
}
Then, if(!security_check('sub')) { ... }


Ah, great idea, thanks! You have been very helpful, thanks.   :D

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



Re: [PHP] Security/$_REQUEST vars... How do you do it?

2005-12-03 Thread comex
 Oh, do you mean that I should do this instead:
No, I meant that you don't have to include the isset at all.  From the manual:

empty() is the opposite of (boolean) var, except that no warning is
generated when the variable is not set.

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



[PHP] How would you write this?

2005-12-03 Thread Michael B Allen
The following code works but I'm a little new to PHP and I'd like to
know if there are better ways to achive the same thing.

In the below form example, if the user supplies one or more fields but
not all that are required, the form is redisplayed but fields that were
supplied are prepopulated and the ones that are required but are missing
are highlighted in red.

Can anyone recommend a better technique or elighten me about features of
the language that I've missed?

Mike

html
body

?php
$set = 0;
$username = ;
$password = ;

if (isset($_POST['username'])) {
$username = trim($_POST['username']);
if (strlen($username)  0) {
$set |= 0x01;
}   
}
if (isset($_POST['password'])) {
$password = trim($_POST['password']);
if (strlen($password)  0) {
$set |= 0x02;
}   
}
if (($set  0x03) == 0x03) { 
echo Logging in with:  . $username . ':' . $password;
} else {
?   
 
form action=login.php method=post
table 
trtd colspan=2Login:/td/tr
trtdUsername:/td
 
?php
if ($set != 0  ($set  0x01) == 0) { 
echo td bgcolor=\#ff\;
} else {
echo td; 
}
echo input type=\username\ name=\username\ value=\ . $username . 
\/; 
?   
 
/td/tr
trtdPassword:/td
 
?php
if ($set != 0  ($set  0x02) == 0) { 
echo td bgcolor=\#ff\;
} else {
echo td; 
}
?   
 
input type=password name=password/
/td/tr
trtd colspan=2input type=submit value=Login//td/tr
/table
/form 
 
?php
}
?   
 
p/a href=login.phpclick me/a
 
/body 
/html

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



RE: [PHP] How would you write this?

2005-12-03 Thread Eternity Records Webmaster
Hi...

the easiest way I have found to do exactly what your looking for is to use a
pear package called html_quickform. I found it easy to use and it saves me
hours and hours of work too. If your interested go to
www.pear.php.net/html_quickform and have a look.



-Original Message-
From: Michael B Allen [mailto:[EMAIL PROTECTED]
Sent: Saturday, December 03, 2005 10:00 PM
To: php-general@lists.php.net
Subject: [PHP] How would you write this?


The following code works but I'm a little new to PHP and I'd like to
know if there are better ways to achive the same thing.

In the below form example, if the user supplies one or more fields but
not all that are required, the form is redisplayed but fields that were
supplied are prepopulated and the ones that are required but are missing
are highlighted in red.

Can anyone recommend a better technique or elighten me about features of
the language that I've missed?

Mike

html
body

?php
$set = 0;
$username = ;
$password = ;

if (isset($_POST['username'])) {
$username = trim($_POST['username']);
if (strlen($username)  0) {
$set |= 0x01;
}
}
if (isset($_POST['password'])) {
$password = trim($_POST['password']);
if (strlen($password)  0) {
$set |= 0x02;
}
}
if (($set  0x03) == 0x03) {
echo Logging in with:  . $username . ':' . $password;
} else {
?

form action=login.php method=post
table
trtd colspan=2Login:/td/tr
trtdUsername:/td

?php
if ($set != 0  ($set  0x01) == 0) {
echo td bgcolor=\#ff\;
} else {
echo td;
}
echo input type=\username\ name=\username\ value=\ . $username .
\/;
?

/td/tr
trtdPassword:/td

?php
if ($set != 0  ($set  0x02) == 0) {
echo td bgcolor=\#ff\;
} else {
echo td;
}
?

input type=password name=password/
/td/tr
trtd colspan=2input type=submit value=Login//td/tr
/table
/form

?php
}
?

p/a href=login.phpclick me/a

/body
/html

--
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] XSLT Processing w/ Embedded PHP Strips Trailing '?'

2005-12-03 Thread Michael B Allen
If I run an xslt processor on some xml w/ PHP in it, the closing '?' gets 
removed:

tr
tdUsername:/td

?php if ($set != 0  ($set  0x01) == 0) {
echo td bgcolor=\#ff\;
} else {
echo td;
}
echo /tdinput type=\username\ name=\username\ value=\ . $username 
. \/;


Would anyone happen to know why this is happening?

I'm using xmlproc from libxslt-1.1.11.

Thanks,
Mike

original XML input:

trtdUsername:/td

?php
if ($set != 0  ($set  0x01) == 0) {
echo td bgcolor=\#ff\;
} else {
echo td;
}
echo /tdinput type=\username\ name=\username\ value=\ . 
$username . \/;
?

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



Re: [PHP] Mail SMTP settings

2005-12-03 Thread Dan
Yes that does work but the return path and my mail headers still show  
the main domain.  My point is that PHP should be acessing my SMTP  
server specified but it is using the default local host instead.


Dan T

On Dec 3, 2005, at 11:06 AM, Curt Zirzow wrote:


On Sat, Dec 03, 2005 at 12:45:24AM -0700, Dan wrote:

I have a PHP 4.x install on an Apache server.  I have a PHP
application and a call to the mail function.  I have 2 static IP's on
the server and I have one web server and one instance of postfix for
each IP to basically separate the two sites.  The only issue I have
right now is sending mail via PHP.

I have tried to set the SMTP server and reply address via a php_value
in my httpd.conf file and via the ini_set function for my site in
question.  Regardless of these setting mail is sent from the www user
at my main site domain:


The ini setting is called 'sendmail_from'. or you can use the 5th
argument in the mail command.

Curt.
--
cat .signature: No such file or directory

--
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] How would you write this?

2005-12-03 Thread Stephen Leaf
I personally would use javascript to evaluate the form and highlight the 
fields onsubmit.

However as a backup I'd do the evaluating in php and add an error label under 
the field.

echo td;
if ($noPass) echo  color='red';
echo Password/td;
if ($noPass) echo td color='red'You must supply a password/td;

Something along those lines.

On Saturday 03 December 2005 21:00, Michael B Allen wrote:
 The following code works but I'm a little new to PHP and I'd like to
 know if there are better ways to achive the same thing.

 In the below form example, if the user supplies one or more fields but
 not all that are required, the form is redisplayed but fields that were
 supplied are prepopulated and the ones that are required but are missing
 are highlighted in red.

 Can anyone recommend a better technique or elighten me about features of
 the language that I've missed?

 Mike

 html
 body

 ?php
 $set = 0;
 $username = ;
 $password = ;

 if (isset($_POST['username'])) {
 $username = trim($_POST['username']);
 if (strlen($username)  0) {
 $set |= 0x01;
 }
 }
 if (isset($_POST['password'])) {
 $password = trim($_POST['password']);
 if (strlen($password)  0) {
 $set |= 0x02;
 }
 }
 if (($set  0x03) == 0x03) {
 echo Logging in with:  . $username . ':' . $password;
 } else {
 ?

 form action=login.php method=post
 table
 trtd colspan=2Login:/td/tr
 trtdUsername:/td

 ?php
 if ($set != 0  ($set  0x01) == 0) {
 echo td bgcolor=\#ff\;
 } else {
 echo td;
 }
 echo input type=\username\ name=\username\ value=\ . $username
 . \/; ?

 /td/tr
 trtdPassword:/td

 ?php
 if ($set != 0  ($set  0x02) == 0) {
 echo td bgcolor=\#ff\;
 } else {
 echo td;
 }
 ?

 input type=password name=password/
 /td/tr
 trtd colspan=2input type=submit value=Login//td/tr
 /table
 /form

 ?php
 }
 ?

 p/a href=login.phpclick me/a

 /body
 /html

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



Re: [PHP] Writing a mailing list program with php/mysql.

2005-12-03 Thread Mark Steudel



Hi there, 

 

There are TONS of tutorials out there on how to store this information into 
a database instead of just mailing it to your self, just google php and 
mysql ...





First you'll
need to create your database using some sort of mysql console (command
line, web based like phpMyAdmin, desktop application like navicat or
mysql administrator)



 

Your database looks like it only needs a few fields


 

id 

Email

prayer

 newsletter 

announce

 

// pulled from php.net 

// connecto to your database 

$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')

    or die('Could not connect: ' . mysql_error());


mysql_select_db('my_database') or die('Could not select database');



 

 replace this code =




 //this is the email message that will be sent


 $message=$mail. would like to be signed up for the .$list. mailing


 lists\r\n;


 //send the email now


 mail([EMAIL PROTECTED], mailing list request, $message,


 From: mailing list form[EMAIL PROTECTED]);

== End replace code



// validate your forms input, could be a function instead



if ( $_POST['prayer'] == 'on' )  $prayer = 'yes' else  $prayer = 'no';

if ( $_POST['news'] == 'on' )    $news = 'yes' else $news = 'no';

 if ( $_POST['announce'] == 'on' )  $announce = 'yes' else  $announce= 'no';

 

 

// next I'll contruct a query to insert it into my database

$query = INSERT INTO newslettertable( id, email, prayer, newsletter, 
announce) VALUES ( '', '.$mail.', '.$prayer.', '. $news.', 
'.$announce.' );

 

// now I'll actually run the query, if there is an error it will spit the 
error out to the screen

$result = mysql_query($query) or die('Query failed: ' . mysql_error());



 

// How to get the databack out from 

$query = SELECT * FROM newslettertable WHERE prayer = 'yes';

 $result = mysql_query($query) or die('Query failed: ' . mysql_error());

 

// Now we'll loop through the data 

while ( $objData = mysql_fetch_object( $result ) )

{

 mail(  $objData-email, 'Prayer Newsletter', 'Prayer newsletter body' 
);

}

 

Hopefully that gives you a rough idea how little more you need to do to hook 
it up to a database.

 

Mark





-Original Message-


From: Eternity Records Webmaster [EMAIL PROTECTED]


To: php-general@lists.php.net


Date: Sat, 3 Dec 2005 19:24:18 -0500


Subject: [PHP] Writing a mailing list program with php/mysql.




 Hi.


 


 I've written a mailing list form for a website. It currently works by


 having


 the subscriber check up to 3 checkboxes depending on the mailing list


 they


 want to sign up for (prayer, newsletter and announce). They then type


 their


 email address into the email address field and click the subscribe


 button.


 After they do that, the php script will check the form for validity and


 return error if not filled out the right way or it will send an email


 to me


 if it worked (in the sence that the form was filled out by the user


 the


 right way). What I need to know is: given the code below, are there any


 examples of php/mysql driven mailing list scripts that I can use as a


 tutorial on helping me to convert mine to a mysql database driven


 program?


 Any ideas/recommendations would be apreciated. Thanks for all the help.


 


 The code below if copied and pasted into their own seperate files


 should


 work on any apache/php 5.0.5/mysql 3.xx server.


 


 mailing_list.html:


 this file was included in the home page of the website with include().


 [code]


 form action=script/mailinglist.php method=post


 table border=1 cellspacing=0 cellpadding=2 style=border-color:


 #600;


 trth style=background-color: #600; color:#fff; text-align: center;


 padding: 0 10px;Sign up for the mailing lists!/th/tr


 trtd


 input type=checkbox name=prayerE Prayer input type=checkbox


 name=newsE News input type=checkbox name=announceE Announce


 /td/tr


 trtd style=background-color: #fff; text-align: center; padding: 0


 10px;


 p style=margin-bottom: 0;


 Your email address: input type=text name=emailbr


 input class=button type=submit value=Sign up now! /br /


 /p


 a href=comunity.phpGo to the Online Comunity page to find out


 more!/abr


 /td/tr


 /table


 /form


 [end of mailing_list.html code]


 


 list_functions.php: the user defined functions created to use in


 mailinglist.php.


 [code]


 ?php


 //checkemail checks an email address to see if its valid


 //true if valid and false otherwise


 function checkemail($email){


 if (eregi('[EMAIL PROTECTED]([a-zA-Z]{2,3})$',


 $email)) {


 return $email; }


 else {return false;}}


 


 //checklist checks that at least 1 mailing list exists


 //returns a string containing mailing lists signed up for or null if


 none


 checked


 function checklist($list1, $list2, $list3){


 if($list1==on){$final=Prayer\n;}


 else {$final=;}


 if($list2==on) {$final.=News\n;}


 else {$final.=;}


 if($list3==on) {$final.=announce\n;}


 else