php-general Digest 20 Apr 2009 15:21:36 -0000 Issue 6077

Topics (messages 291671 through 291698):

Re: DATE / strtotime
        291671 by: Chris
        291672 by: Jim Lucas
        291674 by: Ron Piggott

Re: pup
        291673 by: ramesh.marimuthu.wipro.com
        291675 by: Jim Lucas

Re: How do I access a local variable?
        291676 by: Ashley Sheridan

Resampling images -- need lock ?
        291677 by: Martin Zvarík
        291678 by: kranthi
        291679 by: Martin Zvarík
        291680 by: kranthi
        291691 by: Martin Zvarík
        291692 by: Alpár Török
        291697 by: Bob McConnell

Re: cURL - Error 400
        291681 by: haliphax
        291682 by: David

Re: niewbie - call methods from another class
        291683 by: Philip Thompson

800 pound gorilla
        291684 by: Marc Christopher Hall
        291685 by: Daniel Brown
        291686 by: Philip Thompson
        291687 by: Marc Christopher Hall
        291688 by: Daniel Brown
        291689 by: bruce
        291690 by: Bob McConnell
        291693 by: Marc Christopher Hall
        291694 by: Lists
        291695 by: Bob McConnell
        291696 by: Bastien Koert

Re: escape your variables
        291698 by: PJ

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 ---
Ron Piggott wrote:
Where $date_reference is 2009-04-18 the following code gives me a day of
1969-12-30. How do I get it to be 2009-04-17? $previous_date = strtotime("-1 days", $date_reference); $previous_date = date('Y-m-d', $previous_date);

Slightly wrong syntax.

$previous_date = strtotime("$date_reference -1 days");

--
Postgresql & php tutorials
http://www.designmagick.com/


--- End Message ---
--- Begin Message ---
Ron Piggott wrote:
Where $date_reference is 2009-04-18 the following code gives me a day of
1969-12-30. How do I get it to be 2009-04-17? $previous_date = strtotime("-1 days", $date_reference); $previous_date = date('Y-m-d', $previous_date);

echo $previous_date;   outputs 1969-12-30

Ron



You need to read the strtotime page in the manual.

http://php.net/strtotime

It says that the second argument of the strtotime function is suppose to be a 
unix time stamp.

Is the value that you gave us for $date_reference a unix time stamp?  No

Your code should be like this.

// This converts 2009-04-19 00:00:00 into 1240099200
$date_reference_unix = strtotime($date_reference);
$previous_date = strtotime("-1 days", $date_reference_unix);
$previous_date = date('Y-m-d', $previous_date);

echo $previous_date;   outputs 1969-12-30


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
Thanks Chris.  It has been a while since I used this command.  Ron


On Mon, 2009-04-20 at 13:27 +1000, Chris wrote:

> Ron Piggott wrote:
> > Where $date_reference is 2009-04-18 the following code gives me a day of
> > 1969-12-30. How do I get it to be 2009-04-17? 
> > 
> > $previous_date = strtotime("-1 days", $date_reference); 
> > $previous_date = date('Y-m-d', $previous_date);
> 
> Slightly wrong syntax.
> 
> $previous_date = strtotime("$date_reference -1 days");
> 

--- End Message ---
--- Begin Message ---
Thanks for your idea.

-----Original Message-----
From: Phpster [mailto:phps...@gmail.com]
Sent: Friday, April 17, 2009 5:39 PM
To: Ramesh Marimuthu (WT01 - Telecom Equipment)
Cc: <li...@cmsws.com>; <geek...@gmail.com>; <php-gene...@lists.php.net>
Subject: Re: [PHP] pup



On Apr 17, 2009, at 1:06, <ramesh.marimu...@wipro.com> wrote:

>
> Thanks Jim. Is there a way to get the value of that unchecked box?
>
> -rummy
>
> -----Original Message-----
> From: Jim Lucas [mailto:li...@cmsws.com]
> Sent: Friday, April 17, 2009 10:35 AM
> To: Ramesh Marimuthu (WT01 - Telecom Equipment)
> Cc: geek...@gmail.com; php-gene...@lists.php.net
> Subject: Re: [PHP] pup
>
> ramesh.marimu...@wipro.com wrote:
>>
>> Hi,
>>
>> I'm new to php.
>> Say I have a check box which is checked already. Now I need to
>> uncheck
>
>> it and when I press the submit button, I should get the unchecked
> value.
>> Can anyone help me on this.
>>
>> One.php
>>
>> if($qry[0]!=$login_type)
>> {
>> echo "<td class=tabhead align=center
>> style=background-color:#CC66CC><input type=checkbox name=disable
>> value=a".$count." checked DISABLED /></br>".$slot_value."</td>"; }
>> else { echo "<td class=tabhead align=center
>> style=background-color:#00CCCC><input type=checkbox name=enable[]
>> value='--user ".$slot_value." --ne ".$nen." --timespec ".$slt."'
>> checked
>>> </br>".$slot_value."</td>";
>> }
>>
>> One.php calls Two.php
>> Two.php
>>
>> $enable_slot= $_POST['enable'];
>> $uncheck_slot= $_POST['uncheck'];
>>
>> if ($enable_slot){
>> echo "$enable_slot";
>> foreach($enable_slot as &$a) {
>> echo "<p>".$a." --unreserve</p>";
>> }
>> }
>>
>> I get only the results only if checked. I think I'm doing a mistake
>> in
>
>> the code in red font.
>>
>> regards,
>> -rummy
>>
>>
>
> When you uncheck a checkbox in an HTML form, it will not be submitted.
>
> http://www.w3.org/TR/html401/interact/forms.html#checkbox
>
> The part on the above page talking about "only "on" checkbox controls
> can become successful." is the key here.
>
> The successful part links here:
>
> http://www.w3.org/TR/html401/interact/forms.html#successful-controls
>
> This explains that the definition of a successful checkbox submission
> is one that is  "on".
> To have a checkbox in the "on" state means that it has to be checked.
>
> So, any checkbox that is /not/ checked is considered "off" or
> "undefined" will not be submitted because it is not valid.
>
> Or something like that... :)
>
> Jim Lucas
>
> Please do not print this email unless it is absolutely necessary.
>
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of the
> addressee(s) and may contain proprietary, confidential or privileged
> information. If you are not the intended recipient, you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately and destroy all copies of this message and any
> attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient
> should check this email and any attachments for the presence of
> viruses. The company accepts no liability for any damage caused by any

> virus transmitted by this email.
>
> www.wipro.com
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
>


What I do in this case is define it to unchecked in the php code and
then use the ternary operator to test it


$checkbox1 = 0;

$checkbox1 = (isset($_POST['check1'])) ? 1: 0 ;

Bastien

Please do not print this email unless it is absolutely necessary.

The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email.

www.wipro.com

--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
On Fri, 2009-04-17 at 12:54 -0400, Bob McConnell wrote:
From: tedd
At 10:43 PM -0700 4/16/09, Jim Lucas wrote:
Have your elements setup like such:

<input type="checkbox" name="reserve[rm1]" value="yes" /> Room #1
<input type="checkbox" name="reserve[rm2]" value="yes" /> Room #2
<input type="checkbox" name="reserve[rm3]" value="yes" /> Room #3
<input type="checkbox" name="reserve[rm4]" value="yes" /> Room #4
<input type="checkbox" name="reserve[rm5]" value="yes" /> Room #5

Then on your processing page, you know that you have 5 rooms, 1 - 5.

With this information you can check to make sure that something
exists
<?php
$rooms = range(1,5);
for ( $i = 1; $i <= 5; $i++ ) {
        if ( isset( $_POST['reserve']['rm'.$i] ) {
                # Room was checked
        } else {
                # Room was NOT checked.
        }
}
?>
Jim et al:

Try this:

<input type="checkbox" name="reserve[1]" > Room #1
<input type="checkbox" name="reserve[2]" > Room #2
<input type="checkbox" name="reserve[3]" > Room #3
<input type="checkbox" name="reserve[4]" > Room #4
<input type="checkbox" name="reserve[5]" > Room #5


if (isset($_POST['reserve']) )
    {
    foreach ($_POST['reserve'] as $key => $a)
       {
       echo("$key $a <br />");
       }
    }

Here's the demo:

http://www.webbytedd.com/bbbb/post-array1/index.php

Don't forget the </input> on the end of those input lines. I've seen too
many pages already where I had to fix that problem.

Bob McConnell

It shouldn't really be

<input type="checkbox" name="reserve[1]"> Room #1</input>

but something like this:

<label><input type="checkbox" name="reserve[1]"> Room #1</label>


Well, to quote the W3C Recommendation...
http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1

<FORM action="..." method="post">
<TABLE>
  <TR>
    <TD><LABEL for="fname">First Name</LABEL>
    <TD><INPUT type="text" name="firstname" id="fname">
  <TR>
    <TD><LABEL for="lname">Last Name</LABEL>
    <TD><INPUT type="text" name="lastname" id="lname">
</TABLE>
</FORM>

The label tag should reference the input via the for attribute.  Identifying 
the input tag by id attribute value.

And using the for attribute of the label tag in conjunction with the id
attribute of the input tag, you can separate the label and form element
entirely, which is sueful if you still use tables to line up your
forms!

Ash
www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Sun, 2009-04-19 at 21:55 -0400, Paul M Foster wrote:
> On Mon, Apr 20, 2009 at 12:54:27AM +0100, abdulazeez alugo wrote:
> 
> > 
> > Hi guys,
> > 
> > I have a function inside which I set alocal variable to store a result. Can 
> > I access this variable in another function? if yes then how?
> > 
> > function tbl1($entrytitle, $entrytext)
> > 
> > {
> > 
> > global $conn;
> > 
> > $result= mysql_query("INSERT INTO tbl1(tbl1_id, title, text)
> > 
> >      VALUES('NULL', '$entrytitle', '$entrytext')", $conn);
> > 
> >      $tbl_id=mysql_insert_id($conn);// this is the local variable I'm 
> > setting to get the last auto increment id
> > 
> > } 
> > 
> >  
> > 
> > Now I wish to access that variable in another function thus:
> > 
> > function tbl2($name, $entrytitle, $entrytext)
> > 
> > {
> > 
> > global $conn;
> > 
> > $result =mysql_query("INSERT INTO tbl2(tbl1_id, name, title, text)
> > 
> >                                VALUES('$tbl1_id', '$name', '$entrytitle', 
> > '$entrytext' )", $Conn); 
> > 
> > }
> > 
> >  
> > 
> > Or is there a better way to store the variable?
> 
> If a variable is local to a function, there is no way to access that
> variable outside that function. You can pass it back as a return value
> from the original function, or make it global (not advised) to make it
> visible in other functions.
> 
> Paul
> 
> -- 
> Paul M. Foster
> 

Or pass it by reference to the functions, so that both are able to make
changes to it.



Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
I have 10 images of different sizes.

If user clicks ROTATE, a script will go through all these 10 images and rotates them.

If the user clicks TWICE, the first script will get aborted in the middle (so few images are already rotated) and then the second request will rotate all of them again.

I probably need to write a script that would lock the first file and if this file is already locked it would just die('already working...')

Is this a good approach?

I know I can use javascript to disable second click, but I want it server side.


Thanks for your suggestions,
Martin

--- End Message ---
--- Begin Message ---
yeh. if u want it to be on server side that is a good approach. but i
feel it'll be very easy to do it with javascript...

but what i did not understand is: what should happen if the user
clicks ROTATE second time(when the script completed rotating say 5
images)?

--- End Message ---
--- Begin Message ---
kranthi napsal(a):
yeh. if u want it to be on server side that is a good approach. but i
feel it'll be very easy to do it with javascript...

but what i did not understand is: what should happen if the user
clicks ROTATE second time(when the script completed rotating say 5
images)?
Well, few images (etc. 5) got rotated +90 deg. and then the script got aborted, because of the second request, which will cause another +90 deg rotation again on all images = meaning those 5 will be again rotated +90 = 180, the others stay 90.
--- End Message ---
--- Begin Message ---
then u'll b needing a lock (a shared resource like a SESSION var will
do) even if u do it by javascript

--- End Message ---
--- Begin Message ---
I see...

I will need this too:
ignore_user_abort(true);


kranthi napsal(a):
i dont think flock will help in this case..
flock will b of help when u want to lock a particular file(to
read/write) but it'll not help u to stop execution of a php script


--- End Message ---
--- Begin Message ---
2009/4/20 kranthi <kranthi...@gmail.com>:
> then u'll b needing a lock (a shared resource like a SESSION var will
> do) even if u do it by javascript
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Session variables will not solve race conditions. I would either
ignore the user abort, so script doesn't abort, you can use file
locks, to make sure the scripts  don't  modify it at the same time

-- 
Alpar Torok

--- End Message ---
--- Begin Message ---
From: Martin Zvarík
> kranthi napsal(a):
>> yeh. if u want it to be on server side that is a good approach. but i
>> feel it'll be very easy to do it with javascript...
>>
>> but what i did not understand is: what should happen if the user
>> clicks ROTATE second time(when the script completed rotating say 5
>> images)?
>> 
> Well, few images (etc. 5) got rotated +90 deg. and then the script got 
> aborted, because of the second request, which will cause another +90 deg 
> rotation again on all images = meaning those 5 will be again rotated +90 
> = 180, the others stay 90.

That's what did happen. But what _should_ happen? Should it abort the first 
rotate, or finish all images then rotate each a second time? The code will have 
to be different depending on which option you want.

Bob McConnell

--- End Message ---
--- Begin Message ---
On Fri, Apr 17, 2009 at 7:58 AM, David <quick.webmas...@gmail.com> wrote:
> On Fri, Apr 17, 2009 at 8:55 PM, Andrew Ballard <aball...@gmail.com> wrote:
>>
>> On Fri, Apr 17, 2009 at 12:41 AM, David <quick.webmas...@gmail.com> wrote:
>> > On Thu, Apr 16, 2009 at 11:48 PM, haliphax <halip...@gmail.com> wrote:
>> >
>> >> On Wed, Apr 15, 2009 at 9:17 PM, David <quick.webmas...@gmail.com>
>> >> wrote:
>> >> > Except I also need to POST data to the server to login. After I've
>> >> > logged
>> >> > in, I then need to use cookies to maintain a session.
>> >> >
>> >> > Doing that via file_get_contents() just isn't possible.
>> >> >
>> >> >
>> >> > Thanks
>> >> >
>> >> > On Thu, Apr 16, 2009 at 2:30 AM, haliphax <halip...@gmail.com> wrote:
>> >> >>
>> >> >> On Wed, Apr 15, 2009 at 10:36 AM, David <quick.webmas...@gmail.com>
>> >> wrote:
>> >> >> > I was wondering if anyone could please help me with this cURL
>> >> >> > script
>> >> >> > since I
>> >> >> > keep getting error 400 from the web server:
>> >> >> >
>> >> >> > http://pastebin.ca/1392840
>> >> >> >
>> >> >> > It worked until around a month ago which is when they presumably
>> >> >> > made
>> >> >> > changes to the site. Except I can't figure out what configuration
>> >> option
>> >> >> > in
>> >> >> > the cURL PHP script needs to be changed. I can visit the site
>> >> perfectly
>> >> >> > in
>> >> >> > Lynx, Firefox and IE.
>> >> >>
>> >> >> Are you just trying to get the contents of the page, or is there
>> >> >> something special you're doing? If it's just the contents you're
>> >> >> after, try file_get_contents() if allow_url_fopen is set to TRUE for
>> >> >> your PHP installation.
>> >> >>
>> >> >> http://php.net/file_get_contents
>> >> >> http://php.net/allow_url_fopen
>> >>
>> >> David, please refrain from top-posting.
>> >>
>> >> As for cURL login/session handling... I have an automated script that
>> >> connects to a phpBB bulletin board, and here are the settings that
>> >> have worked for me:
>> >>
>> >> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
>> >> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>> >> curl_setopt($ch, CURLOPT_COOKIESESSION, true);
>> >> curl_setopt($ch, CURLOPT_HEADER, false);
>> >> curl_setopt($ch, CURLOPT_COOKIEFILE, "{$homedir}cookiefile");
>> >> curl_setopt($ch, CURLOPT_COOKIEJAR, "{$homedir}cookiefile");
>> >> curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
>> >>
>> >> I would think CURLOPT_FOLLOWLOCATION and the CURLOPT_COOKIE* options
>> >> are most important for resolving your issue.
>> >>
>> >> HTH,
>> >>
>> >>
>> >> --
>> >> // Todd
>> >>
>> >
>>
>> > Hi,
>> >
>> > Sorry, that didn't work. The website is still returning error 400 with
>> > CURLOPT_COOKIESESSION and CURLOPT_COOKIE enabled.
>> >
>> > I did some experimentation in Firefox by blocking and deleting all
>> > cookies
>> > from the site. When I then visited the site, I was able to reach the
>> > logon
>> > page without returning error 400 so I doubt it's cookies that is the
>> > problem.
>> >
>> > I also tried changing the HTTP headers to:
>> >
>> > Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
>> > Connection: Keep-Alive
>> > Content-Type: text/html; charset=UTF-8
>> >
>> > Which didn't work either.
>> >
>> >
>> >
>> >
>> > Thanks
>> >
>>
>> Does the site require a valid HTTP_REFERER? I haven't seen
>> CURLOPT_REFERER in any of your examples. (If I missed it somewhere,
>> just ignore the noise.)

Have you set your CURLOPT_COOKIEFILE properly? Also--you may need to
unlink() it before you log-in using your cURL script to make sure that
any invalid cookie values (i.e., expired session ID) are cleared out.

unlink("{$homedir}cookiefile");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "{$homedir}cookiefile");
curl_setopt($ch, CURLOPT_COOKIEJAR, "{$homedir}cookiefile");
curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
...

(where $homedir is "/home/haliphax/" or some such value.)

HTH,


-- 
// Todd

--- End Message ---
--- Begin Message ---
On Mon, Apr 20, 2009 at 9:35 PM, haliphax <halip...@gmail.com> wrote:

> On Fri, Apr 17, 2009 at 7:58 AM, David <quick.webmas...@gmail.com> wrote:
> > On Fri, Apr 17, 2009 at 8:55 PM, Andrew Ballard <aball...@gmail.com>
> wrote:
> >>
> >> On Fri, Apr 17, 2009 at 12:41 AM, David <quick.webmas...@gmail.com>
> wrote:
> >> > On Thu, Apr 16, 2009 at 11:48 PM, haliphax <halip...@gmail.com>
> wrote:
> >> >
> >> >> On Wed, Apr 15, 2009 at 9:17 PM, David <quick.webmas...@gmail.com>
> >> >> wrote:
> >> >> > Except I also need to POST data to the server to login. After I've
> >> >> > logged
> >> >> > in, I then need to use cookies to maintain a session.
> >> >> >
> >> >> > Doing that via file_get_contents() just isn't possible.
> >> >> >
> >> >> >
> >> >> > Thanks
> >> >> >
> >> >> > On Thu, Apr 16, 2009 at 2:30 AM, haliphax <halip...@gmail.com>
> wrote:
> >> >> >>
> >> >> >> On Wed, Apr 15, 2009 at 10:36 AM, David <
> quick.webmas...@gmail.com>
> >> >> wrote:
> >> >> >> > I was wondering if anyone could please help me with this cURL
> >> >> >> > script
> >> >> >> > since I
> >> >> >> > keep getting error 400 from the web server:
> >> >> >> >
> >> >> >> > http://pastebin.ca/1392840
> >> >> >> >
> >> >> >> > It worked until around a month ago which is when they presumably
> >> >> >> > made
> >> >> >> > changes to the site. Except I can't figure out what
> configuration
> >> >> option
> >> >> >> > in
> >> >> >> > the cURL PHP script needs to be changed. I can visit the site
> >> >> perfectly
> >> >> >> > in
> >> >> >> > Lynx, Firefox and IE.
> >> >> >>
> >> >> >> Are you just trying to get the contents of the page, or is there
> >> >> >> something special you're doing? If it's just the contents you're
> >> >> >> after, try file_get_contents() if allow_url_fopen is set to TRUE
> for
> >> >> >> your PHP installation.
> >> >> >>
> >> >> >> http://php.net/file_get_contents
> >> >> >> http://php.net/allow_url_fopen
> >> >>
> >> >> David, please refrain from top-posting.
> >> >>
> >> >> As for cURL login/session handling... I have an automated script that
> >> >> connects to a phpBB bulletin board, and here are the settings that
> >> >> have worked for me:
> >> >>
> >> >> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
> >> >> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> >> >> curl_setopt($ch, CURLOPT_COOKIESESSION, true);
> >> >> curl_setopt($ch, CURLOPT_HEADER, false);
> >> >> curl_setopt($ch, CURLOPT_COOKIEFILE, "{$homedir}cookiefile");
> >> >> curl_setopt($ch, CURLOPT_COOKIEJAR, "{$homedir}cookiefile");
> >> >> curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' .
> session_id());
> >> >>
> >> >> I would think CURLOPT_FOLLOWLOCATION and the CURLOPT_COOKIE* options
> >> >> are most important for resolving your issue.
> >> >>
> >> >> HTH,
> >> >>
> >> >>
> >> >> --
> >> >> // Todd
> >> >>
> >> >
> >>
> >> > Hi,
> >> >
> >> > Sorry, that didn't work. The website is still returning error 400 with
> >> > CURLOPT_COOKIESESSION and CURLOPT_COOKIE enabled.
> >> >
> >> > I did some experimentation in Firefox by blocking and deleting all
> >> > cookies
> >> > from the site. When I then visited the site, I was able to reach the
> >> > logon
> >> > page without returning error 400 so I doubt it's cookies that is the
> >> > problem.
> >> >
> >> > I also tried changing the HTTP headers to:
> >> >
> >> > Accept:
> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
> >> > Connection: Keep-Alive
> >> > Content-Type: text/html; charset=UTF-8
> >> >
> >> > Which didn't work either.
> >> >
> >> >
> >> >
> >> >
> >> > Thanks
> >> >
> >>
> >> Does the site require a valid HTTP_REFERER? I haven't seen
> >> CURLOPT_REFERER in any of your examples. (If I missed it somewhere,
> >> just ignore the noise.)
>
> Have you set your CURLOPT_COOKIEFILE properly? Also--you may need to
> unlink() it before you log-in using your cURL script to make sure that
> any invalid cookie values (i.e., expired session ID) are cleared out.
>
> unlink("{$homedir}cookiefile");
> curl_setopt($ch, CURLOPT_COOKIESESSION, true);
> curl_setopt($ch, CURLOPT_COOKIEFILE, "{$homedir}cookiefile");
> curl_setopt($ch, CURLOPT_COOKIEJAR, "{$homedir}cookiefile");
> curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
> ...
>
> (where $homedir is "/home/haliphax/" or some such value.)
>
> HTH,
>
>
> --
> // Todd
>

Hi,

The cookie file is currently empty but when I delete it, a new one is
created once the script is ran.



Thanks

--- End Message ---
--- Begin Message ---
On Apr 19, 2009, at 9:43 AM, MEM wrote:

Hello, I have something like this:

$stmt = $this->_dbh->prepare("INSERT INTO DOG (name_dog, race_dog, id_vet)
VALUES (?, ?, ?)");

            $stmt->bindParam(1, $this->getNameDog() );
            $stmt->bindParam(2, $this->getRaceDog());
            $stmt->bindParam(3, ????????????????????);


            $stmt->execute();
      }

To make this insert function work, I need to fill the id_vet database column
with some values.
I cannot use $this->getIdVet() because this method is not in dog class, is
on the veterinary class.
So my question is:
How can I access the getIdVet() that is on the veterinary class to put it on
the insert dog method?


Thanks a lot,
Márcio

Try this....

<?php
class veterinary {
    public function getIdVet () {
        return $this->id;
    }
}

class dog {
    public function add () {
        $vet = new veterinary ();

$stmt = $this->_dbh->prepare("INSERT INTO DOG (name_dog, race_dog, id_vet) VALUES (?, ?, ?)");

        $stmt->bindParam(1, $this->getNameDog());
        $stmt->bindParam(2, $this->getRaceDog());
        $stmt->bindParam(3, $vet->getIdVet());
        $stmt->execute();
    }
}
?>

Of course here you will have to determine how the vet id is set. The method getIdVet has a redundant name. Since it's already in the veterinary class, just use getId() or id(). However, you'll probably want to change the above implementation to not create the veterinary in the add() method. You'll probably want to create it in the dog constructor...

<?php
class dog {
    public function __construct ($vetId) {
        $this->vet = new veterinary ($vetId);
    }
    ...
}
?>

And use $this->vet instead of $vet in the dog->add() method. Hope that helps. Do a little reading to try to understand using objects a little bit more.....

http://php.net/object

~Philip


--- End Message ---
--- Begin Message ---
Sun buys MySQL and now Oracle buys Sun (not final, yet). What will happen
with the main db we PHP'ers have come to know and love especially since v 5


--- End Message ---
--- Begin Message ---
On Mon, Apr 20, 2009 at 09:48, Marc Christopher Hall
<m...@hallmarcwebsites.com> wrote:
> Sun buys MySQL and now Oracle buys Sun (not final, yet). What will happen
> with the main db we PHP'ers have come to know and love especially since v 5

    Become a MySQL developer and help make the decision.

-- 
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000

--- End Message ---
--- Begin Message ---
On Apr 20, 2009, at 8:48 AM, Marc Christopher Hall wrote:

Sun buys MySQL and now Oracle buys Sun (not final, yet). What will happen with the main db we PHP'ers have come to know and love especially since v 5

Probably nothing. It would not behoove Oracle to get rid of or significantly modify MySQL. It appears that Oracle will just get richer... =D

~Philip

--- End Message ---
--- Begin Message ---

-----Original Message-----
From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel
Brown
Sent: Monday, April 20, 2009 9:52 AM
To: Marc Christopher Hall
Cc: php-gene...@lists.php.net
Subject: Re: [PHP] 800 pound gorilla

On Mon, Apr 20, 2009 at 09:48, Marc Christopher Hall
<m...@hallmarcwebsites.com> wrote:
> Sun buys MySQL and now Oracle buys Sun (not final, yet). What will happen
> with the main db we PHP'ers have come to know and love especially since v
5

    Become a MySQL developer and help make the decision.

-- 
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000


Ahhh, I love the smell of condescension first thing in the morning. BTW I am
a MySQL developer thank you. A developer does not an owner make. Where do
you get the idea that Oracle would put this to a democratic vote?


--- End Message ---
--- Begin Message ---
On Mon, Apr 20, 2009 at 09:58, Marc Christopher Hall
<m...@hallmarcwebsites.com> wrote:
>
> Ahhh, I love the smell of condescension first thing in the morning. BTW I am
> a MySQL developer thank you. A developer does not an owner make. Where do
> you get the idea that Oracle would put this to a democratic vote?

    Condescension?  From where do you gather your "intelligence,"
Marc.  It was a suggestion.  And in the years that I've been a
developer, today is the first time I've seen your name.  Further, a
developer of an open source project understands a key word: fork.

    Good luck with your future banter.

-- 
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000

--- End Message ---
--- Begin Message ---
hmmm...

a developer might not (won't) give you voting rights? (is there sucj a
thing!!!)

however, if you put together a number of really skilled c/c++ (whatever)
developers, then you could easily take the current existing sourcebase of
code, and go ahead and fork your own version, and never need to worry about
what oracle is going to do with the current tree...

of course i'd have a better chance of winning the lottery!! but stranger
thing have happened...

but you should also remember that some major companies are using mysql for
various projects, and they could/might get together to form a dev core team
to keep it moving...

peace..


-----Original Message-----
From: Marc Christopher Hall [mailto:m...@hallmarcwebsites.com]
Sent: Monday, April 20, 2009 6:58 AM
To: 'Daniel Brown'
Cc: php-gene...@lists.php.net
Subject: RE: [PHP] 800 pound gorilla




-----Original Message-----
From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel
Brown
Sent: Monday, April 20, 2009 9:52 AM
To: Marc Christopher Hall
Cc: php-gene...@lists.php.net
Subject: Re: [PHP] 800 pound gorilla

On Mon, Apr 20, 2009 at 09:48, Marc Christopher Hall
<m...@hallmarcwebsites.com> wrote:
> Sun buys MySQL and now Oracle buys Sun (not final, yet). What will happen
> with the main db we PHP'ers have come to know and love especially since v
5

    Become a MySQL developer and help make the decision.

--
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000


Ahhh, I love the smell of condescension first thing in the morning. BTW I am
a MySQL developer thank you. A developer does not an owner make. Where do
you get the idea that Oracle would put this to a democratic vote?


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


--- End Message ---
--- Begin Message ---
From: Marc Christopher Hall
> 
> Sun buys MySQL and now Oracle buys Sun (not final, yet). What will
happen
> with the main db we PHP'ers have come to know and love especially
since v 5

Speak for yourself, I prefer PostgreSQL. But there are already two
announced forks of MySQL, created by developers that left after Sun
bought the company. So I don't think you'll be in any trouble. I did a
Google search last week on "executives departing MySQL" and found them.

Bob McConnell

--- End Message ---
--- Begin Message ---

-----Original Message-----
From: Bob McConnell [mailto:r...@cbord.com] 
Sent: Monday, April 20, 2009 9:59 AM
To: Marc Christopher Hall; php-gene...@lists.php.net
Subject: RE: [PHP] 800 pound gorilla

From: Marc Christopher Hall
> 
> Sun buys MySQL and now Oracle buys Sun (not final, yet). What will
happen
> with the main db we PHP'ers have come to know and love especially
since v 5

Speak for yourself, I prefer PostgreSQL. But there are already two
announced forks of MySQL, created by developers that left after Sun
bought the company. So I don't think you'll be in any trouble. I did a
Google search last week on "executives departing MySQL" and found them.

Bob McConnell




This being a PHP forum I will stand down on a performance/stability debate
over PostgreSQL and MySQL. These responses are what I was fishing for. My
gut reaction was "Not again!" and this time I initially feared a future axe
to MySQL. Upon further thought (and a few deep breaths) I agree that for the
near future, an immediate canning of MySQL would not be in Oracle's best
interest. However, since Oracle has been the competition and (I had no idea
other developers had already begun a fork of MySQL) I believe that Oracle
will close the door on MySQL eventually.

Time will tell. Meanwhile, back to work for me.

-Marc Hall


--- End Message ---
--- Begin Message ---
Marc Christopher Hall wrote:
Sun buys MySQL and now Oracle buys Sun (not final, yet). What will happen
with the main db we PHP'ers have come to know and love especially since v 5

Sorry Marc, meant to send this to the list...

I don't know what to think of this yet. Oracle has always competed with
the SQL architecture. Will they incorporate MySQL into their development.. or will they slowly can it in favor of their berkley architecture!?

Also, it seems to me that we may be losing a pillar of ingenuity and originality in our industry... perhaps one of the biggest oppositions to
Microsoft technologies [SUN].

Big news today!

Donovan


--
  =o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o
  D. BROOKE                       EUCA Design Center
                               WebDNA Software Corp.
  WEB:> http://www.euca.us  |   http://www.webdna.us
  =o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o

--- End Message ---
--- Begin Message ---
From: Marc Christopher Hall
> From: Bob McConnell
>> From: Marc Christopher Hall
>>> 
>>> Sun buys MySQL and now Oracle buys Sun (not final, yet). What will
>> happen
>>> with the main db we PHP'ers have come to know and love especially
>> since v 5
>>
>> But there are already two
>> announced forks of MySQL, created by developers that left after Sun
>> bought the company. So I don't think you'll be in any trouble. I did
a
>> Google search last week on "executives departing MySQL" and found
them.
> 
> 
> These responses are what I was fishing for. My
> gut reaction was "Not again!" and this time I initially feared a
future axe
> to MySQL. Upon further thought (and a few deep breaths) I agree that
for the
> near future, an immediate canning of MySQL would not be in Oracle's
best
> interest. However, since Oracle has been the competition and (I had no
idea
> other developers had already begun a fork of MySQL) I believe that
Oracle
> will close the door on MySQL eventually.

I don't think it makes any difference what Oracle does with it. I
believe most or all of the core source is available under the GPL. So it
will always be available. There is certainly enough interest in the
application that it will attract a number of talented developers no
matter who manages the process. So even if Oracle dumps it, it will
continue to exist in one or more forks. The only business issue will be
who can use the trademark.

On the other hand, there are some closed source utilities and components
that may have to be recreated for any forked version. After all, it was
the "Enterprise" package that was generating the revenue. That is the
only part of the product that Sun or Oracle could really control.

Bob McConnell

--- End Message ---
--- Begin Message ---
On Mon, Apr 20, 2009 at 10:42 AM, Bob McConnell <r...@cbord.com> wrote:

> From: Marc Christopher Hall
> > From: Bob McConnell
> >> From: Marc Christopher Hall
> >>>
> >>> Sun buys MySQL and now Oracle buys Sun (not final, yet). What will
> >> happen
> >>> with the main db we PHP'ers have come to know and love especially
> >> since v 5
> >>
> >> But there are already two
> >> announced forks of MySQL, created by developers that left after Sun
> >> bought the company. So I don't think you'll be in any trouble. I did
> a
> >> Google search last week on "executives departing MySQL" and found
> them.
> >
> >
> > These responses are what I was fishing for. My
> > gut reaction was "Not again!" and this time I initially feared a
> future axe
> > to MySQL. Upon further thought (and a few deep breaths) I agree that
> for the
> > near future, an immediate canning of MySQL would not be in Oracle's
> best
> > interest. However, since Oracle has been the competition and (I had no
> idea
> > other developers had already begun a fork of MySQL) I believe that
> Oracle
> > will close the door on MySQL eventually.
>
> I don't think it makes any difference what Oracle does with it. I
> believe most or all of the core source is available under the GPL. So it
> will always be available. There is certainly enough interest in the
> application that it will attract a number of talented developers no
> matter who manages the process. So even if Oracle dumps it, it will
> continue to exist in one or more forks. The only business issue will be
> who can use the trademark.
>
> On the other hand, there are some closed source utilities and components
> that may have to be recreated for any forked version. After all, it was
> the "Enterprise" package that was generating the revenue. That is the
> only part of the product that Sun or Oracle could really control.
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I think it will be interesting to watch. Oracle does use and support OS,
demonstrated nicely by bundling PHP into their application engine. MySQL
enterprise will nicely fill a hole in the lineup for SMB that Oracle has a
tough time supporting with the expensive enterprise class products.

Hopefully there won't be much change in the next few years, but I shall
remain hopeful that things will stay the current course

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
Bastien Koert wrote:
> On Wed, Feb 18, 2009 at 8:34 AM, PJ <af.gour...@videotron.ca> wrote:
>
>   
>> To focus on mysql_real_escape_string, I am recapping... questions below
>> QUOTE:==========
>> Instead of doing this (for an imaginary table):
>> $sql = "insert into table1(field1, field2) values ('$value1', '$value2')";
>>
>> do
>> $sql = "insert into table1(field1, field2) values ('" .
>> mysql_real_escape_string($value1) . "', '" .
>> mysql_real_escape_string($value2) . "')";
>>
>> Now $value1 and $value2 can only be used as data, they can't be used
>> against you.
>>
>> If you don't do that, try adding a last name of O'Reilly - your code
>> will break because of the ' in the name.
>>
>> When you say "escape all your inputs" - just what do you mean? Does that
>> mean I need some special routines that have to be repeated over and over
>> every time there is an input... but what do you mean by an "input"? And,
>> from looking at all the comments in the manual, it's not clear just
>> where to stop...
>>
>> "input" means anything a user gives you. Whether it's a first name, last
>> name, a comment in a blog, a website url - anything you get from a user
>> must be escaped.
>> END QUOTE ===============
>>
>> So, I am more confused than ever...
>>
>> TWO QUESTIONS:
>>
>> 1.  It seems to me that submitting username, password and database_name
>> is pretty dangerous.
>> How does one deal with that? Do you use mysql_real_escape_string?
>> e.g.
>> <?php
>> $db_host = 'localhost';
>> $db_user = 'auser';
>> $db_pwd = 'apassword';
>>
>> $database = 'adatabase';
>> $table = 'authorBook';
>>
>> if (!mysql_connect($db_host, $db_user, $db_pwd))
>>    die("Can't connect to database");
>>
>> if (!mysql_select_db($database))
>>    die("Can't select database");
>>
>> // sending query
>> $result = mysql_query("SELECT * FROM {$table}");
>>     
>
>
> Inputs are user supplied.
Are you saying that I don't need to sanitize the variables above -
$db_host, $db_user, $db_pwd, $database, $table ?
If they whould be sanitized, just when should that be done? Whlen the
variable is declared? or in the if stetements above and the $result ?

I would love to see an example somewhere that shows an unsanitized
variable and the same variable sanitized.

>  Variables coming from inside the application code
> are not really inputs. I prefer a two step approach to ensure that I am
> (hopefully) free from potential problems.
>
> 1. Use filtering like regex and length checks 
When and specifically on what?
> [
> http://ca2.php.net/manual/en/function.ereg.php]
> 2. Use mysql_real_escape_string in the query wherever the data is
> potentially harmful.
>
>
>
>
>   
>> 2. How do you use mysql_real_escape_string on a string entered in a form
>> page with input and $_POST where the inputs are strings like $titleIN,
>> $authorIN....etc.?
>>
>>     
>
> <?php
> $error = '';
> $title = ''; $authorIN='';  //initialize vars
>
> $title     = (eregi("^[a-z0-9\.\s]+$",$_POST['title'])) ? $_POST['title'] :
> $error .= "invalid title";
> $authorIN = (eregi("^[a-z\.\s]+$",$_POST['author'])) ? $_POST['author'] :
> $error .= "invalid author";
>
> $sql = "insert into table (title, author) values ('" .
> mysql_real_escape_string($title) . "','" .
> mysql_real_escape_string($authorIN) . "')";
>
> //rest of code
> ?>
>
>
>   
>> --
>>
>> Phil Jourdan --- p...@ptahhotep.com
>>   http://www.ptahhotep.com
>>   http://www.chiccantine.com
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>     
I quote from earlier in the post:

=========
Better:
myql_query("INSERT INTO foo (`name`) VALUES ('".
mysql_real_escape_string($name, $link) ."')");

This is better because we escape it in the sql statement itself.
$name remains unchanged in case we want to use it later.

Best:
Use prepared statements!
=========
What is meant by prepared stetements? Does that mean not using variables?

Another quote:
========

Better:
echo htmlspecialchars($name, ENT_QUOTES, 'UTF-8');

This is better because we don't trust the data at all.  You don't know
what it contains.  People find all sorts of interesting ways of
getting weird characters into the apps I write, so just cover all
bases.

Another way:
Create a pre-escaped version of the content in the db.  Keep the
original value so that the user can edit it, but also create a 'clean'
version that you can just echo out.  Just make sure you don't mess up.

=======

I'd like to be able to understand just what is meant by creating a
"pre-escaped version of the content in the db" - I'd like to see an example.
And what would the 'clean' version be, where would you put it or where
is it supposed to be placed?

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


--- End Message ---

Reply via email to