Re: [PHP] anyone interested in PHP? Call for moderator

2009-09-15 Thread Yeti
It is good to hear that they teach PHP in kindergarden these days.

//Yeti

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



Re: [PHP] How can an elephant count for nothing?

2009-02-13 Thread Yeti
I guess the main reason for PHP to behave like this is to make life
easier for many everyday situations.

EXAMPLE:
User input via GET or POST - usually string
You compare it to some value - int/string or whatever

So if a user posts '17' (string) and you compare it to 17 (int),
unless you are using ===, PHP won't complain.

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



Re: [PHP] How can an elephant count for nothing?

2009-02-12 Thread Yeti
 Can anyone explain clearly why comparing a string
 with zero gives this apparently anomalous result?

?php
$string = 'oleyphoont';
var_dump((int)$string, $string == 0, $string == 1);
?

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



[PHP] Help on caching an object.

2009-02-11 Thread Yeti
Hello gang,

First of all, yes I searched the mailing list's archive.

My problem is very simple:
I have an object that's definately called with every page request.
It's pretty much the same for every unregistered/anonymous user.
And it's not small. Alot of attributes are being set from DB queries etc.

Now my idea was to do some sort of caching with PHP to speed things up.
So I was wondering if anybody had experiences on this ...

Of course, I considered using serialize(), but it seemed to me as if
it could cause even more lagging since PHP requires the class to
unserialize the object correctly. Then I would end up reading the
class file, reading the searialized object and unserializing it. A 100
simple DB queries might be done in the same time or at least not much
slower.

Could it be that I'm looking at the wrong place? Should it be more
like caching the queries or something similar?

Thank you very much for everyone's effort in advance.

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



Re: [PHP] Searching in a long text

2009-01-03 Thread Yeti
What if the whole text has only 1 line?

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



Re: [PHP] What does ?xml have to do with it?

2008-12-28 Thread Yeti
I think it can also be set in .htaccess

php_flag short_open_tag off

somebody confirm this or not.

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



Re: [PHP] Re: Read/decode barcodes from an image

2008-12-17 Thread Yeti
Basic bar code detection is not that difficult. You set a couple of
virtual lines over the images and crawl them pixel by pixel. Then
you count the black/white changes and the density of each change. I
could even think of doing this using GD if I had the time. On the
other hand it can get pretty complicated if you need error correction
like a neuronal network would provide it.

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



Re: [PHP] Chrome 1.0 released

2008-12-14 Thread Yeti
It more and more seems like a conspiracy against M$ to me. A company
trying to make up its own standards every once in a while, how can
that be wrong?

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



Re: [PHP] Chrome 1.0 released

2008-12-13 Thread Yeti
I got so used to Opera's mouse gestures, now I can't work fluently
with other browsers. So I tried Chrome for like 5 minutes. It's always
like How do I go back to the previous page again or how do I open a
new tab?.
As long as Chrome is not being bundled with new computers the average
Windows users will stick to Internet Explorer. I know that from
customers who are referring to IE as the program on my computer's
desktop running the internet. So if Google can manage to transform
Chrome into the internet program M$ might be forced to make IE9
support Richard's HTML5 graphing.

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



Re: [PHP] Chrome 1.0 released

2008-12-13 Thread Yeti
I have to defend poor little IE a little now. It supports XHTML and
CSS2 pretty well so far. And those standards came out a couple of
months ago.

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



Re: [PHP] A MySQL Question

2008-12-09 Thread Yeti
As a matter of fact, in space you can't even scream.

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



Re: [PHP] A MySQL Question

2008-12-09 Thread Yeti
 Sure you can... I'm screaming right now... and I'm in space. A container
 within a container within a container within a container (ad infinitum)
 is still within the outermost container.

I didn't hear you scream.

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



Re: [PHP] A MySQL Question

2008-12-08 Thread Yeti
?php
define('HUMAN_STUPIDITY', true);
function bigbang() {
while (HUMAN_STUPIDITY || !isset($debate_is_over)) { }
return true;
}
if (!isset($universe)) bigbang();
?

Who says the big bang is past?

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



Re: [PHP] Poll of sorts: Javascript Form validation or PHP

2008-12-07 Thread Yeti
 I put a small one together using regular expressions,
 http://www.ashleysheridan.co.uk/coding_php_validation.php

So we are regexing emails again?

#OUT OF coding_php_validation.php COPY
case 'email':
{
$expression = /^([a-z0-9_\-\.]+)@([a-z0-9_\-\.]+)\.([a-z]{2,5})$/i;
$errorText = The email does not appear to be a valid type.;
break;
}
#END COPY


What should be valid email addresses according to RFC 2822 [1]:
!#$%*+-/=?^_`{|[EMAIL PROTECTED]
@@example.com

Not valid email addresses:
\@example.com
@@example.com
- [EMAIL PROTECTED]

Valid email addresses according to the Multipurpose Internet Mail
Extension (MIME) [2]:
[EMAIL PROTECTED]
Ã(c)@℞.com


Re: [PHP] Poll of sorts: Javascript Form validation or PHP

2008-12-07 Thread Yeti
I think hotmail, or was it some other mail mogul, is allowing their
users to have those weird German umlauts and some accented characters.

EXAMPLE:
[EMAIL PROTECTED]

We are living in a multilingual world with dozens of alphabets.
Especiall those doing government sites should consider accessibility a
must.
I would not enjoy getting sued by some one who feels discriminated,
because of denied access since his/her name contains abnormal
characters.

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



Re: [PHP] Poll of sorts: Javascript Form validation or PHP

2008-12-05 Thread Yeti
Java Script should always be an option, unless you write the
validation for yourself or people you personally know only.

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



Re: [PHP] Poll of sorts: Javascript Form validation or PHP

2008-12-05 Thread Yeti
Nuclear power plants got the MCA [1]
Developers got the MCA [2]

[1] maximum credible accident
[2] maximum credible addlebrained

Both of them are what nobody likes to think of, but they can (and do?) happen.

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



Re: [PHP] Accessing the 'media' attribute in php

2008-12-03 Thread Yeti
 I have enough trouble getting my rather ancient brain around PHP, and
 was hoping that I could avoid getting involved with JavaScript.
 However it seems that it, or CSS, are the only possibilities for this
 case.

If I understood you correctly what you want is to change the style of
the page when the user is printing it.
As others mentioned before all you would have to do would be adding a
second style sheet for that purpose.

EXAMPLE:
link rel=stylesheet media=screen href=/styles/main.css type=text/css /
link rel=stylesheet media=print href=/styles/print.css type=text/css /

That would be all. Now if you want the user to have some kind of
preview when clickin on a print the page button or link
you need either JavaScript or PHP. The easiest way I could think of
would be using the same print style sheet.

For JavaScript have a look at this page ...
http://www.quirksmode.org/dom/changess.html

I think it should work in most modern browsers. Still doing it with
PHP will work in every browser, but requires the page to reload ...
For PHP have a look at this page ...
http://www.maratz.com/blog/archives/2004/09/21/10-minutes-to-printer-friendly-page/#printQuery

//A yeti

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



Re: [PHP] SELECT into array of arrays

2008-12-03 Thread Yeti
 How should I proceed? Thanks in advance for any suggestions.

Since you are looping through the result already, why not do it this way ..

$combinedArray = array();
for ($i=0;$icount($myArray);$i++) {

$sql = SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]');
$result = mysql_query($sql);

if(mysql_num_rows($result)  0) {
   while ($myrow = mysql_fetch_array($result)) {
   if (in_array($myrow['study'], $myArray))
$combinedArray[$myrow['study']][] = $myrow['symbol'];
   }
}
}

You should get an array like this ...
array(b2008 = array(A, B, C, D), b2005 = array(A, B, E))

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



Re: [PHP] SELECT into array of arrays

2008-12-03 Thread Yeti
Correcting myself now ..

$myArray = array('b2005', 'b2008');
$sql = SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]');
$result = mysql_query($sql);

if(mysql_num_rows($result)  0) {
  while ($myrow = mysql_fetch_array($result)) {
  if (in_array($myrow['study'], $myArray))
$combinedArray[$myrow['study']][] = $myrow['symbol'];
  }
}

Forgot to get rid of the first for loop

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



Re: [PHP] adding key- value pair to an array

2008-12-03 Thread Yeti
 //for each row I want to add percentage as new key-value pair
 // but it gives error 'Undefined variable:
 percentage'
$row-$percentage = ($browseCount / $totalCount ) * 100;

Obviously you get the error because $percentage is not defined ..

I did not fully understand what you wanted.

Here is a list of what should work ...

#Set a variable percentage in $row
$row-percentage = ($browseCount / $totalCount ) * 100;

#Set a variable with name $percentage in $row
$percentage = ($browseCount / $totalCount ) * 100;
$row-$percentage = $percentage;

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



Re: [PHP] SELECT into array of arrays

2008-12-03 Thread Yeti
And yet another thing i have overseen in my statement ..
If you remove the first for loop, also change the sql query. But I'm
sure you saw that already

NEW QUERY:
$sql = SELECT study,symbol FROM test WHERE study IN ('.implode(', ',
$myArray).');

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



Re: [PHP] adding key- value pair to an array

2008-12-03 Thread Yeti
 
 //you can get really stupid with this..
 ${false} = 'some string here';
 echo ${''};
 //echos some string here


I like stupid things

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



[PHP] Short circuit evaluation and include

2008-12-02 Thread Yeti
Hello everyone,
I'm posting this as a warning when using include() or include_once()
and checking their return values.
I'm refactoring someone else's code at the moment and got a short
circuit evaluation problem that made some problems ..
Here's the code:

FILE some_file.php:
?php
function some_function($file) {
$obj = false;

if (
!isset($file)
|| !is_string($file)
|| !is_readable($file)
|| !include_once($file)
|| !class_exists('some_class')
|| !is_a(($obj = new some_class()), 'some_class')
|| !method_exists($obj, 'some_method')
|| !$obj-some_method()
) return false; // line 14

return $obj;
}
$file = 'some_class.php';
some_function($file);
?

FILE some_class.php:
?php
class some_class {
function some_method() {
return true;
}
}
?

ERRORS PRODUCED:
Warning: some_function(1) [function.some-function]: failed to open
stream: No such file or directory in */some_file.php on line 14

Warning: some_function() [function.include]: Failed opening '1' for
inclusion (include_path='.;*/php/pear/') in */some_file.php on line 14

Note: I ran this code in PHP 4.4.9

It seemed to me like include_once() was not fully executed or
something when short circuited, because this code worked just fine
...

FILE some_file.php:
?php
function some_function($file) {
$obj = false;

if (
!isset($file)
|| !is_string($file)
|| !is_readable($file)
|| !include_once($file)
) return false;
if (
!class_exists('some_class')
|| !is_a(($obj = new some_class()), 'some_class')
|| !method_exists($obj, 'some_method')
|| !$obj-some_method()
) return false;

return $obj;
}
$file = 'some_class.php';
var_dump(some_function($file));
?

OUTPUT:
object(some_class)(0) {
}

So I was wondering how include() or include_once() are actually being
executed. I know they both return int(1) if no return specified in the
included file.
That's why I had a glance at the manual [1], where I saw this ..

Because include() is a special language construct, parentheses are not
needed around its argument. Take care when comparing return value.
Example #4 Comparing return value of include
?php
// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include('vars.php') == 'OK') {
echo 'OK';
}

// works
if ((include 'vars.php') == 'OK') {
echo 'OK';
}
?

So when I added the paranthesis it worked ...

FILE some_file.php:
?php
function some_function($file) {
$obj = false;

if (
!isset($file)
|| !is_string($file)
|| !is_readable($file)
|| !(include_once($file)) // --- added paranthesis
|| !class_exists('some_class')
|| !is_a(($obj = new some_class()), 'some_class')
|| !method_exists($obj, 'some_method')
|| !$obj-some_method()
) return false;

return $obj;
}
$file = 'some_class.php';
var_dump(some_function($file));
?

Me, after an hour of coding without a line of code.

[1] http://in.php.net/manual/en/function.include.php

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



Re: [PHP] How to hide MySQL password in connection string in PHP script?

2008-12-02 Thread Yeti
Robert Dodier robert_dodier AT yahoo.com wrote on 12-21-2003
 Hello,

 I am experimenting with a wiki system (PhpWiki) which uses
 a MySQL database to store pages. It seems like a great system.

 The MySQL connection string is specified in a PHP script
 in the form mysql://FOO:[EMAIL PROTECTED]/baz.

 If I'm not mistaken the script has to be world-readable.
 But then, can't any other user (logged in to the host)
 just read the password?

 I share the host with other users, and the script has to
 be in my home directory, so I don't think I can guarantee
 that no other user can see it.

 Thanks for any advice,

 Robert Dodier

I recently had the same problem on a shared host. The only solution I
could think of was to have the server admin set an environment
variable in an  httpd.conf  include file owned by root (chmod 600)
[1].

EXAMPLE (mysql_pw.conf):

SetEnv mysql_pw password
SetEnv mysql_user username

In PHP the variables then should end up in the $_SERVER array ...

EXAMPLE (PHP):
?php
var_dump($_SERVER['mysql_pw'], $_SERVER['mysql_user']);
?

If this is impossible I can't think of another secure way on shared
host systems, since other hosts usually are able to read your files.
Maybe (if supported) one could SetEnv in .htaccess, so an attacker
would at least have to glance into the PHP source code to find out
where the password is stored.
Still most people have it inside an include file and it works, I think.

[1] http://httpd.apache.org/docs/1.3/mod/mod_env.html

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



Re: [PHP] array_intersect question

2008-12-02 Thread Yeti
 The question is how to perform intersection on the following structure:

 $products =
 array(array(green,red,blue),array(green,yellow,red),array(green,red,purple),array(green,red,yellow));

If I understood you correctly ..

?php
$arr = array();
$arr[] = array(green, red, blue);
$arr[] = array(green, yellow, red);
$arr[] = array(green, red, purple);
$arr[] = array(green,red,yellow);
var_dump($arr);
// you could also ..
$arr = array();
array_push(
$arr, array(green, red, blue),
array(green, yellow, red),
array(green, red, purple),
array(green,red,yellow)
);
var_dump($arr);
?

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



Re: [PHP] Happy Turkey Day

2008-11-27 Thread Yeti
Today was a holiday?

I looked Thanksgiving up and wikipedia said it's some kind of
harvest festival. I guess that's why some mentioned turkeys ..

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



Re: [PHP] Voting methodology

2008-11-26 Thread Yeti
I once had to implement something similar for a client's intranet page.
First we designed it to work without login simply by logging the IPs
(static and in the 10.10.*.* range) to avoid people voting twice or
more.
Then the client wanted to have some statistics like what department
voted for what (yeah, not very democratic i know).
So we changed it have the user log in before voting. Now we could also
make sure that only authorized users were voting, unless a user forgot
to log out and a delivery guy was taking his chances (very unlikely).

I think the thingy about online voting is to ask oneself how serious
the result has to be. Getting a 99% bulletproof result might be quite
time consuming (thinking of HTTPS, tokens, authorization, etc. here).
So it all depends on what your client wants.

//A yeti

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



Re: [PHP] getStatic

2008-11-24 Thread Yeti
 What would you do?

I think PHP's string functions are pretty fast and even with large
documents we are talking about a couple of extra microseconds on a
modern machine. I once saw someone do pretty much the same as you are
trying to do with strtr() [1], but I don't know if that function is
faster than str_replace(). You should also consider that if you
framework is going to manage someone's site one day then it could
possibly be on a server with an older PHP version. I disagree with
those on the list saying one should just stick to an existing
templating framework, since it can be quite exciting to think some
neat thingy out. Of course, most people (including me) hardly have any
time at all to spend 1000s of hours on a more or less private project.

[1] http://in.php.net/manual/en/function.strtr.php

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



Re: [PHP] about SimpleXMLElement.

2008-11-22 Thread Yeti
There are some nice SimpleXML examples at php.net, one of them also
covers handling attributes ...
http://in.php.net/manual/en/simplexml.examples.php

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



Re: [PHP] IMagick confusion

2008-11-22 Thread Yeti
First of all .. always be careful with tainted data.
Like when you
$picture = $_GET['PICTURE'];
be aware that this could be a security risk one day an ImageMagick
exploid is circulating.

At the first glance I saw a syntactical thingy that might cause problems ..

case default:
  break;
In PHP switch for default this way ...

switch ($statement) {
case 1:
// do something
break;
default:
//do something else
}

then you forgot a semicolon
 $orientation = $image-getImageProperty(exif:Orientation); // --- ; added

after that I got your script running.

Note:
At least turn error reporting on during debugging etc.
All error-reporting behavior can be modified at any level, so if you
are on a shared host or otherwise unable to make changes to files such
as php.ini, httpd.conf, or .htaccess, simply ...

ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'OFF');

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



Re: [PHP] a for loop and probability random all i need is make them to reverse

2008-11-22 Thread Yeti
That should output the full line now
?

$prExample = new probabilityRandom;


function arasi($a,$b,$data)
{
$x = explode($a,$data);
$z = explode($b,$x[1]);
$oh = $z[0];
if($x  $z) { return $oh; } else { return false; }
}


$x=jZRBb9swDIXvA/YfdFyxHJK0GHadvc7tYUAQb+iZiWlHKGUFkpy1+/WTE7uzFcr1MSbz+NmPj1s4Om3E55X4tBKyFl/Wi+VyefPxQ0Zwwv/PV+vF3fl5epDO//5mlP/bBhoqjK4HfYv1Xdv2oyESGwKH0dbbVdu40U76p7oUuW6oK3299ZWEoPD/fkGGLtE1ipTQM5r3IQs7C3DYFsI9SVtoNcTLDBxAMWw5wesU1QOSQjeDKGy8MD35BtMilXDSxg6RfmmHSu5FfkTgPH0Ac9QjtwK0DJraEbo536vvjfJVBvY4xHts7U/0H4bsXEqNtnY3rId8idaz2IK+zkxZP4ut9EwpPHswq4DoZgh4T/JFGpE7KEvOWCBQUBd41fLGudVV4/XnZeTSPD8pAb+SRUE4eoH8AKZgyH9KAxWK71BV7Gay2FxqoshMdgJcAlONaTdGonXiUR1h7xjqrn7O+t6APbzPHstWhJtPWKapEDufoJ5n2V8dQmuxEL+Pfrf9bcr3RhNNAk0kKsIUyxU79OK6pPYMDokD4HtChbUDmoMcCVkEl41aaqSyfoO3eofXSql5tS3LuNp9e4NYT6e0F99AzXH26kE5Is+EqNeP7VI/ILI84YTrve8HZKRPOPEGYb0bQI13STd2OORaPOJir83alrs2av50kyyRSerMu9Z1zz5sCf7Vb7s7MY87SPFZzEUaqcbsjSnydo81J9Iek43FfSwccTMmyrj7Dw==;
$x = gzinflate(base64_decode($x));
$xx=explode(
,$x);
$xcx=array();

foreach($xx as $c = $y)
{
$yy = arasi( in ,),$y);
$yy = str_replace(,,,$yy);
$xcx[]=$yy;
#echo $yy.br;
$itemisim = explode((,$y);
$itemisim=$itemisim[0];
$xcx[isim][]=$itemisim;
}
for($i=0;$i=count($xcx)-1;$i++)
{
$prExample-add( $xx[$i], $xcx[$i] ); // -- changed to $xx[i]
}
print $prExample-get();

class probabilityRandom {
 #private vars
 var
 $data = array(),
 $universe = 0;
 #add an item to the list and defines its probability of beeing chosen
 function add( $data, $probability ){
 $this-data[ $x = sizeof( $this-data ) ] = new stdClass;
 $this-data[ $x ]-value = $data;
 $this-universe += $this-data[ $x ]-probability = abs( $probability );
 }
 #remove an item from the list
 function remove( $index ){
 if( $index  -1  $index  sizeof( $this-data ) ) {
  $item = array_splice( $this-data, $index, 1 );
  $this-universe -= $item-probability;
 }
 }
 #clears the class
 function clear(){
 $this-universe = sizeof( $this-data = array() );
 }
 #return a randomized item from the list
 function get(){
 if( !$this-universe )
  return null;
 $x = round( mt_rand( 0, $this-universe ) );
 $max = $i = 0;
 do
  $max += $this-data[ $i++ ]-probability;
 while( $x  $max );
 return $this-data[ $i-1 ]-value;
 }
}
?

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



Re: [PHP] Re: Some kind of Popup

2008-11-22 Thread Yeti
Another JavaScript method would be to load the content in a hidden div
with position: absolute.

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



Re: [PHP] Re: Some kind of Popup

2008-11-22 Thread Yeti
 One issue is I don't want to leave the space available on my regular web
 page and would like to try not to overwrite something there - I'd rather
 have a separate window of some sort that sort of floats over the web page.

Well, since Javascript does the Job anyways you don't have to load it
with the page when doing the div method.
You would only need this little addition to your css ..

style type=text/css
.div_win {
position: absolute;
width: 400px;
top: 100px;
left: 10%;
visibility: hidden;
}
/style

When user initializes the request by clicking a link

script type='text/javascript'
var div_window = document.createElement('div');
div_window.setAttribute('class', 'div_win');
div_window.className = 'div_win';
document.body.appendChild(div_window);
/script

Then you do some AJAX or JSON or whatever and apply it to the div.
You can also move the div around doing it somehow like this ...
http://www.quirksmode.org/js/dragdrop.html

Still, opening up a new window might be the simple solution after all lol.

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



Re: İlgi: [PHP] a for loop and probability random all i need is make them to reverse

2008-11-22 Thread Yeti
2008/11/22 Tontonq Tontonq [EMAIL PROTECTED]:
 sorry i think i did tell u wrong about it problem is not showing name
 of it as exaclty i just wanted give a point to it thats not real
 problem real problem is i want it be more unpossible when i give the
 class's add function's higher value

In that case I would go for an algorithm using some kind of gaussian
distribution, like the Marsaglia polar method [1].
I once wrote something similar to what (I think) you are asking for ...

?php
function marsaglia($likelihood) { // adapted polar-method by marsaglia
if (!is_numeric($likelihood) || ($likelihood == 0)) $likelihood = 100;
elseif ($likelihood = 1) return 1;
// the greater likelihood, the less the chance of getting the thingy
$v = 2;
$u1 = $u2 = 1;
while ($v  1) {
$u1 = 1/(rand(1, $likelihood)*$likelihood);
$u2 = 1/(rand(1, $likelihood)*$likelihood);

$v = $u1*$u1 + $u2*$u2;
}

$p = $u1*sqrt((-2)*(log($v)/$v));
return ($p  0.85) ? 1 : (int)$p;
}
?

The best return of this function would be 1. Now if you call the
function with a high $likelihood (say 1000 and more) it gets less
likely have 1 returned ( gaussian ).
If you want to decrease the chance of getting values close to 1 then
you will have to increase $likelihood inside the function or
something.

[1] http://en.wikipedia.org/wiki/Marsaglia_polar_method

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




Re: [PHP] Anyway to simulate pcntl_fork() on Windows?

2008-11-21 Thread Yeti
check this out ...
http://in.php.net/manual/en/ref.pcntl.php#37369

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



Re: [PHP] store class zithin session

2008-11-20 Thread Yeti
If you can't load the class before calling session_start you can store
the serialized object in a file and simple set a
$_SESSION['path_to_file'] session variable..

EXAMPLE:
?php
session_start();

//some code

class apple_tree {
var $apples = 17;
}

$temporary_file = 'appletree.txt';
$file_content = serialize(new apple_tree());

if ($fp = fopen($temporary_file, 'w')) {
fwrite($fp, $file_content);
$_SESSION['path_to_file'] = $temporary_file;
fclose($fp);
}

?

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



Re: [PHP] Model Web Site

2008-11-20 Thread Yeti
 What is new to me is controlling access based on being a member. And
 making it tough for hackers.

 Look for a tutorial on building a login system and go from there.

Since you mentioned security I would recommend HTTPS.
http://en.wikipedia.org/wiki/HTTPS

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



Re: [PHP] Re: anchor name on URL

2008-11-19 Thread Yeti
 Now I tend only to use it now for file management, FTP and testing
 websites.
Beware that Konqueror has changed with KDE4. Now its main purpose is
to be a web browser, whereas the new program Dolphin is used for
file management etc.

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



Re: [PHP] Invalid Arguements

2008-11-19 Thread Yeti
if you

?php
var_dump($_POST['BannerSize']);
?

what do you get?

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



Re: [PHP] Stats (was anchor name on URL)

2008-11-19 Thread Yeti
I think it's also interesting to know what browsers web developers prefer [1].

Also what people would like to know more about [2].
Number 1: howto kiss
Number 5: howto hack (lol?)

[1] http://www.w3schools.com/browsers/browsers_stats.asp
[2] http://www.google.com/intl/en/press/zeitgeist2007/mind.html

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



Re: [PHP] Invalid Arguements

2008-11-19 Thread Yeti
 when I use the var_dump as suggested I get:
 *Parse error*: syntax error, unexpected '' in *
 C:\Inetpub\wwwroot\WorkOrderSystem\WorkOrder.php* on line *136*

I guess that means you tried something like this ...

EXAMPLE:
?php

// some code

?php
var_dump($_POST['BannerSize']);
?

?

Can you see what PHP does not like here?
It's the second ?php tag

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



Re: [PHP] implode()

2008-11-18 Thread Yeti
with implode one can reverse the function arguments i know .. but

?php
$BannerSize = '';
if (isset($_POST['BannerSize'])  is_array($_POST['BannerSize']))
{
$BannerSize = implode(',', $_POST['BannerSize']);
}

?

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



Re: [PHP] Re: phpDesigner 2008?

2008-11-18 Thread Yeti
Yes, NetBeans became my favourite too a while ago. And it runs on many
Operating Systems, is free and has a debugger.
I also like the way it handles projects.

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



Re: [PHP] anchor name on URL

2008-11-18 Thread Yeti
If you do not escape the name attribute you might run into trouble
when using XHTML. Always escape attributes properly.

GOOD:
?php
echo HEREDOC
div style=padding-bottom: 1500px;div style=padding-bottom: 1500px;
a href=#aynchoor title=some_aynchoor name=some_aynchoorClick me/a
/div
div style=padding-bottom: 1500px; background-color: #f00baa;
a href=#some_aynchoor title=aynchoor name=aynchoorClick me too/a
/div
HEREDOC;
?

BAD:
?php
echo 'a href=#aynchoor title=some_aynchoorClick me';
echo 'a href=#some_aynchoor title=aynchoor name=aynchoorClick me too';
?

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



Re: [PHP] Re: anchor name on URL

2008-11-18 Thread Yeti
 I look forward to the day when markup isn't so bloated
 due to the inability of certain web browser franchises to get it right.

Although I usually look at the future through an optimistic point of
view, that day may never come.

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



Re: [PHP] Experience (was: while-question)

2008-11-17 Thread Yeti
who says PHP means programming?
All I see is script code, unless you write your own extension or you
contribute to php-internal

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



Re: [PHP] Experience (was: while-question)

2008-11-17 Thread Yeti
Ok, ok I admit it. PHP is a programming language. I guess I drank too
much assembly code today.
By the way ... Motorola 68000! Those were to good old days.

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



Re: [PHP] Days until Easter and Christmas

2008-11-16 Thread Yeti
 I guess Canadians are slower, eh?  :-)
LOL

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



Re: [PHP] RegEx to check for non-Latin characters

2008-11-15 Thread Yeti
Hi Behzad,

I would try a different approach ...

EXAMPLE (UTF-8):

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /
titlePersia/title
/head
body
?php
$username = '1aﺠﺟﺝﭻﭽﭼﭺ2b;
$encoding = 'utf-8';
$username = mbStringToArray($username, $encoding);
foreach($username as $char) {
   if (strlen($char) == 1) echo $char.' is not a multibyte characterbr /';
}
function mbStringToArray ($string, $encoding) {
   $strlen = mb_strlen($string);
   while ($strlen) {
   $array[] = mb_substr($string,0,1,$encoding);
   $string = mb_substr($string,1,$strlen,$encoding);
   $strlen = mb_strlen($string);
   }
   return $array;
}
?
/body
/html

As you can see I'm using the multibyte string functions [1] and split
$username into a character by character array.
Then I use strlen() for which an UTF-8 char has a length  1. Note:
This might change with PHP6.
It also does not check for Persian characters only yet. You would have
to try something like this ...

EXAMPLE (UTF-8):

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /
titlePersia/title
/head
body
?php
$username = '1aﺠﺟﺝﭻﭽﭼﭺ2b';
$encoding = 'utf-8';
$chars = 
'ﺐﺒﺑﺏﭗﭙﭙپﺖﺘﺗﺕﺚﺜﺛﺙﺞﺠﺟﺝﭻﭽﭼﭺﺢﺤﺣﺡﺦﺨﺧﺥﺪﺪﺩﺩﺬﺬﺫﺫﺮﺮﺭﺭﺰﺰﺯﺯﮋﮋژژﺲﺴﺳﺱﺶﺸﺷﺵﺺﺼﺻﺹﺾﻀﺿﺽﻂﻄﻃﻁﻆﻈﻇﻅﻊﻌﻋﻉﻎﻐﻏﻍﻒﻔﻓﻑﻖﻘﻗﻕﮏﮑﮐکﮓﮕﮔگﻞﻠﻟﻝﻢﻤﻣﻡﻦﻨﻧﻥﻮﻮووﻪﻬﻫﻩﯽﻴﻳﻯ';
$username = mbStringToArray($username, $encoding);
foreach($username as $char) {
   if (strlen($char) == 1) echo $char.' is not a multibyte characterbr /';
   if (mb_strpos($chars, $char, 0, $encoding) !== false) echo $char.' is
a Persian characterbr /';
}
function mbStringToArray ($string, $encoding) {
   $strlen = mb_strlen($string);
   while ($strlen) {
   $array[] = mb_substr($string,0,1,$encoding);
   $string = mb_substr($string,1,$strlen,$encoding);
   $strlen = mb_strlen($string);
   }
   return $array;
}
?
/body
/html

[1] http://in.php.net/manual/en/ref.mbstring.php
[2] http://in.php.net/manual/en/function.strlen.php


Re: [PHP] Recursive Static Method

2008-11-12 Thread Yeti
Some code would be quite helpful here. But your scenario should not
make any problem.

EXAMPLE:
?
class foo {
static function test() {
static $count;
$count++;
echo Call {$count}br /;
include_once('test.php');
}
}
foo::test();
?

EXAMPLE (@file: test.php):
?php
if (class_exists('foo')) {
foo::test();
}
exit();
?

OUTPUT:
Call 1br /Call 2br /

//A yeti

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



Re: [PHP] fopen not working corectly on remote IIS

2008-11-11 Thread Yeti
As PHP says ... there seems to be something wrong with file
permissions. Make sure the IIS-user (if there is one on windows) can
read intekendb.php.
I don't know if you checked [1] yet. It's alot of useful info about php on IIS.

Quote out of that article:
The IIS user (usually IUSR_MACHINENAME) needs permission to read
various files and directories, such as php.ini, docroot, and the
session tmp directory.

Maybe [2] can help you out too.

[1] http://www.php.net/manual/en/install.windows.iis.php
[2] http://at.php.net/manual/en/function.fopen.php#50601

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



Re: [PHP] Secure redirection?

2008-11-05 Thread Yeti
I wonder why you redirect the page via php when the browser supports JavaScript
Why not let JS do the redirect after the XMLHttpRequest?

figurative code ..

if (BROWSER DOES NOT SUPPORT JS) header(Location: http://$host$url;);

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



Re: [PHP] ??????????? ??????? 648-67-61 ??? ?????? ? ???? ?????? ? ??????

2008-11-05 Thread Yeti
no comment

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



Re: [PHP] removing text from a string

2008-11-04 Thread Yeti
?php
$filename = .htaccess;
$fp =@ fopen($filename, r) or die (Couldn't open $filename);
// ENTER ENCODING HERE ..
$encoding = 'UTF-8';
if ($fp)
{
   while (!feof($fp))
   {
 $thedata =@ fgets($fp);
   // if every number is defonoodle separated by a dot ..
   if (is_string($thedata))
   {
   $position_of_dot = mb_strpos($thedata, '.', 0,
$encoding);
   if (is_numeric($position_of_dot) 
($position_of_dot = 0))
   $thedata = trim(mb_substr($thedata,
$position_of_dot,
mb_strlen($thedata, $encoding), $encoding));
   }

 //print the modified line and \n
   }
}
@fclose($fp);

?

[mb_strpos] http://in.php.net/manual/en/function.mb-strpos.php
[mb_substr] http://in.php.net/manual/en/function.mb-substr.php

//A yeti

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



Re: [PHP] Grouping records

2008-11-04 Thread Yeti
 I have transactional records with the following structure

Records of what kind? Is it SQL?

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



Re: [PHP] Re: removing text from a string

2008-11-04 Thread Yeti
 ltrim($line, '0123456789 .');

I am feeling a bit boneheaded now. How easy things can be.

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



Re: [PHP] Re: removing text from a string

2008-11-04 Thread Yeti
Replying to myself now.

On Tue, Nov 4, 2008 at 7:40 AM, Yeti [EMAIL PROTECTED] wrote:
 ltrim($line, '0123456789 .');

 I am feeling a bit boneheaded now. How easy things can be.


This would not work if the character string after the number started
with a number too.

EXAMPLE
?php
$line = '017. 85 apples were sold to customer John Doe.';
# now ltrim would clearly cut off the '85 ' which belongs to the sentence.
var_dump(ltrim($line, '0123456789 .'));
?

So if one still wanted the speedy string functions a simple trim() [1]
or another ltrim() [2] would have to be added.

EXAMPLE
?php
$line = '017. 85 apples were sold to customer John Doe.';
var_dump(ltrim((ltrim($line, '0123456789.'), ' '));
?

Still there is one flaw in this construct:
If there was no white space between the '017.' and the '85 apples ..'
we get the old mishap again.

EXAMPLE
?php
$line = '017.85 apples were sold to customer John Doe.';
# note the difference above: '017.85 apples ...' this time
var_dump(ltrim((ltrim($line, '0123456789.'), ' '));
?

To stick with the string functions one could either use the
strpos($line, '.') + substr() [3] method or do it with explode(),
implode() [4]:

EXAMPLE
?
$line = '017.85 apples were sold to customer John Doe.';
$line = explode('.', $line);
unset($line[0]);
$line = implode('.', $line);
?

So it seems that the regular expressions posted are not a bad choice after all.

//A yeti

[1] http://in.php.net/manual/en/function.trim.php
[2] http://in.php.net/manual/en/function.ltrim.php
[3] http://marc.info/?l=php-generalm=122580865009265w=2
[4] http://in.php.net/manual/en/function.explode.php

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



Re: [PHP] Grouping records

2008-11-04 Thread Yeti
Ok, this looks quite databasey so I guess you will have a query like:

SELECT Rowid, Person, Timediff FROM transitional_records ORDER BY Timediff

I don't know what DB you use. let's say it is MySQL (the others are similar).
Always provide such things when asking for advice. Else it's not easy to help.

EXAMPLE
?php
mysql_connect(localhost, mysql_user, mysql_password) or
die(Could not connect:  . mysql_error());
mysql_select_db(mydb);
$result = mysql_query(SELECT Rowid, Person, Timediff FROM
transitional_records ORDER BY Timediff);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// do something with the result here
}
mysql_free_result($result);
?

So what we get is an array like this ..

array (
Person = (string),
Timediff = (numeric)
);

Rowid, Person and Timediff are the only Values we need to get each
entries Groupid.
Now back to our example ..

EXAMPLE
?php
mysql_connect(localhost, mysql_user, mysql_password) or
die(Could not connect:  . mysql_error());
mysql_select_db(mydb);
$result = mysql_query(SELECT Rowid, Person, Timediff FROM
transitional_records ORDER BY Timediff);
$persons = array(); // array containing each persons current Groupid
$rowids = array(); // array containing each row's groupid
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$rowids[$row['Rowid']] = 0; // default for a row's groupid
if ($row['Timediff']  60) {
if (!isset($persons[$row['Person']])) $persons[$row['Person']] 
= 0;
++$persons[$row['Person']];
}
if (isset($persons[$row['Person']])) $rowids[$row['Rowid']] =
$persons[$row['Person']];
}
var_dump($rowids);
mysql_free_result($result);
?

So what is that script doing?
Well, first of all we set 2 arrays $persons and $rowids;
$persons is some sort of buffer for each person's current Groupid
whilst processing the table entries.
$rowids contains Groupid for each Row (set whilst processing)

WHILE LOOP:
First the current row's Groupid is set to the default value, which is
zero ( $rowids[CURRENT_ID] = 0 ).
Then we check whether the Timediff of the current row is greater than 60 or not.
IF it is the person's current Groupid is incremented (
$persons[CURRENT_PERSON] += 1 )
After the IF statement the current rowid's Groupid is changed to
$persons[CURRENT_PERSON] if that one exists.

As result we should get an array $rowids with the Groupid for each array.

So simply loop through that array and have the database SET the
Groupid somehow like this ..

EXAMPLE
?php
foreach ($rowids as $row = $group) {
echo SQL
UPDATE transitional_records SET Groupid = $group WHERE Rowid = $row;

SQL;
}
?

I hope I could help a little
Be more specific next time

//A yeti

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



Re: [PHP] Электронная реклама 648-67-61 все адреса и базы Москвы и России

2008-11-04 Thread Yeti
Command unkown. Make sure you typed it right.

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



Re: [PHP] basic php question...

2008-11-04 Thread Yeti
Do disability browsers support JavaScript?

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



Re: [PHP] Sessions in object oriented code

2008-10-31 Thread Yeti
 I can't really understand that. Not sure if you understand my problem
 properly (if I've not explained properly). Anyone can give me some solutions
 please?
Well as long as you don not provide any code it's all just wild guesses.
What I tried was to show you a way of simply preventing the HTML from
being sent to the browser before you include the session and/or cookie
file. So you would just have to add the output buffering syntax to
your existing code without changing all the scripts.

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



Re: [PHP] Bitwise operation giving wrong results

2008-10-30 Thread Yeti
Usually in PHP one does not take much care about the data types, but
in this case you absoloodle have to.
If you use bit operators on a character then its ascii number will be
taken instead (how should a number based operation work with a
string?)

also if you pass on $_GET params directly into ay bitwise operation
you might get some un-nice behaviour. So check them first.

?php
$a = $b = false;
if (is_numeric($_GET['b'].$_GET['a'])) {
$a = (int)$_GET['a'];
$b = (int)$_GET['b'];
echo $a  $b;
}
?

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



Re: [PHP] Re: Printing JPEG

2008-10-30 Thread Yeti
If you are on a linux box with lpr [1] running you could try a
shell_exec() in combination with imagemagick

[1] http://tldp.org/HOWTO/Printing-Usage-HOWTO-2.html

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



Re: [PHP] Regex validation

2008-10-30 Thread Yeti
After ceo posted about the imap function I was eager to try it out
and got rather disappointed pretty soon.
imap_rfc822_parse_adrlist() should not be used for email validation!

EXAMPLE:
?php
var_dump(imap_rfc822_parse_adrlist('! # $ %   * + - / = ? ^ _ ` { |
} ~', ''));
?

The above code will output:

array(1) {
  [0]=
  object(stdClass)(2) {
[mailbox]=
string(36) ! # $ %   * + - / = ? ^ _ ` { | } ~
[host]=
string(0) 
  }
}

Although
! # $ %   * + - / = ? ^ _ ` { | } ~@example.com
would be a valid email address!

Without the '@example.com' it is not.

Have a look at the user comments at [1], where one user has further examples.

[1] http://us.php.net/manual/en/function.imap-rfc822-parse-adrlist.php

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



Re: [PHP] Regex validation

2008-10-30 Thread Yeti
ceo wrote:
var_dump(imap_rfc822_parse_adrlist('! # $ %   * + - / = ? ^ _ ` { | } ~', 
''));
This looks like a valid localhost email address to me...

It surely is a valid localhost email address, but what most people
(and the OP) usually need is to validate a full email string with a
local and a domain part.

What should be valid email addresses according to RFC 2822 [1]:
!#$%*+-/=?^_`{|[EMAIL PROTECTED]
@@example.com

Not valid email addresses:
\@example.com
@@example.com
- [EMAIL PROTECTED]

Valid email addresses according to the Multipurpose Internet Mail
Extension (MIME) [2]:
[EMAIL PROTECTED]
[EMAIL PROTECTED]

So for people who got to write code that also works on PHP4 it is not
very easy to validate an email address.
Even nice regex attempts like [3] fail since more and more mail
servers support the MIME hieroglyphs.
That's why I was pretty excited about imap_rfc822_parse_adrlist(),
since it runs in PHP4 if installed.
Which clearly is no substitute for the PHP5+ filter functions [4].
If it's just my brain farting and there actually then tell me.

[1] http://www.faqs.org/rfcs/rfc2822.html
[2] http://en.wikipedia.org/wiki/MIME
[3] http://www.addedbytes.com/php/email-address-validation/
[4] http://in.php.net/filter


Re: [PHP] Mailing lists

2008-10-30 Thread Yeti
Even a four year old girl would think that's too pink, Rich.

What's wrong with pink?

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



Re: [PHP] Mailing lists

2008-10-30 Thread Yeti
My 5-year-old had pretty much the same discussion with his sister

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



Re: [PHP] Sessions in object oriented code

2008-10-30 Thread Yeti
OK I guess it's somehow like this ..

form
?php
if (isset($_POST['submit'])) {
include('sessions.php');
// include sessions.php
}
?
!-- form innerhtml --
/form

now this of course is something very bad to do and it wont work.
One way to prevent markup from being outputted is using ob_buffer() [1]

EXAMPLE:
?php
$form = FORM
form
!-- form inner xml --
/form
FORM;
ob_start();
echo $form;
$output_buffer = ob_get_contents();
ob_end_clean();
var_dump(nl2br(htmlentities($output_buffer)));
?

So what we do here is simply start the output buffer befor echoing $form.
ob_get_contents() returns the outputbuffer as it is right now.
By calling ob_end_clean() buffering is stopped and the buffer cache released.
Still keep in mind that headers will still be sent when buffering the output.

here is a more complex
EXAMPLE:
?php
ob_start(); // starting the output buffer
?
html
body
!-- inner xml --
{{replace_me}}
/body
/html
?php
$output_buffer = ob_get_contents();
ob_end_clean();
session_start();
$_SESSION['test'] = time();
echo str_replace('{{replace_me}}', 'pThis is the replaced string.br
/SESSION[test] was set to: '.$_SESSION['test'].'/p',
$output_buffer);
?

Now we start the output buffer at the beginning of the script and the
session at the end.
It does not matter whether we close the PHP tag after starting the
ob_buffer. ( like with ? )
As long as we do not flush_end or clean_end the output buffering
process it will continue caching the output (except headers).
So session_start should work after actually outputting markup.

Another method could be like we did above the str_replace() [2] ...

EXAMPLE:
?php
$some_number = time();
$html = HTML
html
body
pTime: $some_number/p
p{{replace_me}}/p
/body
/html
HTML;
echo str_replace('{{replace_me}}', 'This string was changed by PHP', $html);
?

There is still plenty of other possible solutions. Keep on rocking

[1] http://in.php.net/manual/en/ref.outcontrol.php
[2] http://in.php.net/manual/en/function.str-replace.php

//A yeti

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



Re: [PHP] Regex validation

2008-10-29 Thread Yeti
On Wed, Oct 29, 2008 at 5:36 AM,  [EMAIL PROTECTED] wrote:

 When it comes to email validation, I would recommend using the IMAP function 
 which will be both fast and correct:

 http://us.php.net/manual/en/function.imap-rfc822-parse-adrlist.php

 Otherwise, it's guaranteed that you are having at least some false positives, 
 and probably some false negatives.

Didn't know about those IMAP functions. And they even work in PHP4.
Thanks for telling.

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



Re: [PHP] Parsing URLs

2008-10-28 Thread Yeti
One could also abuse basename and pathinfo.
Works in PHP4+

?php
$uri = 'http://www.domain.com/page/file/';
$pathinfo = pathinfo($uri);
$webpageaccess = array();
$webpageaccess[1] = $webpageaccess[2] = '';
if (isset($pathinfo['basename'])) $webpageaccess[1] = $pathinfo['basename'];
if (isset($pathinfo['dirname'])) $webpageaccess[2] =
basename($pathinfo['dirname']);
//var_dump($webpageaccess);
?

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



Re: [PHP] Regex validation

2008-10-28 Thread Yeti
 If your trying to filter E-Mail addresses, then filter_var is what you
 should use:

 http://php.net/filter_var

If the OP (original poster) got PHP5+

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



Re: [PHP] Interactive canvas example

2008-10-26 Thread Yeti
It worked for me. Although I had some quite CPU intensive processes
running, so it lagged a bit.
Had no time to look into the code, so I was wondering if you could
answer my question ...
That yellow information box popping up onclick(), is it drawn by JS or
is it something like a hidden div?

Congratulations on that one
//A yeti

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



Re: [PHP] Re: Interactive canvas example

2008-10-26 Thread Yeti
JS I suppose. Though it creates a DIV element on demand. The function
in question is RGraph.Tooltip() in RGraph.common.js.

OK, I found it. Thank you for showing me. I was thinking of something
similar recently.

/**
* Shows a tooltip next to the mouse pointer
*
* @param text The tooltip text
* @return The tooltip object - a DIV
*/
RGraph.Tooltip = function (canvas, text, x, y)
{
/**
* Hide any currently shown tooltip
*/
if (RGraph.tooltip) {
RGraph.tooltip.style.display = 'none';
RGraph.tooltip = null;
}

/**
* Show a tool tip
*/
var obj  = document.createElement('DIV');
obj.style.position= 'absolute'
obj.style.backgroundColor = '#E1';
obj.style.border  = '1px solid #333';
obj.style.borderRight = '2px solid #333';  // Set the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
obj.style.borderBottom= '2px solid #333'; // Set the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
obj.style.display = 'block'
obj.style.visibility  = 'visible';
obj.style.paddingLeft = '3px';
obj.style.paddingRight= '3px';
obj.style.fontFamily  = 'Tahoma';
obj.style.fontSize= '10pt';
obj.innerHTML = text;

document.body.insertBefore(obj, canvas);

obj.style.left= (canvas.offsetLeft) + x + 3;
obj.style.top = (canvas.offsetTop + y) - obj.offsetHeight;

/**
* Install the function for hiding the tooltip.
*
* FIXME Not sure how this will affect any existing document.onclick 
event
*/
document.body.onclick = function ()
{
RGraph.tooltip.style.display = 'none';
}

/**
* Keep a reference to the object
*/
RGraph.tooltip = obj;
}

Now I wonder why you are creating a new tooltip each time the user
clicks on the graph?
Why not do it the following way?

RGraph.Tooltip = function (canvas, text, x, y)
{
try {
if (RGraph.tooltip) { // if tooltip already drawn
RGraph.tooltip.innerHTML = text;
RGraph.tooltip.style.left = (canvas.offsetLeft) + x + 3;
RGraph.tooltip.style.top = (canvas.offsetTop + y) -
RGraph.tooltip.offsetHeight;
} else { // create tooltip if not drawn yet
var obj  = document.createElement('DIV');

obj.style.position= 'absolute'
obj.style.backgroundColor = '#E1';
obj.style.border  = '1px solid #333';
obj.style.borderRight = '2px solid #333';  // Set 
the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
obj.style.borderBottom= '2px solid #333'; // Set 
the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
obj.style.display = 'block'
obj.style.visibility  = 'visible';
obj.style.paddingLeft = '3px';
obj.style.paddingRight= '3px';
obj.style.fontFamily  = 'Tahoma';
obj.style.fontSize= '10pt';
/*
//alternatively one could create a tooltip css 
class since this is
presentation
obj.className = 'tooltip'; //IE
obj.setAttribute('class', 'tooltip'); // W3C DOM
*/
document.body.insertBefore(obj, canvas);

RGraph.tooltip = obj;

document.body.onclick = function ()
{
RGraph.tooltip.style.left = '-999'; //older 
opera fix
}

return RGraph.Tooltip(canvas, text, x, y);
}
return RGraph.tooltip; // return tooltip obj as stated in 
functions comment
} catch(e) {
return false;   
}
}

Secondly CanvasTextFunctions.letters() really is in a class of its own.
And why dont you use prototype [1]?

[1] http://www.w3schools.com/jsref/jsref_prototype_array.asp

//A yeti

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



Re: [PHP] clear a mysql table

2008-10-25 Thread Yeti
I used to have a similar problem
What I did was to define a max number of cashed pages.
So when reaching that number I simply did it the FIFO way

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



Re: [PHP] what's the difference in the following code?

2008-10-24 Thread Yeti
The difference between the examples are still nothing, it do the same.
But I never use the short version of if, because when I look after some month 
in some projects I have a better overview when there is a long if , its much 
easier to extend.

As explained a couple of times already - there is not supposed to be a
difference.
It's about security and making code maintainance easier.

[quote to Chris's former post]
(..) imagine you're manually reviewing a colleague's code, and you're
looking through a few thousand lines to try to help identify security
problems. (..)
[end quote]

It's the old What's good code and what's bad code? discussion.
In this case ternary operations are bad code.

sorry for my bad english
Die Code tun nicht Unterschiede in Execution. Es ist Sicherheits Frage.
sorry for my bad German

//A yeti

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



Re: [PHP] Building an array, kind of?

2008-10-24 Thread Yeti
?php
$arr = array(1234, 1235, 1236, 1237, 1238, 1239);
$string = implode(', ', $arr);
var_dump($string);
?

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



Re: [PHP] MkDir Help

2008-10-23 Thread Yeti
If you are prior PHP5 write your own recursive mkdir function [1] as
posted on this list a while ago.

[1] http://marc.info/?l=php-generalm=121926660406116w=2

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



Re: [PHP] Inheritance of class methods

2008-10-23 Thread Yeti
Using extends means that a class IS-A substructure of its parent class(es).

EXAMPLE:

class plant { };
class tree extends plant { };
class apple_tree extends tree { };

apple_tree inherits all methods and attributes from plant and tree
So if there was a methods plant-growth() you can also call it from
tree and apple_tree

IS-A versus HAS-A

apple_tree IS-A tree
apple_tree HAS-A fruit called apple

So apple does not extend apple_tree because it is not a tree

EXAMPLE:

class apple {
var color = 'blue';
var inhabitant = 'worm';
}
class apple_tree extends tree {
var apples = array(new apple());
}

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



Re: [PHP] export data to a ms excel file using php

2008-10-23 Thread Yeti
I'm not into MS Office, but isn't there some weird Office XML format
since Office 2007?
At MSDN I could find a nice description of the wannabe standard [1].
So if the new Excel can take XML it wouldn't be too difficult to
export the data I guess.

[1] http://msdn.microsoft.com/en-us/library/aa338205.aspx

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



Re: [PHP] Re: -help

2008-10-22 Thread Yeti
-help: invalid argument

I like the way you handle input errors in your php-general subroutines David.

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



Re: [PHP] Problem changing file encoding

2008-10-22 Thread Yeti
A neat way to transcode between different encodings is htmlentities
and html_entity_decode [1, 2]

EXAMPLE:

?php
# encode a string in UTF-8 to html entities
$string = 'øæåöäü';
$string = htmlentities($string, ENT_QUOTES, 'UTF-8');
# transcode it into ISO-8859-15
$string = html_entity_decode($string, ENT_QUOTES, 'ISO-8859-15');
?

There was a user with a similar problem at phpbuilder forums [3]. Have
a closer look at it.

[1] http://us2.php.net/manual/en/function.htmlentities.php
[2] http://us2.php.net/manual/en/function.html-entity-decode.php
[3] http://www.phpbuilder.com/board/archive/index.php/t-10334612.html

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



Re: [PHP] Re: -help

2008-10-22 Thread Yeti
Well maybe it is because he has register_globals on why he is not
printing a list of valid arguments.

imagine something like this ..

@php-generals$ [PHP] -help
List of valid arguments:
-c, --make-me-forget erases the built-in mainframe's short term memory
-f, --flush-me erases the entire memory of the built-in mainframe
-h, --help prints this list
-s, --show-bank-data prints the bank account data
-u, --user username for login
-p, --password passphrase for login
@php-generals$ [PHP] -u ' ; return true;' -p ' ; shell_exec('su god');' -s -c
Login successful!
Welcome to the built-in mainframe god.
--- Bank account data ---
* * *  **
 **  ** ** **
 *** ***  ***
---
[EMAIL PROTECTED] dd if=/dev/zero of=/dev/sda; exit;

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



Re: [PHP] Difficulty navigating symlinks

2008-10-22 Thread Yeti
If you are in control of you DNS records you could CNAME [1] the sites
to the same address, where a PHP script or RewriteRule [2] loads the
specific configuration by checking the requested URI. Since you got
them on the same server anyways this would not cost any performance.

[1] http://www.zytrax.com/books/dns/ch8/cname.html
[2] http://marc.info/?l=php-generalm=122383066714789w=2

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



Re: [PHP] Securing AJAX requests with PHP?

2008-10-21 Thread Yeti
 True, but then my permission / auth / workflow schema defines all that. the
 user won't like have that permission, the request will be logged and nothing
 is ever deleted from the app in any case since I only allow soft (record
 level flag ) deletes to ensure data integrity

I agree with Bastien here. If you can't trust your authorized users
then don't authorize them to delete entries. I would also recommend
some kind of access control to lower the risk of a complete data loss.
Use HTTPS to prevent man in the middle attacks.

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



Re: [PHP] what's the difference in the following code?

2008-10-21 Thread Yeti
OP = original poster (in this case I guess)
http://acronyms.thefreedictionary.com/OP

So it's all about making code readable and probably easier to maintain
(even people unfamiliar with the script).
Doesn't that render the ternary operator IF-statement unnecessary?
Have I been totally wrong using it in countless scripts of mine
(always thought it's a neat way to do if )?
Somebody please tell me that I do not have to rewrite my code base
now, since I care about security.

Btw. PHP's ternary inconsistency here ..
http://en.wikipedia.org/wiki/%3F:#Inconsistency_of_implementations

And how about this ..
switch(isset($_GET['search'])) {
case true:
$search = $_GET['search'];
break 1;

default:
$search = '';
}

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



Re: [PHP] Securing AJAX requests with PHP?

2008-10-18 Thread Yeti
Ok, but how safe are tokens?
Thinking of man in the middle attacks they do not make much sense, do they?

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



Re: [PHP] Re: what's the difference in the following code?

2008-10-18 Thread Yeti
I would understand it if it was like this ..

?php
$search = isset($_GET['search']) ? $_GET['search'] : '';
# versus
if (isset($_GET['search'])) { $search = $_GET['search']; }
?

In the first statement $search would either be set to $_GET['search']
or an empty string, whereas in the second statement $search would only
be set, if there is a $_GET['search']

//A yeti

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



Re: [PHP] Re: what's the difference in the following code?

2008-10-18 Thread Yeti
 Wrong. They are equivalent. The second is probably just easier to follow
 with a clearly defined default value outside the conditional block.

Well, leaving out the default value at the 2nd if statement makes a
difference and that's what I did.
Here is the code I changed again ..

Set to $_GET['search'] or an empty string
?php
$search = isset($_GET['search']) ? $_GET['search'] : '';
?

Only set if there is a $_GET['search']
?php
// no default value 
if (isset($_GET['search'])) $search = $_GET['search'];
?

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



Re: [PHP] Securing AJAX requests with PHP?

2008-10-17 Thread Yeti
but whose counting :-))

Someone is for sure. Maybe the scheduler?

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



Re: [PHP] Information on Cookies

2008-10-15 Thread Yeti
 You encrypt stuff with a string that you keep secret. That string is needed 
 to decrypt the string.
I recommend you change that string once in a while.

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



Re: [PHP] Pure PHP Templating Class/AJAX Problem

2008-10-14 Thread Yeti
Well after looking at the template thing you posted with your link it
seems to me like PHP is used to create working XML. So i wonder why
you are using AJAX here.
Now could it be that you use appendChild() ? That function would
simply add the XML again.

It's not easy to tell if you are not showing the JavaScript code ..
Still it simply depends on how you are importing the node you get from
XMLHttpRequest() or responseXML

Btw. importNode() is not working on all Browsers ..
Below is a code snipped I use for my AJAX class in JavaScript to copy
a node of one XML document (like from responseXML) into another. It
works in IE6+ and all W3C compliant browsers.
To make this work you will still have to make some ajustments.

xml_obj.prototype.xml_import_node = function(node, to_node,
all_children) { // cross browser importNode, NOTE: if toNode not
specified it will be set to current root_element
// appends node as a child to to_node
// if all_children is true then all child nodes will be imported too
/* NOTE TYPES:
ELEMENT_NODE = 1;
ATTRIBUTE_NODE = 2;
TEXT_NODE = 3;
CDATA_SECTION_NODE = 4;
ENTITY_REFERENCE_NODE = 5;
ENTITY_NODE = 6;
PROCESSING_INSTRUCTION_NODE = 7;
COMMENT_NODE = 8;
DOCUMENT_NODE = 9;
DOCUMENT_TYPE_NODE = 10;
DOCUMENT_FRAGMENT_NODE = 11;
NOTATION_NODE = 12;
*/
if (!node) return false;
if (!this.DOC) this.DOC = document;
if (!to_node.nodeType) {
if (!this.XML) return false;
try {
to_node = this.XML.documentElement;
this.DOC = this.XML;
} catch(e) {
return false;
}
}
try {
if (!node.nodeType) return false;
switch (node.nodeType) {
case 1: // new element
var new_node = 
this.DOC.createElement(node.nodeName);
if (node.attributes  
(node.attributes.length  0)) { // if it
has attributes
for (var count = 0; (count  
node.attributes.length); count++) {

this.xml_import_node(node.attributes[count], new_node);
}
}
if (all_children  (node.childNodes  
(node.childNodes.length 
0))) { // if child nodes
var dump = null;
for (var count = 0; (count  
node.childNodes.length); count++) {

this.xml_import_node(node.childNodes[count], new_node, true);
}
}
to_node.appendChild(new_node);
return new_node;
break;
case 2: // new attribute
var name = node.nodeName;
switch (node.nodeName.toLowerCase()) {
case 'onload':
case 'onunload':
case 'onblur':
case 'onclick':
case 'ondblclick':
case 'onfocus':
case 'onkeydown':
case 'onkeypress':
case 'onkeyup':
case 'onmousedown':
case 'onmousemove':
case 'onmouseout':
case 'onmouseover':
case 'onmouseup':
var eval_code = 
'to_node.'+node.nodeName.toLowerCase();
eval_code += ' = 
function() { '+node.nodeValue+' };';
eval(eval_code);
break;
case 'style':
to_node.style.cssText = 
node.nodeValue; // IE FIX
// no break
case 'class':
 

Re: [PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Yeti
Ok, so empty is faster. I appreciate the time you guys took to bench the thing.
But I'm still gonna use array_key_exists.
If you like it or not.
Using it a couple of times in my scripts will slow them down a few nanoseconds.
That's plain evil mwhahaha.

//A yeti

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



Re: [PHP] PHP to get File Type

2008-10-14 Thread Yeti
   function get_file_extension($file) {

http://us2.php.net/manual/en/function.pathinfo.php

?php
$path_parts = pathinfo('/www/htdocs/index.html');

echo $path_parts['dirname'], \n;
echo $path_parts['basename'], \n;
echo $path_parts['extension'], \n;
echo $path_parts['filename'], \n; // since PHP 5.2.0
?

Secondly the MIME type can differ from the extension (file suffix)
It's the same with uploaded files. Although the browser sends the MIME
type it might not be the right one, since browsers obtain the MIME by
checking the extension.

//A yeti

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



Re: [PHP] 1 last error to fix before the application is done!

2008-10-14 Thread Yeti
You might also want to try array_key_exists

if (array_key_exists('loggedin', $_SESSION['userInfo'])) {
// do something with $_SESSION['userInfo']['loggedin']
}

//A yeti

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



Re: [PHP] PHP to get File Type

2008-10-14 Thread Yeti
 Is there any function in PHP to get the file/Mime type of any file?
check this out:
http://us2.php.net/manual/en/function.finfo-open.php

//A yeti

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



Re: [PHP] Re: 1 last error to fix before the application is done!

2008-10-14 Thread Yeti
 Personally, I very rarely see the point in using array_key_exists... It's a 
 function call and has overhead where as isset() and empty() are language 
 constructs and (I would hope) are much more efficient (although I've not done 
 any benchmarks)

# i don't know what's wrong with this ..

$foo = array();
$foo['bar'] = null;
if (array_key_exists('bar', $foo)) {
 switch ($foo['bar']) {
  case true:
   //do something
   break 1;
  default:
   //do something else
}
}

# if that's causing more overhead then let me see your benchmark, then
i believe it

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



Re: [PHP] RewriteRule

2008-10-13 Thread Yeti
 What's the point of using '{0,}' instead '*' ?

Well the thing is that with the {0,} more REQUEST_URIs are valid:
eg.
/blog
/blog/
/blog/17
/blog/17/
/blog/17/0
/blog/17/0/

AND additional characters get ignored (like when it is necessary to
reload content with javascript, due to caching issues)

/blog/17/0/ignored_string

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



Re: [PHP] RewriteRule

2008-10-13 Thread Yeti
Jessen wrote:
RewriteRule ^blog/([^/]+)/([^/]+)/ blog.php?getparam1=$1getparam2=$2 
[NC,QSA,L]

Of course, your truely does what the OP asked for + it cuts of all
strings after the last /

/A yeti

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



Re: [PHP] RewriteRule

2008-10-13 Thread Yeti
You are absoloodle right about that. Although I'm not sure about their
greediness, which might be different.
I prefer the '{0,}' in my rewrite rules because I usually define the
max-length to prevent code injection.

eg.

# to make sure only the first 8 chars get passed on to PHP
RewriteRule ^blog/([^/]{0,8} index.php?a=$1 [NC,QSA,L]

So that's why they ended up in my reply.

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



  1   2   >