php-general Digest 15 May 2010 10:02:42 -0000 Issue 6745

Topics (messages 305228 through 305248):

Re: opening a link in a new window
        305228 by: Adam Richardson
        305229 by: Michiel Sikma
        305239 by: Andrew Ballard

PHP framework
        305230 by: jfmatos.electrex.pt
        305231 by: Ashley Sheridan
        305232 by: Augusto Flavio

Re: Question about creating php files from a form
        305233 by: Kevin
        305238 by: Lester Caine
        305245 by: Lawrance Shepstone

var_dump( (0 == 'heading') ) == TRUE ?!
        305234 by: Daevid Vincent
        305235 by: James Colannino
        305236 by: richard gray
        305237 by: kranthi

Re: Multiple Login in a single PC should not be possible
        305240 by: Jagdeep Singh
        305241 by: Robert Cummings
        305242 by: Lester Caine
        305243 by: Jagdeep Singh
        305244 by: Lester Caine
        305248 by: Ashley Sheridan

Re: create tree from arrays
        305246 by: shahrzad khorrami

Email with attachment
        305247 by: Php Developer

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Fri, May 14, 2010 at 4:49 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:

>  On Fri, 2010-05-14 at 13:18 -0400, Adam Richardson wrote:
>
> On Fri, May 14, 2010 at 8:59 AM, Andrew Ballard <aball...@gmail.com> wrote:
>
> > On Thu, May 13, 2010 at 5:18 PM, Ashley Sheridan
> > <a...@ashleysheridan.co.uk> wrote:
> > > On Thu, 2010-05-13 at 17:13 -0400, David Mehler wrote:
> > >
> > >> Hello,
> > >> I want to open an external link in a new window, i know i can do this
> > >> with xhtml, but only with the transitional dtd, which i'm not using. I
> > >> was wondering if php could pull this off?
> > >> Thanks.
> > >> Dave.
> > >>
> > >
> > >
> > > No. PHP is on the server, not the client-side. If you can't use
> > > something like target="_blank" in your xhtml, then consider using
> > > Javascript. It's not the ideal solution, as it won't work where
> > > scripting is disabled or not available.
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> >
> > It may or may not be the "ideal" solution, but I'm pretty sure it is
> > considered the "correct" solution going forward. I recall reading
> > somewhere that things like controlling the "target" for a link are
> > considered behavior rather than part of the document's semantic
> > structure, and therefore belong in scripting rather than markup under
> > XHTML. That makes sense given that one of the goals of XHTML is
> > structured documents that can be consumed by multiple services,
> > including but not exclusively web browsers.
> >
> > This also has the side effect that the decision of whether to open a
> > link in the current window or a new window/tab belongs to the viewer
> > instead of the author, which some argue is exactly as it should be.
> >
> > Andrew
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> I'd avoid the target attribute, as it's deprecated in the strict versions
> (and I'd avoid it for the reasons Andrew mentioned.)
>
> For reading, here's a nice resource to start 
> with:http://www.456bereastreet.com/archive/200603/the_target_attribute_and_opening_new_windows/
>
> Adam
>
>
>
> There are still valid reasons to use it. On my own site for example, and
> links which lead outside of my site open up in a new tab/window. I link to a
> lot of other external sites often in my blog entries, and I think it's valid
> that these links open up in new tabs/windows so that my site is left open
> when they read the rest of the article.
>
> I guess I could add some form of indication that the link will open up in a
> new window though.
>
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
The resource I suggested was focused on the use of the target attribute to
open a new window.

Yes, there are situations where opening a new window/tab are appropriate
(but, as you mentioned, you should always try to provide feedback that
clicking the link will open a new window.)  However, using javascript to
open new windows provides a solution that validates for both strict and
transitional documents AND separates behavior from content.

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On 14 May 2010 22:49, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:

>
> There are still valid reasons to use it. On my own site for example, and
> links which lead outside of my site open up in a new tab/window. I link
> to a lot of other external sites often in my blog entries, and I think
> it's valid that these links open up in new tabs/windows so that my site
> is left open when they read the rest of the article.
>
> I guess I could add some form of indication that the link will open up
> in a new window though.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
I don't entirely agree that the target attribute should be avoided, or that
you absolutely need to use Strict XHTML rather than Transitional. There
really aren't that many differences between them. Yes, a lot of legacy
elements were removed, but those that program in valid XHTML tend to not use
them anyway.

The real reason why target is a little ill-conceived is because not all
target devices are able to use it in a valid way, e.g. phones with simple
web browsers. But if it was never your intention to support those devices,
using Transitional and the target attribute really isn't an issue.

Michiel

--- End Message ---
--- Begin Message ---
>> On Fri, May 14, 2010 at 8:59 AM, Andrew Ballard <aball...@gmail.com> wrote:
>>
>> > This also has the side effect that the decision of whether to open a
>> > link in the current window or a new window/tab belongs to the viewer
>> > instead of the author, which some argue is exactly as it should be.
>> >
>> > Andrew

On Fri, May 14, 2010 at 4:49 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
> There are still valid reasons to use it. On my own site for example, and
> links which lead outside of my site open up in a new tab/window. I link
> to a lot of other external sites often in my blog entries, and I think
> it's valid that these links open up in new tabs/windows so that my site
> is left open when they read the rest of the article.
>
> I guess I could add some form of indication that the link will open up
> in a new window though.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

Obviously it is up to you as the site author, but then that was part
of the point I was trying to make above. Authors frequently make links
to "external" material open in a new window because they don't want
the user to navigate away from their own site. However, there are many
who would argue that the target of a link is a decision that belongs
to the viewer. In most browsers, one has the choice with any regular
link to either click it and open it in the same window/frame as the
referring document, or open the context menu (right-click, etc.) for
the link and open it in a new tab/window. If the site author specifies
target="_blank", the author has removed one of those options from the
viewer. I get annoyed by sites that use
href="javascript:window.open('someurl')" specifically because it
prevents me from choosing to open the link in a new tab.

Besides, as Adam said, more and more web browsing is being done on
mobile devices and other platforms that don't support multiple
"windows". In these environments, the idea of a link target no longer
has meaning.

For what it's worth, here is a sample page that shows one way to
address the OP's question of duplicating the functionality of "target"
on links while still being valid XHTML. And yeah ... I know someone
will blast me for how much code it took to duplicate a simple
target="_blank" attribute. :-) I didn't test it extensively (just
tried it in Firefox and IE7) but I believe it degrades pretty well, it
simulates target pretty closely, and it validates.

http://pastebin.com/Q3MrWBKi


Andrew

--- End Message ---
--- Begin Message ---
Greetings all!

I new in template engines and frameworks, can you advice me the best php
framework. Do you all use smarty? I need something that does MVC and
templates, and specialy that has a lot of web resources to see other uers
experiences and problems.

Regards,

Joao


--- End Message ---
--- Begin Message ---
On Sat, 2010-05-15 at 00:02 +0200, jfma...@electrex.pt wrote:

> Greetings all!
> 
> I new in template engines and frameworks, can you advice me the best php
> framework. Do you all use smarty? I need something that does MVC and
> templates, and specialy that has a lot of web resources to see other uers
> experiences and problems.
> 
> Regards,
> 
> Joao
> 
> 


CodeIgniter is probably the simplest to get to grips with as frameworks
go. It's my understanding that Smarty is more of a templating engine
than a framework.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
You can use the symfony. It's a great framework.



Bye.



Augusto Morais

--- End Message ---
--- Begin Message ---
Paul M Foster wrote:
On Thu, May 13, 2010 at 11:53:54PM -0400, Kevin wrote:

<snip>

/On a side note:
I am having some issues with connecting to a SQLite database right now
... I'm getting the following error "Fatal Error: 'sqlite_open' is an
unknown function"
But I'm putting that on the side right now.

I think the docs are still screwed up. Try sqlite3_open() instead and
see if that works. Also, check phpinfo() to see if the SQLite/SQLite3
modules are loaded.

Paul

Thanks Paul,
I tried with sqlite3_open() and it gave the same error.

--- End Message ---
--- Begin Message ---
Kevin wrote:
I am having some issues with connecting to a SQLite database right now
... I'm getting the following error "Fatal Error: 'sqlite_open' is an
unknown function"
But I'm putting that on the side right now.

I think the docs are still screwed up. Try sqlite3_open() instead and
see if that works. Also, check phpinfo() to see if the SQLite/SQLite3
modules are loaded.

I tried with sqlite3_open() and it gave the same error.

 THEN ... 'check phpinfo()'
Obviously sqlite extension is not actually loaded.
You don't aey which OS ... On windows there are a list of extensions in the php.ini file, just 'uncomment' the one(s) you need ...

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
Kevin wrote:
>>> I am having some issues with connecting to a SQLite database right now
>>> ... I'm getting the following error "Fatal Error: 'sqlite_open' is an
>>> unknown function"
>>> But I'm putting that on the side right now.
>>
>> I think the docs are still screwed up. Try sqlite3_open() instead and
>> see if that works. Also, check phpinfo() to see if the SQLite/SQLite3
>> modules are loaded.
>>
> I tried with sqlite3_open() and it gave the same error.

  THEN ... 'check phpinfo()'
Obviously sqlite extension is not actually loaded.
You don't aey which OS ... On windows there are a list of extensions in the 
php.ini file, just 'uncomment' the one(s) you need ...

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

__________________________________________________________________________

There is no sqlite3_open() - there is only an OOP interface for php_sqlite3.

I wrote to the list in frustration about this choice not too long ago, and
concluded that the only way to accomplish this is to:

1.) Use php-sqlite3 extension (not to be confused with the php_sqlite3 -
dash vs underscore) - but this isn't a great solution because it would mean
you would need to ask your host to enable a custom extension, which they
usually don't do. If you're hosting this app on your own server, then give
it a bash.

2.) Otherwise, get involved in PECL development and help give php_sqlite3 a
procedural interface.

Of course, if you're looking for basic database storage, then SQLite2
(php_sqlite) would work fine.

Best of luck,
Lawrance


--- End Message ---
--- Begin Message ---
Can someone explain why an integer 0 compared to a string evaluates to
boolean true??

var_dump( (0 == 'heading') );

Yet, 

var_dump( (1 == 'heading') );

Is FALSE.

WTF? I would expect the 0 one to be FALSE too.


--- End Message ---
--- Begin Message ---
I'm pretty sure this is the right answer.  If not, someone please
correct me.  PHP will compare the 0 against the integer represented by
the string.  So, for example, 0 == "0" would test true.  0 == "1" would
test false.  However, 'heading' doesn't represent a valid integer, so it
appears on the right hand side as just 0, which is equal to the left
hand side.

James

Daevid Vincent wrote:
> Can someone explain why an integer 0 compared to a string evaluates to
> boolean true??
> 
> var_dump( (0 == 'heading') );
> 
> Yet, 
> 
> var_dump( (1 == 'heading') );
> 
> Is FALSE.
> 
> WTF? I would expect the 0 one to be FALSE too.

--- End Message ---
--- Begin Message ---
On 15/05/2010 03:19, Daevid Vincent wrote:
Can someone explain why an integer 0 compared to a string evaluates to
boolean true??

var_dump( (0 == 'heading') );

Yet,

var_dump( (1 == 'heading') );

Is FALSE.

WTF? I would expect the 0 one to be FALSE too.

http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion

IMO this is a pretty well known gotcha of PHP - you need to use === to check type as well as value
Rich

--- End Message ---
--- Begin Message ---
== operator type casts the string to integer before comparing
so the comparison boils down to 0 == 0 which is true
these rules also apply to the switch statement
http://php.net/manual/en/language.operators.comparison.php

but with === the typecasting does no occur

--- End Message ---
--- Begin Message ---
Hi!

Thanks for all the replies... But may of the solutions are not for my
question.

Friends!

E.g. : If user1 has logged in Internet Explorer on IP adress (Say IP - A)
with MAC Adress (MAC-X)
Then No other user can login on that IP (IP-A) AND MAC Adress (MAC-X) on any
other browser say Firefox.

I can stop any user to login more than one time at two different machines..

But I am unable to stop Multiple logins on same machine (ofcourse on
different Browsers) Because each browser has different SESSION and Cookie
system.

I hope problem is very clear now..

regards

Jagdeep Singh

On Fri, May 14, 2010 at 9:51 PM, tedd <tedd.sperl...@gmail.com> wrote:

> At 12:48 PM +0530 5/14/10, Jagdeep Singh wrote:
>
>> Hi All!
>>
>> I am looking for a solution, I want a user to do a single Login only on a
>> PC
>> .
>>
>> E.g. If a User has logged on my website website.com in Internet explorer,
>> then he cant login on same website in another browser like Firefox etc
>> with
>> same loginid or another.
>>
>> Can I trace MAC address of a single machine to solve this issue?
>>
>> Or is there a concept of GLOBAL COOKIE / Cross Browser Cookie which will
>> work for all browsers in a single machine..
>>
>> I hope You will help me out
>>
>>
>> Regards
>>
>> Jagdeep Singh
>> +91 9988009272
>>
>
> Jagdeep:
>
> I don't think this is solvable.
>
> You can make it such that if a person is logged-in that they cannot log-in
> again until they log-out of their current session -- that's do able.
>
> But using IP addresses, or trying to sniff the machine, or other such
> attempts at identifying user will most certainly be problematic and not
> solve the problem.
>
> Good luck,
>
> tedd
>
> --
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>

--- End Message ---
--- Begin Message ---
Jagdeep Singh wrote:
Hi!

Thanks for all the replies... But may of the solutions are not for my
question.

Friends!

E.g. : If user1 has logged in Internet Explorer on IP adress (Say IP - A)
with MAC Adress (MAC-X)
Then No other user can login on that IP (IP-A) AND MAC Adress (MAC-X) on any
other browser say Firefox.

I can stop any user to login more than one time at two different machines..

But I am unable to stop Multiple logins on same machine (ofcourse on
different Browsers) Because each browser has different SESSION and Cookie
system.

I hope problem is very clear now..

Oh, I see... you don't even want 2 DIFFERENT users on the same computer to log in at the same time. Hah, you must be doing an online game or something. You cannot do what you want to do.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Jagdeep Singh wrote:
Hi!

Thanks for all the replies... But may of the solutions are not for my
question.

But I am unable to stop Multiple logins on same machine (ofcourse on
different Browsers) Because each browser has different SESSION and Cookie
system.

As I have already said ... you need to maintain a list of 'logged in' machines in addition to the 'logged in' users. You check any new login against the machine list as well as the user list.

You ARE right in that a different browser will not have the cookie settings, but in YOUR case, simply do not use browser based 'storage'. Store the settings so that authentication from a different browser will return the current logged in status. I'm not worried about different browsers, but if the browser 'connection' is lost, then reopening it and trying to log in again takes you back to the point where the connection was lost. Should work cross browser, and does work IE6 to IE7 or 8.

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
I am working on e-learning module...


On Sat, May 15, 2010 at 12:03 PM, Robert Cummings <rob...@interjinn.com>wrote:

> Jagdeep Singh wrote:
>
>> Hi!
>>
>> Thanks for all the replies... But may of the solutions are not for my
>> question.
>>
>> Friends!
>>
>> E.g. : If user1 has logged in Internet Explorer on IP adress (Say IP - A)
>> with MAC Adress (MAC-X)
>> Then No other user can login on that IP (IP-A) AND MAC Adress (MAC-X) on
>> any
>> other browser say Firefox.
>>
>> I can stop any user to login more than one time at two different
>> machines..
>>
>> But I am unable to stop Multiple logins on same machine (ofcourse on
>> different Browsers) Because each browser has different SESSION and Cookie
>> system.
>>
>> I hope problem is very clear now..
>>
>
> Oh, I see... you don't even want 2 DIFFERENT users on the same computer to
> log in at the same time. Hah, you must be doing an online game or something.
> You cannot do what you want to do.
>
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>

--- End Message ---
--- Begin Message ---
Jagdeep Singh wrote:
How can I define "Machine"?

That IS the problem. As with a lot of this stuff - nothing was ever actually DESIGNED to work :( So $_SERVER["REMOTE_ADDR"] will block multiple machines if they are sharing the one connection. I've been lucky so far in that 'REMOTE_ADDR' CAN be resolved to a machine in my own case.

This like 'tzoffset' is an area where the simplest basic functions actually need to be fixed. If you are working cross timezones have you considered the problem of knowing the right time where daylight saving is important. My users have to set their correct daylight saving zone in their profile. 'tzoffset' is no use.

Both of these are areas that need fixing?

( As an aside ... some schools are now using 'virtual' desktops, so several pupils may WELL be working on the one 'virtual server' but each in their own sessions. This makes it impossible to identify the individual users as well )

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
On Sat, 2010-05-15 at 08:18 +0100, Lester Caine wrote:

> Jagdeep Singh wrote:
> > How can I define "Machine"?
> 
> That IS the problem. As with a lot of this stuff - nothing was ever actually 
> DESIGNED to work :( So $_SERVER["REMOTE_ADDR"] will block multiple machines 
> if 
> they are sharing the one connection. I've been lucky so far in that 
> 'REMOTE_ADDR' CAN be resolved to a machine in my own case.
> 
> This like 'tzoffset' is an area where the simplest basic functions actually 
> need 
> to be fixed. If you are working cross timezones have you considered the 
> problem 
> of knowing the right time where daylight saving is important. My users have 
> to 
> set their correct daylight saving zone in their profile. 'tzoffset' is no use.
> 
> Both of these are areas that need fixing?
> 
> ( As an aside ... some schools are now using 'virtual' desktops, so several 
> pupils may WELL be working on the one 'virtual server' but each in their own 
> sessions. This makes it impossible to identify the individual users as well )
> 
> -- 
> Lester Caine - G8HFL
> -----------------------------
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
> 


I explained off-list how you could do this. Create a hash of the
machines IP and browser with the username of the logged in user:

md5($ip . $browser . $username);

And store that in the database when they log in. Now each time they
perform an action, create a hash from those same bits of information
again and check it against the one created when they logged in.

You can't access their Mac address. Many people on the list have
explained that to you now. I'm not sure why an e-learning module needs
such strict requirements, as it's perfectly valid that a user might want
to use more than one browser at a time.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Thanks to all, it works now:

    function mktree_array(&$arr, $id = 0)
    {
       $result = array();
       foreach ($arr as $a) {
           if ($id == $a['parentID']) {
               $a['children']  = $this->mktree_array($arr, $a['nid']);
               $result[] = $a;
           }
       }
       return $result;
    }


merci

Shahrzad ;)

--- End Message ---
--- Begin Message ---
Hi,

I found a good function at php.net that sends email with atachment, but 
unfortunately i still cannot figure out how to send a body of the email too. 
Here is the code:

function sendEmailWithAttachement($to, $subject, $message, $file)
{
  if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
    $eol="\r\n";
  } 
  elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
    $eol="\r";
  }
  else 
  {
    $eol="\n";
  } 
  $filename = basename($file);
  displaymessage($filename);
  $file_size = filesize($file);
  $file_type = filetype($file);
  displaymessage($file_size);
  $handle = fopen($file, "rb");
  $content = fread($handle, $file_size);
  $content = chunk_split(base64_encode($content));
  fclose($handle);
  # Common Headers
$headers = 'From: cont...@example.com'.$eol;
$headers .= 'Reply-To: cont...@example.com'.$eol;
$headers .= 'Return-Path: cont...@example.com'.$eol;     // these two to set 
reply address
$headers .= "Message-ID: <".time()." 
TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;           // These two to help 
avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; 
boundary=\"".$mime_boundary."\"".$eol;
$msg = "";

# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$file_type."; name=\"".$filename."\"".$eol;   // 
sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= $message;
$msg .= "Content-Disposition: attachment; 
filename=\"".$filename."\"".$eol.$eol; // !! This line needs TWO end of lines 
!! IMPORTANT !!
$msg .= $content.$eol.$eol;
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;

# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your 
email-reading-software.".$eol;
$msg .= "+ + Text Only + +".$eol.$eol; 

# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;   // finish with two eol's for 
better security. see Injection.
mail($to, $subject, $msg, $headers);
}




--- End Message ---

Reply via email to