php-general Digest 31 Mar 2008 16:40:21 -0000 Issue 5378
Topics (messages 272324 through 272345):
Re: preg_replace_callback(), how to pass function argument/param?
272324 by: Casey
272325 by: Micky Hulse
272326 by: Casey
272327 by: Micky Hulse
question about select tag in php
272328 by: Sudhakar
272336 by: admin.buskirkgraphics.com
restricting filesystem access
272329 by: Hamar Gábor
272330 by: paragasu
272333 by: Hamar Gábor
272335 by: paragasu
272337 by: Daniel Brown
Problem in a generate password function
272331 by: Mário Gamito
272332 by: Stut
Re: LDAP in php
272334 by: pobox.verysmall.org
Re: PHP 5 file_get_contents() problems
272338 by: Daniel Brown
Re: new lines in textareas?
272339 by: Daniel Brown
Re: Google Pagerank script
272340 by: Daniel Brown
272345 by: admin.buskirkgraphics.com
Re: auto generated PDF
272341 by: Daniel Brown
Re: character encoding
272342 by: Bill
Reporting mail as spam
272343 by: Sándor Tamás (HostWare Kft.)
272344 by: Daniel Brown
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
On Sun, Mar 30, 2008 at 9:37 PM, Micky Hulse <[EMAIL PROTECTED]> wrote:
> Casey wrote:
> > preg_replace_callback($f, 'mah_processTags(\'$0\', $arg1)', $text);
> > Does this work?
>
> Awww, does not seem to work. :(
>
> But maybe I need to dink with the code a bit more...
>
> I would like to avoid setting a global here. :D
>
> Thanks for the help Casey! I will let you know if I get it working. I
> may just have to think of a different approach here.
>
>
>
> Cheers,
> Micky
>
>
Hmmm. I've searched around, and it seems that only a global would work :/
--
-Casey
--- End Message ---
--- Begin Message ---
Casey wrote:
Hmmm. I've searched around, and it seems that only a global would work :/
Thanks for the help Casey! I really appreciate it. :)
Yah, I think I will use a global for now... Until I can think of an
alternative coding approach.
Have a good one!
Cheers,
Micky
--
Wishlist: <http://tinyurl.com/22xonb>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
--- End Message ---
--- Begin Message ---
On Sun, Mar 30, 2008 at 10:06 PM, Micky Hulse <[EMAIL PROTECTED]> wrote:
> Casey wrote:
> > Hmmm. I've searched around, and it seems that only a global would work :/
>
> Thanks for the help Casey! I really appreciate it. :)
>
> Yah, I think I will use a global for now... Until I can think of an
> alternative coding approach.
>
> Have a good one!
>
>
>
> Cheers,
> Micky
>
>
What does mah_process_tags do anyway? XD
--
-Casey
--- End Message ---
--- Begin Message ---
Casey wrote:
What does mah_process_tags do anyway? XD
Ah, hehe... Oh, basically I am trying to write a plugin for the
Textpattern CMS:
<http://textpattern.com/>
processTags() is a core TXP function... Basically, it parses any TXP
template tags (<txp:function_name atts="foo" />).
Long story short, I am am modifying the processTags() function so that
it looks for class methods when parsing template tags, vs. looking for
regular functions.
Thanks again Casey! I really appreciate your help. :)
Cheers,
Micky
--
Wishlist: <http://tinyurl.com/22xonb>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
--- End Message ---
--- Begin Message ---
i have two select tags as part of a registration form, city1 city2 where
city1 has a list of regions and similar for city2
there are different regions for city1 and city2 so instead of all the
regions appearing one after the other i would like to create a blank option
followed by the next set of regions for formatting purpose only.
ex=
<select name="city1">
<option <?php if ($city1=="region1"){echo "SELECTED";}?>
value="region1">Select region1</option>
<option <?php if ($city1=="nameofregion1"){echo "SELECTED";}?>
value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($city1=="nameofregion2"){echo "SELECTED";}?>
value="nameofregion2">nameofregion2</option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>
</select>
<select name="city2">
<option <?php if ($city2=="region2"){echo "SELECTED";}?>
value="region2">Select region2</option>
<option <?php if ($city2=="nameofregion1"){echo "SELECTED";}?>
value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="2"){echo "SELECTED";}?> value="2"></option>
<option <?php if ($city2=="nameofregion2"){echo "SELECTED";}?>
value="nameofregion2">nameofregion2</option>
<option <?php if ($northisland=="3"){echo "SELECTED";}?> value="3"></option>
</select>
from a php validation perspective if a user does not select any of the
regions or both the regions i am displaying an error message asking them to
either select 1 region from either city1 or city2
as of now there is a blank option being displayed which is working fine, i
am having an issue with the php validation.
until i introduced value=0 my rules for validating the select tag were:
1. user cannot leave both the select tags with the default option which is
"Select region1" & "Select region2"
2. user cannot select both the regions from city1 & city2 select tags
the code of 2. is
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}
now by introducing <option <?php if ($northisland=="0"){echo "SELECTED";}?>
value="0"></option> there is a conflict with the above php validation code
used in point 2.
1.
is it correct to use 1,2,3 as part of the following <option> tag or should i
only use 0 everywhere
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>
2.
how can i get around the conflict that is being created by introducing this
value=0 with
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}
as i need the above php code and i also need the blank space for formatting
purpose
please advice.
thanks.
--- End Message ---
--- Begin Message ---
Code wise your form options are too bulky and you need to look at slimming that
down like below. Not that my example is prefect but easier to control the
option enviroment.
echo "<select name='city1'>";
for($d=1; $d<=2; $d++)
{
if($city1 == "region$d"){
echo "<option selected value='region$d'>region$d;
}ELSE{echo "<option value='region$d'>region$d;}
}
echo "</select><BR><select name='city2'>";
for($d=1; $d<=3; $d++)
{
if($city1 == "region$d"){
echo "<option selected value='region$d'>region$d;
}ELSE{echo "<option value='region$d'>region$d;}
}
echo "</select>";
Also I would use some onblur or onsubmit javascript for form validation
submitting and then showing the error is NOT a good way to validate a form.
Richard L. Buskirk
Blame the GUI between your chair and keyboard.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
i have two select tags as part of a registration form, city1 city2 where
city1 has a list of regions and similar for city2
there are different regions for city1 and city2 so instead of all the
regions appearing one after the other i would like to create a blank option
followed by the next set of regions for formatting purpose only.
ex=
<select name="city1">
<option <?php if ($city1=="region1"){echo "SELECTED";}?>
value="region1">Select region1</option>
<option <?php if ($city1=="nameofregion1"){echo "SELECTED";}?>
value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($city1=="nameofregion2"){echo "SELECTED";}?>
value="nameofregion2">nameofregion2</option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>
</select>
<select name="city2">
<option <?php if ($city2=="region2"){echo "SELECTED";}?>
value="region2">Select region2</option>
<option <?php if ($city2=="nameofregion1"){echo "SELECTED";}?>
value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="2"){echo "SELECTED";}?> value="2"></option>
<option <?php if ($city2=="nameofregion2"){echo "SELECTED";}?>
value="nameofregion2">nameofregion2</option>
<option <?php if ($northisland=="3"){echo "SELECTED";}?> value="3"></option>
</select>
from a php validation perspective if a user does not select any of the
regions or both the regions i am displaying an error message asking them to
either select 1 region from either city1 or city2
as of now there is a blank option being displayed which is working fine, i
am having an issue with the php validation.
until i introduced value=0 my rules for validating the select tag were:
1. user cannot leave both the select tags with the default option which is
"Select region1" & "Select region2"
2. user cannot select both the regions from city1 & city2 select tags
the code of 2. is
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}
now by introducing <option <?php if ($northisland=="0"){echo "SELECTED";}?>
value="0"></option> there is a conflict with the above php validation code
used in point 2.
1.
is it correct to use 1,2,3 as part of the following <option> tag or should i
only use 0 everywhere
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>
2.
how can i get around the conflict that is being created by introducing this
value=0 with
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}
as i need the above php code and i also need the blank space for formatting
purpose
please advice.
thanks.
--- End Message ---
--- Begin Message ---
Hi,
I am a new php user and I have a question, for which I couldn't find any
answer.
I'd like to restrict php code to access the filesystem. I'd like to have
only one directory where the php code can write, create or read files,
and an other directory hierarchy where the php codes present. I need
this to avoid php code to rewrite other php code in case of bug and/or
an attack.
I already tried the open_basedir directive, but it couldn't work because
in this case the executed php have to be in the accessable directory
hierarchy.
Thanks,
Gabor
--- End Message ---
--- Begin Message ---
> I'd like to restrict php code to access the filesystem. I'd like to have
> only one directory where the php code can write, create or read files,
> and an other directory hierarchy where the php codes present. I need
> this to avoid php code to rewrite other php code in case of bug and/or
> an attack.
>
> I already tried the open_basedir directive, but it couldn't work because
> in this case the executed php have to be in the accessable directory
> hierarchy.
>
> Thanks,
> Gabor
>
it depends, if you run your own server (you have root password). then you
can do something
about this. but if you run on shared server, i don't think you have a lot of
options.
if you afraid the php code to rewrite other code (rare case). just chmod all
the php files
to 644.
--- End Message ---
--- Begin Message ---
Hi,
Thank you for the answer.
I am running my site on a shared server, but I can overwrite the options
in the php.ini file. Unfortunately php runs as my user, so changing the
permissions to 644 doesn't work, php is still able to write anything.
Gabor
2008. 03. 31, hétfő keltezéssel 16.51-kor paragasu ezt írta:
> > I'd like to restrict php code to access the filesystem. I'd like to have
> > only one directory where the php code can write, create or read files,
> > and an other directory hierarchy where the php codes present. I need
> > this to avoid php code to rewrite other php code in case of bug and/or
> > an attack.
> >
> > I already tried the open_basedir directive, but it couldn't work because
> > in this case the executed php have to be in the accessable directory
> > hierarchy.
> >
> > Thanks,
> > Gabor
> >
>
> it depends, if you run your own server (you have root password). then you
> can do something
> about this. but if you run on shared server, i don't think you have a lot of
> options.
> if you afraid the php code to rewrite other code (rare case). just chmod all
> the php files
> to 644.
--- End Message ---
--- Begin Message ---
> Thank you for the answer.
>
> I am running my site on a shared server, but I can overwrite the options
> in the php.ini file. Unfortunately php runs as my user, so changing the
> permissions to 644 doesn't work, php is still able to write anything.
>
> Gabor
>
ok.. your hosting enable the php suexec. i afraid there is not much you can
do to modified the php.ini. you may use ini_set() or the .htaccess to
override
the value anyway.
one thing you can do. sanitize input and make sure you code good :p
--- End Message ---
--- Begin Message ---
On Mon, Mar 31, 2008 at 4:21 AM, Hamar Gábor <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am a new php user and I have a question, for which I couldn't find any
> answer.
>
> I'd like to restrict php code to access the filesystem. I'd like to have
> only one directory where the php code can write, create or read files,
> and an other directory hierarchy where the php codes present. I need
> this to avoid php code to rewrite other php code in case of bug and/or
> an attack.
Are you saying that you want to use one file to allow people to
write to your server without allowing them to overwrite other files?
Try creating a directory, chmod 777 if needed, and then in your write
routing, disallow periods (.), slashes (/), backslashes (\), et
cetera. And you may also want to look into escapeshellarg() and
escapeshellcmd() depending on your code. You can also chmod the
directory and all files within where the PHP files are located to 644,
which will disallow writing if Apache isn't running suExec.
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
--- End Message ---
--- Begin Message ---
Hi,
I have the code of a function to generate a random 10 character long
password following my signature.
To test it i do:
$clearpass = create_pass();
print('Clear: ' . $clearpass);
die();
But the output is only "Clear:"
Why isn't it working ?
Any help would be appreciated.
Warm Regards,
Mário Gamito
--
function create_pass ()
{
$length=10;
$password = "";
$possible = "0123456789abcdefghijklmnopqrstuvxz";
$i = 0;
while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
return $password;
}
--- End Message ---
--- Begin Message ---
Mário Gamito wrote:
I have the code of a function to generate a random 10 character long
password following my signature.
To test it i do:
$clearpass = create_pass();
print('Clear: ' . $clearpass);
die();
But the output is only "Clear:"
Why isn't it working ?
Works fine here: http://dev.stut.net/php/mario.php
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
Chris schrieb:
If ldap can already use a database backend, just use the normal ldap_*
functions to do all of the work, don't re-invent it all.
http://www.php.net/ldap
Just wanted to avoid installing and maintaining a LDAP server and
mapping all the data.
Perhaps I am underestimating it, but just to read one URI like request,
find the data and send it back in some form, does not look difficult to
implement. We do not need full LDAP support, just to feel Thunderbird
and Squirrelmail address books. Both can't edit LDAP yet anyway.
--- End Message ---
--- Begin Message ---
On Sun, Mar 30, 2008 at 6:03 PM, php <[EMAIL PROTECTED]> wrote:
> Thanks Greg...I am aware of the allow_url_fopen/allow_url_include
> relationship.
>
> Your suggestion to look into curl was implemented and there still seems to
> be something else afoot.
>
> I created a simple set of curl functions which just printed a remote url to
> the browser window. This tested well on an alternate test site which has PHP
> 5 running.
>
> However back on the hosting client I'm having problems with, curl throws the
> following error message:
> CURLE_COULDNT_RESOLVE_HOST (6)
>
> Couldn't resolve host. The given remote host was not resolved.
That's a DNS issue, not a PHP issue. Is this a shared web host,
or one for which you have root access? If you have at least shell
access without a jail (chroot), try PING'ing the domain from the
server and see what happens. It could even be something as simple as
a typo in the domain, but most likely it's a DNS resolution problem.
If you want to test your script on a different server, let me know
and I'll set you up with a temporary account on one of mine.
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
--- End Message ---
--- Begin Message ---
On Sun, Mar 30, 2008 at 12:26 AM, Mary Anderson
<[EMAIL PROTECTED]> wrote:
> Hi all,
> I have a php script which produces text which is to be displayed in
> a textarea. I have the wrap for the text area set to 'hard'. I need to
> have newlines inserted in the text.
> "\n" and "<br>" don't work. They just get quoted literally in the
> text. I suspect I need to use htmlspecialchars , but don't know what
> special character to feed it.
Sounds like you're using literal quotes here, Mary. Single quotes
('like this')take all data between them as literal, while double
quotes ("like this") translate things within.
$a = "Hello!";
$b = "I just wanted to say: $a";
$c = 'I just wanted to say: $a';
$d = "The quick brown fox jumped over the lazy dogs.\n";
$e = 'The quick brown fox jumped over the lazy dogs.\n';
The above will output as follows:
$a: Hello!
$b: I just wanted to say: Hello!
$c: I just wanted to say: $a
$d: The quick brown fox jumped over the lazy dogs. (with a newline)
$e: The quick brown fox jumped over the lazy dogs.\n
You may instead want to use HEREDOC syntax.
$text =<<<EOT
This will allow for actual newlines to be carried over.
This also means that Windows-vs-Linux-vs-Mac newlines
are translated exactly as they were entered, so if you're
typing the data into the HEREDOC in a standard Windows
environment, you'll have \r\n, whereas Linux will have \n, and
Mac will have \r. Keep in mind, in a HEREDOC, those
newline characters will not translate, but variables will.
$b
EOT;
As always, if you want a newline after the final text is typed,
include one full blank line after. And always end your HEREDOC by
typing the signifier as the first character on the line.
Sorry if this is "dumbing it down" for you, but I wanted to take
the opportunity to not only address what may be your problem, but also
put this tidbit into the archives with the question you asked, since
someone down the road may very well find your question with that
problem. ;-)
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
--- End Message ---
--- Begin Message ---
On Sun, Mar 30, 2008 at 12:25 PM, tedd <[EMAIL PROTECTED]> wrote:
>
> Sure, a few years ago I spent a considerable amount of time finding
> the code and here it is:
>
> http://www.webbytedd.com/a/page-rank/index.php
>
> It used to work, but now it doesn't.
>
> Anyone care to tell me why it doesn't work anymore and how to fix it?
Because it's not there. A lot of times, when you don't have a
script installed and you try to access it, it won't work, it'll just
lead to a 404, like in your case. ;-P
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
--- End Message ---
--- Begin Message ---
If you do have a index.php file in that directory and you are sure the path is
correct check the chmod and chown of the index.php file.
Richard L. Buskirk
Dont be so -1 cubed.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
On Sun, Mar 30, 2008 at 12:25 PM, tedd <[EMAIL PROTECTED]> wrote:
>
> Sure, a few years ago I spent a considerable amount of time finding
> the code and here it is:
>
> http://www.webbytedd.com/a/page-rank/index.php
>
> It used to work, but now it doesn't.
>
> Anyone care to tell me why it doesn't work anymore and how to fix it?
Because it's not there. A lot of times, when you don't have a
script installed and you try to access it, it won't work, it'll just
lead to a 404, like in your case. ;-P
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On Sun, Mar 30, 2008 at 5:27 AM, Alain Roger <[EMAIL PROTECTED]> wrote:
> Hi,
>
> i want to implement on my web portal electronic invoicing system.
> basically data will be stored into PostgreSQL DB.
>
> I would like to know if someone already have experiences with such feature
> or where could i find some tutorials or help about this topic.
>
> Concretly, user will buy some products/services online and i would like to
> send him a PDF invoice via email.
A lot of people don't realize, but if you're using Linux, CUPS has
a nice print-to-PDF-file option. It's not native PHP, of course, but
it's a nice, quick, reliable alternative.
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
--- End Message ---
--- Begin Message ---
Ok I give it a try as soon as I can.
>> Hotmail will accept mail delivery from PHP ?
>
> Sure. There is nothing specific of PHP that prevents Hotmail from
> accepting messages sent by PHP scripts.
--- End Message ---
--- Begin Message ---
Hi,
I wrote a little registration routine, which will send a confirmation letter to
the user with a random number in the message body (my site is on a host, so I
can't write in the subject, and ask the user to reply), which can be clicked
then, and my site will finish the registration. My big problem is, that this
host inserts an X header to the mail which identifies my PHP script as the
X-PHP. As I recognize, this header adds a huge number to the spam score. Is
there any possibility, to reduce the other scores? By the way, what counts most
in a spam?
Thanks,
SanTa
--- End Message ---
--- Begin Message ---
On Mon, Mar 31, 2008 at 12:01 PM, Sándor Tamás (HostWare Kft. )
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I wrote a little registration routine, which will send a confirmation letter
> to the user with a random number in the message body (my site is on a host,
> so I can't write in the subject, and ask the user to reply), which can be
> clicked then, and my site will finish the registration. My big problem is,
> that this host inserts an X header to the mail which identifies my PHP script
> as the X-PHP. As I recognize, this header adds a huge number to the spam
> score. Is there any possibility, to reduce the other scores? By the way, what
> counts most in a spam?
Paul Graham wrote an interesting essay several years ago about
that, including some great real-world examples using Bayesian filters
and scores. I'd recommend giving it a look:
http://www.paulgraham.com/spam.html
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
--- End Message ---