php-general Digest 3 Jun 2007 02:53:12 -0000 Issue 4826
Topics (messages 256004 through 256020):
Re: Error logging
256004 by: itoctopus
Getting the filesize of a file with the help of javascript
256005 by: Mark
256007 by: Richard Lynch
Re: Streaming download to IE doesn't work
256006 by: Steve
Re: uploading really big files
256008 by: Richard Lynch
256013 by: Alexander Jaeger
256017 by: Richard Lynch
Re: Cant set info in DB...HELP
256009 by: Richard Lynch
256020 by: Stut
Re: linking to an image with document_root
256010 by: Richard Lynch
256011 by: Richard Lynch
Re: $_GET strings seperation
256012 by: Navid Yar
When and when not to use ' and "
256014 by: Brian Seymour
256015 by: Daniel Brown
256016 by: Richard Lynch
I cannot figure out why this is not working?
256018 by: Brad Sumrall
256019 by: Tijnema
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 ---
I've had the same weird problem before, and eventually I discovered that the
error_reporting was set on the script level (eg in the PHP page) using the
function error_reporting. The thing is any setting in your php pages would
overwrite the php.ini setting (as far as I know).
--
itoctopus - http://www.itoctopus.com
"Clark Alexander" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> We have the following php.ini settings:
> error_reporting = E_ALL
> display_errors = Off
> display_startup_errors = Off
> log_errors = On
> log_errors_max_len = 1024
> ignore_repeated_errors = Off
> ignore_repeated_source = Off
> report_memleaks = On
> track_errors = Off
>
> on a SuSE 10.1 server and the errors are being logged to
> /var/log/apache2/error_log
> (although I can't seem to find a setting that is making that happen.)
>
> parse errors ARE being logged to this file and that would be extremely
> useful information for students to be able to have when trying to find
> problems in their scripts. I can't just make that file readable to them.
>
> So, I had students create a "logs" directory within their file area and
> set
> the permissions so that the server can to it. I have them adding the
> following to the script(s) that they wish to troubleshoot:
>
> ini_set("log_errors", "On");
> ini_set("error_reporting", E_ALL);
> ini_set("error_log", "logs/error_log");
>
>
> Parse errors are not being written to their personal log file, though. Why
> not?? About the only going in there are NOTICE level entries.
>
> Thanks.
>
> Clark W. Alexander
--- End Message ---
--- Begin Message ---
Hey,
I`m currently making a script and i`m having the intention of getting it to
work on as much hosts as possible.
The big problem with this is that some host (mostly free hosts) turn off
alot of vital functions that i need to get for
example the filesize of a remote file (or anything remote). Now i had the
idea to use some javascript ajax
requests to a host that does support that stuff so that it`s still availible
on alot hosts.. even if they have it turned off.
Now i`m just wondering how you guys would go arround a problem like this and
if you think the above is a good idea..?
btw.. i have the remote filesize stuff with the help of javascript and ajax
working so it`s not a impossible idea.. it`s probably just a little harder
when you need to get remoe (xml) files with net security update.. or even
the remote creation of thumbnails.
Thanx in favor,
Mark.
--- End Message ---
--- Begin Message ---
On Sat, June 2, 2007 9:42 am, Mark wrote:
> I`m currently making a script and i`m having the intention of getting
> it to
> work on as much hosts as possible.
> The big problem with this is that some host (mostly free hosts) turn
> off
> alot of vital functions that i need to get for
> example the filesize of a remote file (or anything remote). Now i had
> the
> idea to use some javascript ajax
> requests to a host that does support that stuff so that it`s still
> availible
> on alot hosts.. even if they have it turned off.
>
> Now i`m just wondering how you guys would go arround a problem like
> this and
> if you think the above is a good idea..?
> btw.. i have the remote filesize stuff with the help of javascript and
> ajax
> working so it`s not a impossible idea.. it`s probably just a little
> harder
> when you need to get remoe (xml) files with net security update.. or
> even
> the remote creation of thumbnails.
You could, perhaps, write various "fallback" functions to try to find
the filesize...
See if filesize(REMOTE) works.
See if curl is installed, and do a HEAD request for HTTP
If it's FTP, see if PHP has ftp functions.
You might want to use JS as a last resort, as you can't guarentee that
it will be enabled on the browser, nor that the various security
resrictions won't trip you up.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
That's why you comment your code. Take the extra time and put a bit of
effort into explaining yourself. Add in a paragraph explaining what's going
on, link to whatever solution you found on the web (who knows it might still
exist), and just outright bloat it with comments. You might find it annoying
now, but I can't tell you how many times I've thanked myself for doing stuff
like this when I've revisited old code.
You don't need to comment every line, but put a nice hearty paragraph at the
beginning of the confusing part and things should be nice and clear to
anyone who has to maintain it.
"Daniel Kasak" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Wed, 2007-05-30 at 13:40 -0500, Richard Lynch wrote:
> ..snip...
>> If I returned to this 2 years later ( or
> God forbid, someone else had to look at it ), they wouldn't have a clue
> what it was doing, or why.
> ..snip ..
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: [EMAIL PROTECTED]
> website: http://www.nusconsulting.com.au
--- End Message ---
--- Begin Message ---
On Sat, June 2, 2007 8:38 am, Alexander Jaeger wrote:
> - Give them FTP or SCP or something that is more stable and will
> re-try.
>
> -> *SCP* (http://en.wikipedia.org/wiki/Secure_copy)
> SCP ?!? an shell account for an unkown person on a server?
> NO DONT DO THAT!!!
> the only way to secure scp running normal envirements is to
> set
> a chroot, and that is way to much effort for a system > 5 users.
> (http://sublimation.org/scponly/wiki/index.php/Main_Page)
> the least thing you would have to worry about is that your
> server is becoming a spam nest.
Depends who is doing the uploading...
One also could imagine a write-only account, either in FTP or SCP setup.
I know I've seen this in FTP, and I don't see any reason SCP couldn't.
> -> *Flash *:
> There a lot of Tutorials out there, try google or sourceforge.
Leaves all your non-Flash users out in the cold, which to me is a
non-starter, but might be fine for the OP
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
Depends who is doing the uploading...
One also could imagine a write-only account, either in FTP or SCP setup.
I know I've seen this in FTP, and I don't see any reason SCP couldn't.
the reason why scp is different is it needs an system account with a
valid shell.
FTP does simply not (but it can :).
I think nobody except the root user should have shell access to a server,
only for security reasons.
-> *Flash *:
There a lot of Tutorials out there, try google or sourceforge.
Leaves all your non-Flash users out in the cold, which to me is a
non-starter, but might be fine for the OP
There I totaly agree with you! But I require my user to have flash, same
as i require them to have an graphical browser.
I can imagine where the internet would be with still browsing with lynx,
but i guess that is a decision every developer has to face.
I guess the gap is between introducing people how to handle a ftp or scp
transfer and installing flash.
I would go with the second choice.
Nevertheless, i see your point.
Thanks,
Alex
--- End Message ---
--- Begin Message ---
On Sat, June 2, 2007 3:01 pm, Alexander Jaeger wrote:
>> Depends who is doing the uploading...
>>
>> One also could imagine a write-only account, either in FTP or SCP
>> setup.
>>
>> I know I've seen this in FTP, and I don't see any reason SCP
>> couldn't.
>>
>>
> the reason why scp is different is it needs an system account with a
> valid shell.
> FTP does simply not (but it can :).
>
> I think nobody except the root user should have shell access to a
> server,
> only for security reasons.
Veering off the original topic quite a bit here, but...
I personally would refuse to work with any webhost who didn't give me
a shell account.
cron jobs, symlinks, large-scale file operations, and other
innumerable minor reasons make non-ssh web development a royal PITA
for me, personally.
So root-only shell is way too restrictive, imho.
>>> -> *Flash *:
>>> There a lot of Tutorials out there, try google or
>>> sourceforge.
>>>
>>
>> Leaves all your non-Flash users out in the cold, which to me is a
>> non-starter, but might be fine for the OP
>>
>>
> There I totaly agree with you! But I require my user to have flash,
> same
> as i require them to have an graphical browser.
>
> I can imagine where the internet would be with still browsing with
> lynx,
> but i guess that is a decision every developer has to face.
Ummmmm.
I tend to use Linux as my desktop, and gave up on Flash long ago.
Once I stopped installing it on Windows, I had a MUCH better online
experience, actually.
Websites are faster, no annoying random noises and fewer distracting
"popups" and the CPU and RAM usage finally is reasonable.
So I can't listen to bands on myspace. big deal.
> I guess the gap is between introducing people how to handle a ftp or
> scp
> transfer and installing flash.
The gap is between a tiny percentage of users who CANNOT install
flash, period.
I don't know of any OS that doesn't have a large assortment of FTP
clients available.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Fri, June 1, 2007 10:52 pm, kvigor wrote:
> I'm using phpMyAdmin and I can't get any of my form data into the
> database.
> It returns message: "MySQL returned an empty result set" w/in
> phpMyAdmin
> GUI.
That might be normal...
If you are doing an INSERT, you won't have a result set returned.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
Please include the list on all replies.
K.Hayes wrote:
I don't know if I'm escaping the 'vars correctly'. If I'm wrong can you
give me an example?
<snip>
$sql_query = "INSERT INTO contestants (conName, conAddress, conCity,
conState, conZip, conPhone, schName, schAddress, schCity, schState, schZip,
strName, strCity, strState) VALUES('$regName', '$regAddress', '$regCity',
'$regState', '$regZip', '$regPhone', '$sclName', '$sclName', '$sclCity',
'sclState', '$sclZip', '$stoName', '$stoCity', '$stoState')";
$insert_query = mysqli_real_escape_string($connection, $sql_query);
mysqli_query($connection,$insert_query); ?>
No, this is not the right way. I suggest you read the manual page on
mysqli_real_escape_string (http://php.net/mysqli_real_escape_string).
You need to run it on every variable you are using *in* the SQL query,
not on the SQL query itself.
Google for a php mysqli tutorial - all this stuff is very basic and
should be covered by most tutorials you'll find.
-Stut
--- End Message ---
--- Begin Message ---
On Fri, June 1, 2007 6:33 pm, chris smith wrote:
> On 6/2/07, Richard Lynch <[EMAIL PROTECTED]> wrote:
>> On Fri, June 1, 2007 3:16 am, blueboy wrote:
>> > May be a stupid question but can I link to images with doscument
>> root
>> >
>> > $img_url= $_SERVER['DOCUMENT_ROOT'].'/images/holder.gif';
>> >
>> > echo "<img src=\"$img_url\" width=\"250\" height=\"163\"/>";
>> >
>> > I am certain the path is correct,
>> >
>> > If not what are my alternatives?
>>
>> You could try if faster than you'll get an answer here, but, yes,
>> you
>> could do that.
>>
>> You may even want to set up a variable called $IMAGE_ROOT and set it
>> to $_SERVER['DOCUMENT_ROOT'] in a config/include file, so that if
>> you
>> ever want to move all your images somewhere else, you only change
>> one
>> line of code.
>
> How's that going to help when the OP is using a *file path* as an
> image source ?
Because if he tries it, he'll find out it wont' work.
And if he has it only ONE place to fix, then that's better than having
it all over his site, once he finds out that DOCUMENT_ROOT is wrong,
but something like HTTP_HOST is right.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
On Fri, June 1, 2007 8:37 pm, Tom Rogers wrote:
> Friday, June 1, 2007, 6:16:34 PM, you wrote:
> b> May be a stupid question but can I link to images with doscument
> root
>
> b> $img_url= $_SERVER['DOCUMENT_ROOT'].'/images/holder.gif';
>
> b> echo "<img src=\"$img_url\" width=\"250\" height=\"163\"/>";
>
> b> I am certain the path is correct,
>
> b> If not what are my alternatives?
>
>
> b> R.
>
>
> You don't need anything other than the first slash and it will be from
> the root of the web site. So all you need is:
> $url = '/images/holder.gif';
>
> and it will come from http://whatever.com/images/holder.gif
That actually relies on the browser to fill in the domain, and it's a
Documented Feature so that's fine...
But if you have dreams of scaling up to zillions of users, setting
this up "right" so that you can flip all your images to separate boxes
(or dcn or akami-like or...) is probably a Good Idea.
It will only take a few minutes' work, and some discipline on an
ongoing basis, but it's not "hard" by any means.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
Hey Jarred,
Sorry I couldn't get to you earlier. Thanks again for all the help.
And yes, I live maybe about 15-20 min from the new stadium.
Take care...
Navid
On 5/27/07, Jared Farrish <[EMAIL PROTECTED]> wrote:
On May 26, 5:39 pm, [EMAIL PROTECTED] ("Navid Yar") wrote:
> Thanks so much Jarred. It helps me learn more when there's an
> explaination on how the code works. I'll play around with it, change
> it a bit and give that a try. Take care...
> P.S. -- I'm in Arlington, TX
I work with a guy from Arlington. Live near the new stadium?
Incidentally, ponder this:
<code>
function shortGetNewQueryString($arr,$merge) {
return array_merge($arr,$merge);
}
echo('<pre>');
// Let's do one new cID, new GET key/value
$query = Array('cID'=>42,'freudian'=>'slip');
$go = shortGetNewQueryString($_GET,$query);
print_r($go);
// Let's do one new cID, new GET key/value
$query = Array('cID'=>9-002,'footloose'=>'fancy free');
$go = shortGetNewQueryString($go,$query);
print_r($go);
// Let's do one new cID, new GET key/value
$query = Array('cID'=>493,'fugged'=>'dhaboutit');
$go = shortGetNewQueryString($go,$query);
print_r($go);
// Let's do one new cID, new GET key/value
$query = Array('cID'=>A4,'longlongtimeago'=>'in a galaxy far, far
away');
$go = shortGetNewQueryString($go,$query);
print_r($go);
echo('</pre>');
</code>
By the way, when you run that code, pay special attention to the
second test. Very very tricky entry anomaly... Wuffuh!
Pay attention to how short that new code is
( shortGetNewQueryString() ). It's certainly arguable you don't even
need to wrap it in a function. Consider:
<code>
// This is the best version, I believe: brief and simple.
function mediumGetNewQueryString ($arr,$add) {
foreach ($add as $key=>$val) {
$arr[$key] = $val;
}
return $arr;
}
echo('<pre>');
print_r( mediumGetNewQueryString($_GET,$query) );
echo('<pre>');
</code>
And then, of course, a number of shortcuts may be used to obscurify and
mystify your code for later puzzling, head-scratchedness.
This is, of course, exactly comparable to all the other example
methods:
<code>
// Hard to read, ie, needless brevity
function annoyingGetNewQueryString ($arr,$add) {
foreach ($add as $key=>$val) $arr[$key] = $val;
return $arr;
}
echo('<pre>');
print_r( annoyingGetNewQueryString($_GET, $query) );
echo('</pre>');
</code>
Caution: Using array_merge, though, will overwrite keynames, but NOT
numerical items. You can't auto-map over numerical keys with array_merge(),
apparently.
Consider:
<code>
$array = Array(
[0] => 'moe'
[1] => 'curly',
[2] => 'larry'
);
// Is equivalent to ~
$array = Array();
$array[] 'moe';
$array[] 'curly';
$array[] 'larry';
// Is equivalent to ~
$array = Array();
array_push($array, 'moe');
array_push($array, 'curly');
array_push($array, 'larry');
</code>
When you add a numerical array in php, it is added to the stack as a new
item, or push. Essentially,
$array = Array('item1')
$array[] = 'item2' eq ~ "Array('item1','item2')"
And then when you call on the array, it
{ get Array as Numerically-Indexed Set } eq ~ split($array,$token=',') eq ~
({ [0] => 'item' , [1] = 'item2' })
So an array on a stack can be represeted in memory as a comma-delimited
numerically-indexed list, eg, 'item','item2'
--
Jared Farrish
Intermediate Web Developer
Denton, Tx
Abraham Maslow: "If the only tool you have is a hammer, you tend to see
every problem as a nail." $$
--- End Message ---
--- Begin Message ---
I noticed today when I was using mysql_fetch_array something weird happened.
Database:
| id |
1
Code:
$colVal = "id";
$foo=mysql_fetch_array($someresult, MYSQL_ASSOC);
Now all I wanted to do was get the value of 1 into the variable $bar. Please
assume $someresult was the direct product of mysql_query("select * from
thistable");.
$bar = $foo['$colVal']; // didn't work
$bar = $foo['{$colVal}']; // didn't work
$bar = $foo[$colVal]; // worked
$bar = $foo['id']; // obviously worked
What I don't understand is why the first or second option didn't work.
Can anybody shed some light on this?
Brian Seymour
AeroCoreProductions
http://www.aerocore.net/
--- End Message ---
--- Begin Message ---
On 6/2/07, Brian Seymour <[EMAIL PROTECTED]> wrote:
I noticed today when I was using mysql_fetch_array something weird happened.
Database:
| id |
1
Code:
$colVal = "id";
$foo=mysql_fetch_array($someresult, MYSQL_ASSOC);
Now all I wanted to do was get the value of 1 into the variable $bar. Please
assume $someresult was the direct product of mysql_query("select * from
thistable");.
$bar = $foo['$colVal']; // didn't work
$bar = $foo['{$colVal}']; // didn't work
$bar = $foo[$colVal]; // worked
$bar = $foo['id']; // obviously worked
What I don't understand is why the first or second option didn't work.
Can anybody shed some light on this?
Brian Seymour
AeroCoreProductions
http://www.aerocore.net/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Brian,
Single quotes give a literal value of the data passed, while
double quotes give the translated value. For example, if you have the
following:
<?
$the = "end";
echo '$the';
echo " ";
echo "$the";
?>
.... you'll have the following output:
$the end
The same counts for escaped characters, such as the newline
character (\n). If you put it in single quotes, it's processed as a
literal value; the same newline inserted in double quotes is displayed
properly, as again, it's processed as a translated value.
So:
<?
$word = "this";
echo '$word\nworks';
echo "\n\n";
echo "$word\nworks";
?>
Shows:
$word\nworks
this
works
Hope that helps a bit. I'm in the middle of moving furniture into
my new house and can't get the bed upstairs, so I decided to take a
break and grab some "sanity" from the list. Talk about your
oxymorons....
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
--- End Message ---
--- Begin Message ---
On Sat, June 2, 2007 3:15 pm, Brian Seymour wrote:
> $bar = $foo['$colVal']; // didn't work
> $bar = $foo['{$colVal}']; // didn't work
> $bar = $foo[$colVal]; // worked
> $bar = $foo['id']; // obviously worked
>
> What I don't understand is why the first or second option didn't work.
>
> Can anybody shed some light on this?
' is actually easier to explain.
' has only TWO special characters you can embed in it: ' and \
$foo = 'That\'s life!';
$bar = 'The backslash \\ should be escaped, because it\'s special';
You don't HAVE to escape \ with \\ if PHP won't get "confused" by
whatever else you have in your string, but it's a Good Idea, imho, to
just always escape it, so you understand what the string parser is
doing internally.
" is a bit more complex.
In addition to " and \ being special, exactly parallel to ' and \
inside '', you also have:
variables like $foo and 1-D arrays like $foo[id]
special control characters like \n \t \r
any char you want with octal
{ and } for some versions (ugh) of PHP
There is also heredoc syntax, which is probably best for large chunks
of text, in general.
Full documentation is here:
http://us.php.net/manual/en/language.types.string.php
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
<?php
{
$to =
("[EMAIL PROTECTED],[EMAIL PROTECTED]");
$subject = "online guestbook register";
$email = $_POST['email'] . "\n";
$headers = "Reply-To: " . $_POST['email'] . "\n";
$body = "Visitor Infomation: " . "\n" .
"Name: " . $_POST['name2'] . "\n" .
"Email: " . $_POST['email2'] . "\n";
}
else
{
mail($to,$subject,$body,$headers);
$to = ("$email2");
$subject = ("Thank you");
$email = $_POST['email'] . "\n";
$headers = "Reply-To: " . $_POST['email'] . "\n";
$body = "Thank you for signing our Guest Book and visiting our website. Feel
free to search our extensive property database, as this is the most current
up to date information in the Real Estate Market today. You will see the
latest listings the same time the Realtors do. Check out
http://www.Floridaonlineinvestments.com" . "\n" .
mail($to,$subject,$body,$headers);
}
?>
--- End Message ---
--- Begin Message ---
On 6/2/07, Brad Sumrall <[EMAIL PROTECTED]> wrote:
<?php
{
$to =
("[EMAIL PROTECTED],[EMAIL PROTECTED]");
$subject = "online guestbook register";
$email = $_POST['email'] . "\n";
$headers = "Reply-To: " . $_POST['email'] . "\n";
$body = "Visitor Infomation: " . "\n" .
"Name: " . $_POST['name2'] . "\n" .
"Email: " . $_POST['email2'] . "\n";
}
else
{
mail($to,$subject,$body,$headers);
$to = ("$email2");
Where did you get $email2??
$subject = ("Thank you");
$email = $_POST['email'] . "\n";
Why do you need $email?
$headers = "Reply-To: " . $_POST['email'] . "\n";
$body = "Thank you for signing our Guest Book and visiting our website. Feel
free to search our extensive property database, as this is the most current
up to date information in the Real Estate Market today. You will see the
latest listings the same time the Realtors do. Check out
http://www.Floridaonlineinvestments.com" . "\n" .
mail($to,$subject,$body,$headers);
}
?>
Did you get any error?
And what does mail return? true or false?
Tijnema
--- End Message ---