Re: [PHP] Howto detect the hostname of the server?

2011-11-25 Thread Mark Kelly
Hi.

On Saturday 26 Nov 2011 at 00:14 Andreas wrote:

 how could I identify the server the script runs on?

[snip]
 
 I looked into phpinfo() but haven't found anything helpful, yet.
 Have I overlooked something or is there another way to identify the server?

Wouldn't the server IP address in $_SERVER['SERVER_ADDR'] or the hostname in 
$_SERVER['SERVER_NAME'] do the trick? That's what I use. The second one is 
handy for differentiating between sites when using Apache name-based virtual 
hosts on the same IP.

Full list here:

http://uk.php.net/manual/en/reserved.variables.server.php

Cheers,

Mark

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



Re: [PHP] Re: Secure data management

2011-10-05 Thread Mark Kelly
Hi.

On Wednesday 05 Oct 2011 at 00:04 Mark Kelly wrote:

 I'd be interested in any ideas folk have about these issues, or any others
 they can envisage with this proposal.

Thank you all for joining in here - it's been a fascinating read so far.

Mark

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



Re: [PHP] Re: Secure data management

2011-10-04 Thread Mark Kelly
Hi.

On Tuesday 04 Oct 2011 at 21:39 Stuart Dallas wrote:

 http://stut.net/2011/09/15/mysql-real-escape-string-is-not-enough/

Thanks. I followed this link through and read the full message (having missed 
it the first time round), and while I find the idea of using base64 to 
sanitise text interesting I can also forsee a few difficulties:

It would prevent anyone from accessing the database directly and getting 
meaningful results unless the en/decode is in triggers, or maybe stored 
procedures. No more one-off command-line queries.

How would you search an encoded column for matching text?

I'd be interested in any ideas folk have about these issues, or any others 
they can envisage with this proposal.

Cheers,

Mark

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



Re: [PHP] Re: dynamic copyright in page footer?

2011-04-30 Thread Mark Kelly
On Saturday 30 Apr 2011 at 14:28 Nathan Rixham wrote:

 echo implode(,, range(2011,date(Y)));

What an elegant solution! Thank you.

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



[PHP] Regex for extracting quoted strings

2011-03-05 Thread Mark Kelly
Hi.

I'm hoping someone can help me extract text between double quotes from a 
string.

$regex = 'some magic';
$r = preg_match($regex, $sentence, $phrases);

So, if 

$sentence = 'Dave said This is it. Nope, that is the wrong colour she 
replied.';

I want $phrases to contain 'This is it' and 'Nope, that is the wrong colour'.

Can anyone help?

Cheers,

Mark

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



Re: [PHP] Re: Regex for extracting quoted strings

2011-03-05 Thread Mark Kelly
Hi.

Thanks for all the replies.

On Saturday 05 Mar 2011 at 22:11 Simon J Welsh wrote:

 On 6/03/2011, at 11:08 AM, Shawn McKenzie wrote:
  $regex = '/([^]+)/';

Shawn, this regex gets me two copies of each string - one with and one without 
the double quotes - as did the one Nathan posted earlier.
 
 Also, you'll want preg_match_all rather than preg_match.

Yeah, I realised that quite early on in my messing about.

What I have ended up with is:

$regex = '/.*?/';
$found = preg_match_all($regex, $sentence, $phrases);

This still leaves the quotes in the phrases, but at least I only get one copy 
of each phrase. I'm just trimming the quotes afterwards.

Thanks for all the advice.

Mark

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



Re: [PHP] Custom function

2011-02-16 Thread Mark Kelly
Hi.

On Wednesday 16 Feb 2011 at 00:49 Simon J Welsh wrote:

 As $z is converted to a boolean and exists, that works just the same way as
  !empty(). ---

First I'd like to apologise for handing out bad advice, and second, to thank 
Simon and Andre for pointing out my mistake. I'll go back to keeping my mouth 
shut in future :)

Cheers guys,

Mark

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



Re: [PHP] Custom function

2011-02-15 Thread Mark Kelly
Hi.

On Tuesday 15 Feb 2011 at 23:41 Andre Polykanine wrote:

 Give it a default (possible empty) value:

 function MyFunction($x, $y, $z=) {
 // function goes here
 if (!empty($z)) {
 // The optional parameter is given
 }
 }

Using an empty string and the empty() function in this way can lead to subtle 
and hard to find bugs - for example if $z = 0, the code will not be executed. 
Note the list of things that are considered empty:

http://uk.php.net/manual/en/function.empty.php

Instead, consider setting the default value for $z to boolean false:

function MyFunction ($x, $y, $z = FALSE) {
  if ($z) {
// do stuff with $z
  }
}

In this way almost any value in $z will trigger the conditional code, 
including 0 or an empty string. The exceptions are FALSE and NULL. If you 
explicitly need to react to a NULL value, use is_null() to detect it. 

Cheers,

Mark

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



Re: [PHP] NetBeans Question

2010-05-30 Thread Mark Kelly
Hi Tedd.

On Sunday 30 May 2010 at 19:01 tedd wrote:
 I wanted to ask my questions on the NetBeans forums, but I am having
 trouble logging in. They seem to have a problem with my given ID,
 password, and email address and I haven't the time to straighten it
 all out -- I just want answers -- so I turned to this list.

Just in case you didn't spot it, there is a mailing list specifically for PHP 
development using netbeans that I have found very useful. You can sign up 
here:

http://netbeans.org/community/lists/top.html#technologies

Cheers,

Mark

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



Re: [PHP] NetBeans Question

2010-05-30 Thread Mark Kelly
Hi Brandon.

You sent your reply directly to me, instead of to the mailing list. 

Also I don't agree - netbeans is an excellent IDE and to call it a text editor 
is not doing it justice at all.

Cheers,

Mark

On Monday 31 May 2010 at 02:03 you wrote:

 Dreamweaver is better if you want a real IDE. If you want a regular text
 editor netbeans is the way to go.
 
 On Sun, May 30, 2010 at 8:15 PM, Mark Kelly p...@wastedtimes.net wrote:
  Hi Tedd.
 
  On Sunday 30 May 2010 at 19:01 tedd wrote:
   I wanted to ask my questions on the NetBeans forums, but I am having
   trouble logging in. They seem to have a problem with my given ID,
   password, and email address and I haven't the time to straighten it
   all out -- I just want answers -- so I turned to this list.
 
  Just in case you didn't spot it, there is a mailing list specifically for
  PHP
  development using netbeans that I have found very useful. You can sign up
  here:
 
  http://netbeans.org/community/lists/top.html#technologies
 
  Cheers,
 
  Mark
 
  --
  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] NetBeans Question

2010-05-30 Thread Mark Kelly
Hi.

On Monday 31 May 2010 at 02:50 Ashley Sheridan wrote:
 Yeah, like I mentioned earlier, Dreamweaver is known for having issues
 with include files, can be slow when working on large projects with lots
 of files, and is only available for Mac and Windows, which limits it
 somewhat.

Indeed. I can't stand the thing myself - I was just being polite :)

I use netbeans on Linux and Windows, so its cross-platform nature is quite 
important to me. I also appreciate the Subversion integration, which is very 
nicely done.

Tedd: I'm no expert, but I'll chime in if I have any answers for you.

Cheers,

Mark

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



Re: [PHP] Need login suggestions

2010-05-02 Thread Mark Kelly
Hi.

On Monday 03 May 2010 at 03:49 Ashley M. Kirchner wrote:

[snip]

So what if a student registers on the wrong side of the wall?  Nothing
 happens

[snip]

  Kids would be registering for a
  photo contest, parents will be registering for something completely
  different.

You might try changing the interface to reflect the above - instead of 
dividing the users into students and parents, give them two nice big buttons 
to click Register for Photo Contest and Register for This Other Thing.

As far as managing the differences in code, when they log in stick $userType 
(from the database I guess) in the session and check it in every secured page 
to control who sees what. I've done several variations on this particular 
theme; it's simple to manage, especially if you have a page initialisation 
function/method you can put the $userType check into. 

HTH,

Mark

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



Re: [PHP] Recognizing double clicks

2009-11-22 Thread Mark Kelly
Hi.

On Sunday 22 Nov 2009 at 05:34 Skip Evans wrote:
 It just dawned on me the button may be disabled right when
 it's clicked to prevent a double submit?
 
 Is that doable?

To mark a button as disabled after it has been clicked to prevent it being 
clicked twice just add some simple code in the button (all on one line in case 
it wraps):

onClick=this.disabled=true; this.value='Processing'; this.form.submit();

However I would also do something server side (a unique ID for every form 
served works well) to handle browsers that don't have javascript turned on. 
Never rely on (or trust) code running on the client.

Cheers,

Mark


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



Re: [PHP] putting variables in a variable

2009-07-21 Thread Mark Kelly
Ross,

If I understand correctly what you want to do, you're almost there...

You need:

$myimage1 = image1.jpg;
$myimage2 = image2.jpg;
$myimage3 = image3.jpg;

$body .=
table
  tr
tdimg src=\$myimage1\/td
  /tr
  tr
tdimg src=\$myimage2\/td
  /tr
  tr
tdimg src=\$myimage3\/td
  /tr
/table
;

Cheers,

Mark


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



Re: [PHP] Re: preg_replace problem

2009-06-14 Thread Mark Kelly
Hi.

On Saturday 13 June 2009, Al wrote:
 I may not have been very clear. Feed it just  test   with the
 quotes. You should get back, test the same as you gave it.   Instead,
 I get back quote;testquote;

Like Shawn, I have tried your code in isolation and only get the expected 
results. I looped it over a few test values:

?php
$valueList = array('','test','testtest','testamp;test');
echo pre\n\n;
foreach ($valueList as $value) {
echo Before: $value\n;
$value=preg_replace(%(?!amp;)%i, amp;, $value);
echo After: $value\n\n;
}
echo '/pre';
?

outputs (ignoring pre as that was just to remove the br / for easy 
reading):

Before: 
After: 

Before: test
After: test

Before: testtest
After: testamp;test

Before: testamp;test
After: testamp;test

The only conclusion is that something else in your code is converting the 
quotes. Have a look around.

HTH

Mark

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



Re: [PHP] Fractions

2009-05-24 Thread Mark Kelly
Hi.

On Sunday 24 May 2009, Ron Piggott wrote:
 Is there a way to remove the trailing '0'?

$width = number_format($width,2);

 Also is there a way to have the original fraction display (1/4), as well
 as have provision for 1/8 and 3/8 and 1/2, etc. display?

On this one I suspect you'd have to write your own function, but maybe 
someone else knows better.

HTH

Mark

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



Re: [PHP] what to use instead of foreach

2009-04-14 Thread Mark Kelly
Hi Phil.

On Monday 13 April 2009, PJ wrote:
 Thanks for the suggestion, Mark. I've already experimented with count;
 you're close, but there is still a small glitch and that's in count();
 foreach doesn't give a damn about count so you can't use that - it is
 reset once inside the foreach loop.

Look again at the code - the count() is not inside the foreach, so it is 
not reset, simply stored in $lastIndex for comparison.

If your array is associative then simply use another variable to find the 
last value in the array - the code doesn't need to change much.

Try actually running the code below - it does work, as does the previous 
version I posted if the array is not associative. 

I'd prefer it if in future you didn't tell me that my code didn't work 
without actually trying it - I tested that snippet before posting it, as I 
did with the following.

HTH

Mark

?php
// Non-associative array (the code I posted previously).
$a = array('1','2','3');

$lastIndex = count($a) - 1;
$outputString = '';
foreach ($a as $index = $value) {
if ($index != $lastIndex) {
$outputString .= $value, ;
} else {
$outputString = rtrim($outputString,', '); // Strip last comma.
$outputString .=   $valuebr /;
}
}
echo $outputString;

// Associative array (changed only very slightly).
$a = array('martha' = '1','jock' = '2','dave' = '3');

$lastIndex = count($a);
$counter = 0;
$outputString = '';
foreach ($a as $index = $value) {
$counter++;
if ($counter != $lastIndex) {
$outputString .= $value, ;
} else {
$outputString = rtrim($outputString,', '); // Strip last comma.
$outputString .=   $valuebr /;
}
}
echo $outputString;
?

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



Re: [PHP] what to use instead of foreach

2009-04-13 Thread Mark Kelly
Hi.

On Sunday 12 April 2009, PJ wrote:
 foreach does not allow for different formatting for output...

[snip]

 But how do you get result1, result2  result3 // with br at end ?

$lastIndex = count($a) - 1; // Adjust for zero-indexing.
$outputString = '';
foreach ($a as $index = $value) {
if ($index != $lastIndex) {
$outputString .= $value, ;
} else {
$outputString = rtrim($outputString,', '); // Strip last comma.
$outputString .=   $valuebr /;
}
}
echo $outputString;

Like that? If your array is associative you can drop the $lastIndex calc 
and adjust the loop to update a counter instead. 

HTH

Mark

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



Re: [PHP] $_GET

2009-04-11 Thread Mark Kelly
Hi.

On Sunday 12 April 2009, Ron Piggott wrote:
 At the very start of my index.php I have the following lines of code:

 foreach($_GET as $key = $val) {
 $$key = $_GET[$val];
 echo $_GET[$val] . br /;
 }

Try:

echo $_GET[$key] . br /;

HTH

Mark

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



Re: [PHP] Search thoughts

2008-07-19 Thread Mark Kelly
Hi.

Just noticed I replied direct rather than to the list last time, sorry 
about that.

On Saturday 19 July 2008, Richard Heyes wrote:
 How much traffic do you have and what's your hardware? Are your queries
 cached and subsequently repeated? Do you pre cache common queries?

I've done this kind of search twice, but both were for internal web apps so 
I can't link you to them. In both cases I return only items IDs and limit 
it to 10 results, with the subsequent queries being done only if the 
previous ones didn't return enough results to fill the page. Both of these 
speed it up a lot, obviously. One of them has a possible max of 6 
different ways to examine the data tables, and still return a full results 
page in under half a second.

Nothing is pre-cached, and I'm really not sure about the hardware, sorry, 
that's the IT guy's problem. I don't imagine it's anything spectacular 
though.

The apps get quite heavy use but I'm with Tedd on the results issue, we 
only see maybe 10% of the users going to page 2, but these are internal 
users searching company data, so the pattern may not be typical.

Hope you find something you're happy with,

Mark

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



Re: [PHP] looping through a $_POST variable

2007-12-30 Thread Mark Kelly
Hi.

On Monday 31 December 2007 00:34, Richard Kurth wrote:
 When I do a var_dump($_POST['emails']); it has all the emails in it
 string(65) [EMAIL PROTECTED] [EMAIL PROTECTED]
 [EMAIL PROTECTED]

Then this simple regex should do you; just use it instead of explode:

$AddressList = preg_split('/\s+/', $_POST['emails']);

 I will validate the emails after I get the loop to work

An better idea might be to do that INSIDE the loop (the following assumes 
your $memberid is a number, adjust to suit if this is not the case):

foreach ($AddressList as $emailaddress) {
// Escape the data before letting it near the db
$SAFE_emailaddress = mysql_real_escape_string($emailaddress);
$SAFE_memberid = intval($_POST[members_id]);
// Build the query
$sql = SELECT id 
FROM contact
WHERE emailaddress = '$SAFE_emailaddress' 
AND members_id = '$SAFE_memberid';
// etc. etc.
}

 safe_query  is a function that I call that does query stuff

That is a *terrible* name for that function, as it does nothing at all to 
make the query safe. You might consider renaming it to run_query or 
something. Remember, other people may have to make sense of your code one 
day.

Hope this helps,

Mark

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



Re: [PHP] From TXT to a mySQL db

2007-10-18 Thread Mark Kelly
Hi.

On Thursday 18 October 2007 19:29, Marcelo Wolfgang wrote:
 Hi all,

 I need some helps/tips to know if a transition from a txt file to a sql
 database is viable to do.

[snipped data and table descriptions]

 Is there a quick and simple way to convert the row string into a INSERT
 query ?

Once you have opened the file for reading, read one line at a time and use 
explode() to get the individual fields out of each line into an array. By 
the looks of the data you need to tell explode to use ^ as field 
delimiter.

Then contruct an SQL INSERT query and execute it to put the array values 
into the correct table, depending on whether the first value is 10 or 20. 
Make sure you escape each field value to make it safe for whatever 
database you are using.

Repeat for each line until there aren't any more. 

I've done similar things to this more than once and as long as the data 
isn't too weird you should have no problems.

 Should I try some manipulation first with the TXT file ?

I wouldn't imagine there would be any need for that, no. 

Hope this helps,

Mark

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



Re: [PHP] Thoughts about music library

2007-08-06 Thread Mark Kelly
Hi.

On Monday 06 August 2007 23:13, Børge Holen wrote:
 As mentioned earlier, I want to make stuff myself

When I did this I used Music Player Daemon (MPD - http://musicpd.org/) and 
wrote my own web interface in php. It offers a nice simple but powerful 
API, and is *very* low on resource usage (no seperate database). I used it 
running from an old 200Mhz SBC board in a Playstation 2 case. I thought it 
made for a nice flexible system as there are clients to control the daemon 
available for all manner of hardware. 

Cheers,

Mark

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



Re: [PHP] Pirate PHP books online?

2007-07-16 Thread Mark Kelly
Hi.

On Monday 16 July 2007 12:42, Dotan Cohen wrote:

 So, suckers, I'm with you now, and I'll start pirating again. 

This is a real shame (not to mention a foolish thing to post to a publicly 
archived mailing list). As a user of open source technology you are 
benefiting directly from the PHP developers choice of license, and relying 
on people respecting it. It is hypocritical to expect everyone to respect 
the PHP license and give you nice tech for free, then turn round and 
ignore a different license just because the authors haven't chosen to give 
away their work.

 Anyone know where I can pick up a copy of Ubuntu pirated?

You may have intended this as a joke, but recently there have been 
(unconfirmed from what I can tell) reports of Ubuntu torrent downloads 
with pre-installed trojans. Always get your stuff from the official sites.

http://www.funtechtalk.com/trojan-horse-loaded-version-of-ubuntu-704-spreading-over-torrent-sites/

(ugly URL may wrap)

Please reconsider your decision to selectively ignore copyright licenses. 

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



Re: [PHP] Re: php security books

2007-07-04 Thread Mark Kelly
Hi.

On Wednesday 04 July 2007 13:01, Andrew Hutchings wrote:

 Avoid the O'Reilly one as it is flawed.

In what way?

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



Re: [PHP] PHP not posting

2007-06-24 Thread Mark Kelly
On Sunday 24 June 2007 13:54, Pieter du Toit wrote:
 Hi

 I installed PHP5 on iis and i can see hello world and phpinfo.

 When i right click the webpage and view source, i can see the php code,
 and the form does not want to post the form details.

 Will appreciate any help.

I'm not really knowledgeable about IIS, but if you can see php code in the 
browser it usually means the web server hasn't been set up to execute php 
rather than just serving it. 

Check your config to make sure it knows to pass *.php requests through php5 
rather than just sending the page back directly. How you do this on IIS is 
beyond me I'm afraid.

HTH

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



Re: [PHP] php/ajax question

2006-12-30 Thread Mark Kelly
On Saturday 30 December 2006 18:56, tedd wrote:
 Why can't the php script redirect the browser when called via ajax ?

The browser will not be expecting a page back, and will ignore headers. 
Just some quick suggestion code, this isn't tested (except createRequest - 
I use that all the time)...

function createRequest() {
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject(Msxml2.XMLHTTP);
} catch (othermicrosoft) {
try {
request = new ActiveXObject(Microsoft.XMLHTTP);
} catch (failed) {
request = null;
}
}
}
if (request == null) alert(Error creating request object!);
   }

function sndReq(action) {
createRequest();
var url = a.php?action= + Volume + dummy= + new Date().getTime(); 
// random shit at the end is hack to get round browser response cacheing
request.open(GET,url);
request.onreadystatechange = updateReq;
request.send(null);
}

function updateReq() {
if (request.readyState == 4) {
var newLocation = request.responseText;
window.location = newLocation;
}
}

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



Re: [PHP] php/ajax question

2006-12-30 Thread Mark Kelly
On Saturday 30 December 2006 18:56, tedd wrote:
 Why can't the php script redirect the browser when called via ajax ?

The browser will not be expecting a page back, and will ignore headers. The 
response must be handled by a function you define.

For the sake of a quick demo, if your php accepts an action via GET and 
simply prints the location for the redirect, you can do it at the client 
end. 

// example code

function createRequest() {
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject(Msxml2.XMLHTTP);
} catch (othermicrosoft) {
try {
request = new ActiveXObject(Microsoft.XMLHTTP);
} catch (failed) {
request = null;
}
}
}
if (request == null) alert(Error creating request object!);
   }

function sndReq(action) {
createRequest();
var url = a.php?action= + action + dummy= + new Date().getTime(); 
// random stuff at the end is hack to get round browser response 
cacheing
request.open(GET,url);
request.onreadystatechange = updateReq;
request.send(null);
}

function updateReq() {
if (request.readyState == 4) {
var newLocation = request.responseText;
window.location = newLocation;
}
}

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



[PHP] Tidy HTML source?

2006-11-27 Thread Mark Kelly
Hi.

In the stuff I do almost all the HTML is generated with PHP as basically 
none of it is static (lots of tabular data, state-sensitive links, stuff 
like that).

Am I crazy to make an extra effort in my code to make the generated HTML 
pretty? By this I mean linebreaks, indentation etc. - stuff that is aimed 
at readability rather than correctness. This is obviously above and beyond 
simply making sure it validates. It's not a huge burden by any means, but 
it *is* extra effort.

What do you guys do?

Looking forward to your replies.

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



Re: [PHP] Tidy HTML source?

2006-11-27 Thread Mark Kelly
On Monday 27 November 2006 17:10, Mark Kelly wrote:

 Am I crazy to make an extra effort in my code to make the generated HTML
 pretty? 

Thanks everyone for your thoughts on this - I'm quite relieved that I'm not 
the only one who sits and tweaks so that the HTML is nice and readable.

It just struck me that trying to make my PHP spit out page source that 
looks like it was made lovingly by hand was perhaps the work of an 
obsessive.

Now I know that even if it is, I'm not alone :)

Cheers!

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



[PHP] Including Functions; one file or many?

2006-05-26 Thread Mark Kelly
Hi

I'm writing a set of db abstraction functions for an internal app which will 
give us a set of simple function calls for dealing with the db, like 

$result = db_AddEmployee($EmployeeData);
$EmployeeData = db_GetEmployee($EmployeeID);

etc.

There will be quite a few functions needed to deal with all the different 
ways the app touches the db, so my question is:

Am I better off putting all these functions into one big include file (which 
could get pretty big) or using a seperate 'include' file for each function?

I'm thinking about the tradeoff between simplifying code by only having a 
single include file (parsing a lot of functions that aren't used, but less 
disk access) and having several include files (no extra funcs but lots more 
disk access). 

I realise there probably isn't a 'correct' way to do this, I'm curious about 
which methods folk here use in situations like this.

TIA in advance for any advice,

Mark

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



Re: [PHP] Including Functions; one file or many?

2006-05-26 Thread Mark Kelly
 At 9:02 AM +0100 5/26/06, Mark Kelly wrote:
 TIA in advance for any advice,

And thanks in arrears to all who responded.

Since there appears to be no compelling reason to go either way, and we 
already have subdivided include files for functions (to a limited extent) 
I've decided to go with a different file for each kind of data; ie. 
db_employees.inc, db_contacts.inc, db_products.inc etc. so I can load the 
ones that are relevant to the current page, not all 2 squillion funcs.

This was TBH my preference anyway, I just wanted to make sure that more 
experienced heads than mine didn't know of any compelling reasons for 
another method.

Thanks again for all the replies.

Mark

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



Re: [PHP] Including Functions; one file or many?

2006-05-26 Thread Mark Kelly
On Friday 26 May 2006 14:56, Matt Carlson wrote:
 One note on include files.  Usually it's best practice to not name them
 .inc

 Name them .inc.php so that they cannot be opened by a webbrowser, thus
 giving more information to a potential attacker.

Is this still a concern when all include files are stored outside the 
webroot (and thus in theory not directly accessible) anyway?

 Just my $.02

And much appreciated it is too - I'd *far* rather have too much advice than 
not enough - especially where security is concerned.

Mark

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



Re: [PHP] Including Functions; one file or many?

2006-05-26 Thread Mark Kelly
On Friday 26 May 2006 16:41, Jochem Maas wrote:

 besides .inc.php seems to be/becoming a sort of defacto std (no need for
 filenaming jihad people ;-)

That's certainly worth considering (particularly as the project is still at 
the very early stages), thank you both for mentioning it. My experience has 
been that de facto standards are often the most resilient in the long run.

  And much appreciated it is too - I'd *far* rather have too much advice
  than not enough - especially where security is concerned.

 always look both ways when crossing the street. ;-)

See, if someone had said that to me 30 years ago I'd still have all three 
legs and a functioning ink sac :)

Cheers,

Mark

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



Re: [PHP] redirect using php

2006-04-05 Thread Mark Kelly
On Tuesday 04 April 2006 22:27, Brady Mitchell wrote:
  -Original Message-
  In JSP I have access to a function called sendRedirect() to
  send a user
  from one page to another, usually after some processing completed. Is
  there a similar function in PHP?

 Take a look at the header() function.
 http://php.net/header

 To redirect you can use:  header(Location: http://www.example.com/;);

You can also use something like: 

echo meta http-equiv=\Refresh\ content=\0;url=$from_page\;

depending on your needs.

Mark

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



Re: [PHP] redirect using php

2006-04-05 Thread Mark Kelly
On Wednesday 05 April 2006 13:55, Chris Shiflett wrote:
 Mark Kelly wrote:
  You can also use something like:
 
  echo meta http-equiv=\Refresh\ content=\0;url=$from_page\;

 There's no need to use a meta tag to mimic HTTP headers. PHP provides
 the header() function.

I have been using that method when I got part-way through some processing 
that produces output, and hit something that requires a redirect. As I 
understand it headers are no use to me here.

I'm very much a beginner, so if this is the wrong way to do this, I'd 
appreciate pointers. Thanks for the reply, either way.

Mark

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



Re: [PHP] redirect using php

2006-04-05 Thread Mark Kelly
On Wednesday 05 April 2006 14:33, Chris Shiflett wrote:
 Mark Kelly wrote:
You can also use something like:
   
echo meta http-equiv=\Refresh\ content=\0;url=$from_page\;
  
   There's no need to use a meta tag to mimic HTTP headers. PHP
   provides the header() function.
 
  I have been using that method when I got part-way through some
  processing that produces output, and hit something that requires a
  redirect. As I understand it headers are no use to me here.

 You're still using a Refresh header. The difference is that you're using
 a meta tag to mimic the header (e.g., http-equiv).

I understand that. I'm sorry, I am obviously not making myself clear...

The php manual page tells me that I can't use header() after any output has 
been sent, thus making it useless in my (obviously badly explained) case 
above.

What happens in my app is: the data processing is in several discrete 
sequential stages, each one echoing status to the user. When it hits 
something that requires additional pre-processing by a different page, I 
use the http-equiv redirect with a 3 second delay so the user can read the 
message telling them what is going on.

Am I correct that header() is no use for this, and is there a correct way 
to achieve what I describe? I'm a bit concerned that my ignorance may have 
led me to do this wrong - this is my first php app.

Also, thanks to all the folk suggesting javascript, but this is an internal 
app, and policy has javascript turned off on all browsers.

Thanks again,

Mark

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



Re: [PHP] Creating forms dynamically

2006-03-15 Thread Mark Kelly
On Tuesday 14 March 2006 20:21, Paul Goepfert wrote:

 If anyone has any ideas on how to create the form when the error messages
 are displayed without having to code it a second time please let me
 know.

I use an assoc. array that matches the form inputs, for example:

$FormDisplayData = array(
  'username' = '',
  'email' = '',
  'city' = ''
  );

and a flag variable that is set when an error is encountered.

Then in the form:

echo Enter your username: input type=\text\ 
 name=\username\ 
 value=\{$FormDisplayData['name']}\;
if ($FoundErrors) { echo Invalid username!;}

and so on.

This way, first time through the form the array is empty and the error flag 
is false - user gets a form ready to be filled in. If you get a processing 
error, populate the $FormDisplayData array with the values from $_POST, and 
the user gets his input back to correct, and a message telling him why. 
Neat, huh?

There are undoubtedly many other ways to do this, but this is the only one I 
know :)

Hope this helps.

Mark

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