php-general Digest 17 Aug 2009 05:24:10 -0000 Issue 6289

Topics (messages 296836 through 296865):

Re: Issue with the huge import script
        296836 by: Phpster

Re: How do I extract link text from anchor tag as well as the URL from the 
"href" attribute
        296837 by: chrysanhy
        296839 by: Ralph Deffke
        296840 by: Ralph Deffke
        296841 by: chrysanhy
        296842 by: chrysanhy
        296846 by: Ralph Deffke
        296847 by: Ralph Deffke
        296858 by: chrysanhy

Dan Brown
        296838 by: Angus Mann
        296844 by: Per Jessen

Cannot exec in my own directory
        296843 by: Dotan Cohen
        296845 by: Sudheer Satyanarayana
        296850 by: Dotan Cohen
        296852 by: Caner Bulut
        296856 by: Dotan Cohen

Sanitizing mysql inserts of user data
        296848 by: Dotan Cohen
        296851 by: Caner Bulut
        296853 by: Adam Randall
        296854 by: Dotan Cohen
        296855 by: Dotan Cohen

brainstorm/samples on _autoload() needed
        296849 by: Ralph Deffke

Re: Another date exercise
        296857 by: Paul M Foster
        296860 by: Ralph Deffke

running str_replace, it misbehaves!
        296859 by: Allen McCabe

<link> to a css file requires .css ???
        296861 by: Daniel Kolbo
        296862 by: Nitsan Bin-Nun
        296863 by: Daniel Kolbo
        296864 by: Adam Shannon

Re: File or directory?
        296865 by: George Langley

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---

On Aug 15, 2009, at 9:15 PM, Devendra Jadhav <[email protected]> wrote:

Hi,

I have to import data from one database to another, I have to import around
100000(1Lac) records.
First I need to check if the record is already imported or not and import
only those records which are not imported.

Here is my logic

$already_imported = get_already_imported_records();
format of the $already_imported is $already_imported[someid] = 'imported';

Now i take all records from another db and iterating through it.

if (!key_exists($already_imported[$new_id])){
       import_function($new_id)
}else{
       echo 'allready imported'.$already_imported[$new_id];
}

Now my script is importing same records for more than one time. I am not
able to get through this issue

Is it because of the size of the records or something else...?

Please suggest me some solution which is faster, safe and easy to code :D

Thanks in advance

--
Devendra Jadhav

What are the databases? Both mysql? Or different systems? How do you define whether the record exists?

Are you running into timeout issues? If so, one trick is to write the page to process 100 or so records at a time and then use JavaScript to reload the page to avoid the timeout issues.

Bastien

Sent from my iPod


--- End Message ---
--- Begin Message ---
It did not work. Both gave me a "Call to undefined method" fatal error.

On Sun, Aug 16, 2009 at 1:43 AM, Ralph Deffke <[email protected]> wrote:

>
> try
>
> $link->nodeValue()
>
> or
>
> $link->getContent()
>
> im not shure which one works on an image link which is indeed a child of <a
> so u could also check if the node has a child, if so its an image with, in
> good practice. an alt attribute to use
>
> haven't tried but should work. let me know pls
>
> [email protected]
>
>
> "chrysanhy" <[email protected]> wrote in message
> news:[email protected]...
> > I have the following code to extract the URLs from the anchor tags of an
> > HTML page:
> >
> > $html = new DOMDocument();
> > $htmlpage->loadHtmlFile($location);
> > $xpath = new DOMXPath($htmlpage);
> > $links = $xpath->query( '//a' );
> > foreach ($links as $link)
> > { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
> >
> > If I have a link <a href="http://X.com";>YYYY</a>, how do I extract the
> > corresponding YYYY which is displayed to the user as the text of the link
> > (if it's an image tag, I would like a DOMElement for that).
> > Thanks
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
did u try it something like this

foreach ($links as $link) {
    $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
    $int_url_list[$i++]["linkText"] = $link->getContent(  ); // nodeValue();
}
that should work

send ur code then please
ralph_def...@yahoo,de


"chrysanhy" <[email protected]> wrote in message
news:[email protected]...
> I have the following code to extract the URLs from the anchor tags of an
> HTML page:
>
> $html = new DOMDocument();
> $htmlpage->loadHtmlFile($location);
> $xpath = new DOMXPath($htmlpage);
> $links = $xpath->query( '//a' );
> foreach ($links as $link)
> { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
>
> If I have a link <a href="http://X.com";>YYYY</a>, how do I extract the
> corresponding YYYY which is displayed to the user as the text of the link
> (if it's an image tag, I would like a DOMElement for that).
> Thanks
>



--- End Message ---
--- Begin Message ---
I found this iteration over the item collection
for ($i = 0; $i < $items->length; $i++) {
    echo $items->item($i)->nodeValue . "\n";
}

check here as well
http://us.php.net/manual/en/domnodelist.item.php

doesn't seem a simple foreach dos it

[email protected]

"chrysanhy" <[email protected]> wrote in message
news:[email protected]...
> It did not work. Both gave me a "Call to undefined method" fatal error.
>
> On Sun, Aug 16, 2009 at 1:43 AM, Ralph Deffke <[email protected]>
wrote:
>
> >
> > try
> >
> > $link->nodeValue()
> >
> > or
> >
> > $link->getContent()
> >
> > im not shure which one works on an image link which is indeed a child of
<a
> > so u could also check if the node has a child, if so its an image with,
in
> > good practice. an alt attribute to use
> >
> > haven't tried but should work. let me know pls
> >
> > [email protected]
> >
> >
> > "chrysanhy" <[email protected]> wrote in message
> > news:[email protected]...
> > > I have the following code to extract the URLs from the anchor tags of
an
> > > HTML page:
> > >
> > > $html = new DOMDocument();
> > > $htmlpage->loadHtmlFile($location);
> > > $xpath = new DOMXPath($htmlpage);
> > > $links = $xpath->query( '//a' );
> > > foreach ($links as $link)
> > > { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
> > >
> > > If I have a link <a href="http://X.com";>YYYY</a>, how do I extract the
> > > corresponding YYYY which is displayed to the user as the text of the
link
> > > (if it's an image tag, I would like a DOMElement for that).
> > > Thanks
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>



--- End Message ---
--- Begin Message ---
I pasted the code exactly as you have it, and I got the following:

*Fatal error*: Call to undefined method DOMElement::getContent()

I got the same thing with nodeValue().

On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke <[email protected]> wrote:

> did u try it something like this
>
> foreach ($links as $link) {
>    $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
>    $int_url_list[$i++]["linkText"] = $link->getContent(  ); // nodeValue();
> }
> that should work
>
> send ur code then please
> ralph_def...@yahoo,de
>
>
> "chrysanhy" <[email protected]> wrote in message
> news:[email protected]...
> > I have the following code to extract the URLs from the anchor tags of an
> > HTML page:
> >
> > $html = new DOMDocument();
> > $htmlpage->loadHtmlFile($location);
> > $xpath = new DOMXPath($htmlpage);
> > $links = $xpath->query( '//a' );
> > foreach ($links as $link)
> > { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
> >
> > If I have a link <a href="http://X.com";>YYYY</a>, how do I extract the
> > corresponding YYYY which is displayed to the user as the text of the link
> > (if it's an image tag, I would like a DOMElement for that).
> > Thanks
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
WHile waiting for suggestions for extracting the link text from the DOM, I
tried a brute force approach using the URLs I had found with getAttribute(),
but found myself baffled by my results. I boiled down my issue with this
approach to the following snippet.

$htmldata =<<<EOB
http://www.protools.com/users/user_story.cfm?story_id=1162&amp;lang=1";>&quot;Creating

            Surround Mixes with Tim Weidner</a>&quot; <img height="11"
src="new.gif" width="28">
            - <i>Magnification</i> engineer talks about mixing the album at
the
            <i>ProTools</i> site, by Jim Batchco
http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html";>&quot;Don't
            Go&quot; Video</a><a href="
http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html";></a>
            <img height="11" src="new.gif" width="28"> - Presented by Beyond
Music
            (<a href="http://www.apple.com/quicktime/download/";>QuickTime</a>

            Required)
EOB;
$url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
$posn = strpos($url, $htmldata);
echo "URL |$url| position is |$posn|";

Running this gives me:

URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is ||

I've tried lots of functions, and even regular expressions, but I cannot get
the code to find the URL in the HTML. While I still hope for a DOM solution
to getting this link text, WHY can't the code find the URL in the HTML
snippet?

On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy <[email protected]>wrote:

> I pasted the code exactly as you have it, and I got the following:
>
> *Fatal error*: Call to undefined method DOMElement::getContent()
>
> I got the same thing with nodeValue().
>
>
> On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke <[email protected]>wrote:
>
>> did u try it something like this
>>
>> foreach ($links as $link) {
>>    $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
>>    $int_url_list[$i++]["linkText"] = $link->getContent(  ); //
>> nodeValue();
>> }
>> that should work
>>
>> send ur code then please
>> ralph_def...@yahoo,de
>>
>>
>> "chrysanhy" <[email protected]> wrote in message
>> news:[email protected]...
>> > I have the following code to extract the URLs from the anchor tags of an
>> > HTML page:
>> >
>> > $html = new DOMDocument();
>> > $htmlpage->loadHtmlFile($location);
>> > $xpath = new DOMXPath($htmlpage);
>> > $links = $xpath->query( '//a' );
>> > foreach ($links as $link)
>> > { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
>> >
>> > If I have a link <a href="http://X.com";>YYYY</a>, how do I extract the
>> > corresponding YYYY which is displayed to the user as the text of the
>> link
>> > (if it's an image tag, I would like a DOMElement for that).
>> > Thanks
>> >
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>

--- End Message ---
--- Begin Message ---
well the immage goes inside the <a..> <img...> </a>

on ur html the node a has no value however u should not get a error

this is pergect jtml link
<a href="thema.htm"><img src="button4.jpg" width="160" height="34"
border="0" alt="THEMA"></a>

ralph

"chrysanhy" <[email protected]> wrote in message
news:[email protected]...
> WHile waiting for suggestions for extracting the link text from the DOM, I
> tried a brute force approach using the URLs I had found with
getAttribute(),
> but found myself baffled by my results. I boiled down my issue with this
> approach to the following snippet.
>
> $htmldata =<<<EOB
>
http://www.protools.com/users/user_story.cfm?story_id=1162&amp;lang=1";>&quot;Creating
>
>             Surround Mixes with Tim Weidner</a>&quot; <img height="11"
> src="new.gif" width="28">
>             - <i>Magnification</i> engineer talks about mixing the album
at
> the
>             <i>ProTools</i> site, by Jim Batchco
> http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html";>&quot;Don't
>             Go&quot; Video</a><a href="
>
http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html";></a>
>             <img height="11" src="new.gif" width="28"> - Presented by
Beyond
> Music
>             (<a
href="http://www.apple.com/quicktime/download/";>QuickTime</a>
>
>             Required)
> EOB;
> $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
> $posn = strpos($url, $htmldata);
> echo "URL |$url| position is |$posn|";
>
> Running this gives me:
>
> URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is
||
>
> I've tried lots of functions, and even regular expressions, but I cannot
get
> the code to find the URL in the HTML. While I still hope for a DOM
solution
> to getting this link text, WHY can't the code find the URL in the HTML
> snippet?
>
> On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy
<[email protected]>wrote:
>
> > I pasted the code exactly as you have it, and I got the following:
> >
> > *Fatal error*: Call to undefined method DOMElement::getContent()
> >
> > I got the same thing with nodeValue().
> >
> >
> > On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke
<[email protected]>wrote:
> >
> >> did u try it something like this
> >>
> >> foreach ($links as $link) {
> >>    $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
> >>    $int_url_list[$i++]["linkText"] = $link->getContent(  ); //
> >> nodeValue();
> >> }
> >> that should work
> >>
> >> send ur code then please
> >> ralph_def...@yahoo,de
> >>
> >>
> >> "chrysanhy" <[email protected]> wrote in message
> >> news:[email protected]...
> >> > I have the following code to extract the URLs from the anchor tags of
an
> >> > HTML page:
> >> >
> >> > $html = new DOMDocument();
> >> > $htmlpage->loadHtmlFile($location);
> >> > $xpath = new DOMXPath($htmlpage);
> >> > $links = $xpath->query( '//a' );
> >> > foreach ($links as $link)
> >> > { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
> >> >
> >> > If I have a link <a href="http://X.com";>YYYY</a>, how do I extract
the
> >> > corresponding YYYY which is displayed to the user as the text of the
> >> link
> >> > (if it's an image tag, I would like a DOMElement for that).
> >> > Thanks
> >> >
> >>
> >>
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
>



--- End Message ---
--- Begin Message ---
this worked here:
<?php

$html = new DOMDocument();
$html->loadHtmlFile("testHtml.html");
$links = $html->getElementsByTagName('a');
echo "<pre>";

foreach ($links as $item) {
  echo $item->getAttribute( 'href' ). "\n";
  echo "-------" . $item->nodeValue . "\n";
}

echo "</pre>";

?>

Im sending u the 2 files directly in a minute. it came out, as I thought
earlier that u have to check if the <a> tags has got children to extract
image links.

[email protected]


"chrysanhy" <[email protected]> wrote in message
news:[email protected]...
> WHile waiting for suggestions for extracting the link text from the DOM, I
> tried a brute force approach using the URLs I had found with
getAttribute(),
> but found myself baffled by my results. I boiled down my issue with this
> approach to the following snippet.
>
> $htmldata =<<<EOB
>
http://www.protools.com/users/user_story.cfm?story_id=1162&amp;lang=1";>&quot;Creating
>
>             Surround Mixes with Tim Weidner</a>&quot; <img height="11"
> src="new.gif" width="28">
>             - <i>Magnification</i> engineer talks about mixing the album
at
> the
>             <i>ProTools</i> site, by Jim Batchco
> http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html";>&quot;Don't
>             Go&quot; Video</a><a href="
>
http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html";></a>
>             <img height="11" src="new.gif" width="28"> - Presented by
Beyond
> Music
>             (<a
href="http://www.apple.com/quicktime/download/";>QuickTime</a>
>
>             Required)
> EOB;
> $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
> $posn = strpos($url, $htmldata);
> echo "URL |$url| position is |$posn|";
>
> Running this gives me:
>
> URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is
||
>
> I've tried lots of functions, and even regular expressions, but I cannot
get
> the code to find the URL in the HTML. While I still hope for a DOM
solution
> to getting this link text, WHY can't the code find the URL in the HTML
> snippet?
>
> On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy
<[email protected]>wrote:
>
> > I pasted the code exactly as you have it, and I got the following:
> >
> > *Fatal error*: Call to undefined method DOMElement::getContent()
> >
> > I got the same thing with nodeValue().
> >
> >
> > On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke
<[email protected]>wrote:
> >
> >> did u try it something like this
> >>
> >> foreach ($links as $link) {
> >>    $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
> >>    $int_url_list[$i++]["linkText"] = $link->getContent(  ); //
> >> nodeValue();
> >> }
> >> that should work
> >>
> >> send ur code then please
> >> ralph_def...@yahoo,de
> >>
> >>
> >> "chrysanhy" <[email protected]> wrote in message
> >> news:[email protected]...
> >> > I have the following code to extract the URLs from the anchor tags of
an
> >> > HTML page:
> >> >
> >> > $html = new DOMDocument();
> >> > $htmlpage->loadHtmlFile($location);
> >> > $xpath = new DOMXPath($htmlpage);
> >> > $links = $xpath->query( '//a' );
> >> > foreach ($links as $link)
> >> > { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
> >> >
> >> > If I have a link <a href="http://X.com";>YYYY</a>, how do I extract
the
> >> > corresponding YYYY which is displayed to the user as the text of the
> >> link
> >> > (if it's an image tag, I would like a DOMElement for that).
> >> > Thanks
> >> >
> >>
> >>
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
>



--- End Message ---
--- Begin Message ---
The code snippet below worked! Thank you so much for your time helping me
with this!

On Sun, Aug 16, 2009 at 11:26 AM, Ralph Deffke <[email protected]>wrote:

> this worked here:
> <?php
>
> $html = new DOMDocument();
> $html->loadHtmlFile("testHtml.html");
> $links = $html->getElementsByTagName('a');
> echo "<pre>";
>
> foreach ($links as $item) {
>  echo $item->getAttribute( 'href' ). "\n";
>  echo "-------" . $item->nodeValue . "\n";
> }
>
> echo "</pre>";
>
> ?>
>
> Im sending u the 2 files directly in a minute. it came out, as I thought
> earlier that u have to check if the <a> tags has got children to extract
> image links.
>
> [email protected]
>
>
> "chrysanhy" <[email protected]> wrote in message
> news:[email protected]...
> > WHile waiting for suggestions for extracting the link text from the DOM,
> I
> > tried a brute force approach using the URLs I had found with
> getAttribute(),
> > but found myself baffled by my results. I boiled down my issue with this
> > approach to the following snippet.
> >
> > $htmldata =<<<EOB
> >
> http://www.protools.com/users/user_story.cfm?story_id=1162&amp;lang=1
> ">&quot;Creating
> >
> >             Surround Mixes with Tim Weidner</a>&quot; <img height="11"
> > src="new.gif" width="28">
> >             - <i>Magnification</i> engineer talks about mixing the album
> at
> > the
> >             <i>ProTools</i> site, by Jim Batchco
> > http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html";>&quot;Don't
> >             Go&quot; Video</a><a href="
> >
> http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html
> "></a>
> >             <img height="11" src="new.gif" width="28"> - Presented by
> Beyond
> > Music
> >             (<a
> href="http://www.apple.com/quicktime/download/";>QuickTime</a>
> >
> >             Required)
> > EOB;
> > $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
> > $posn = strpos($url, $htmldata);
> > echo "URL |$url| position is |$posn|";
> >
> > Running this gives me:
> >
> > URL 
> > |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html|<http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html%7C>position
> >  is
> ||
> >
> > I've tried lots of functions, and even regular expressions, but I cannot
> get
> > the code to find the URL in the HTML. While I still hope for a DOM
> solution
> > to getting this link text, WHY can't the code find the URL in the HTML
> > snippet?
> >
> > On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy
> <[email protected]>wrote:
> >
> > > I pasted the code exactly as you have it, and I got the following:
> > >
> > > *Fatal error*: Call to undefined method DOMElement::getContent()
> > >
> > > I got the same thing with nodeValue().
> > >
> > >
> > > On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke
> <[email protected]>wrote:
> > >
> > >> did u try it something like this
> > >>
> > >> foreach ($links as $link) {
> > >>    $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
> > >>    $int_url_list[$i++]["linkText"] = $link->getContent(  ); //
> > >> nodeValue();
> > >> }
> > >> that should work
> > >>
> > >> send ur code then please
> > >> ralph_def...@yahoo,de
> > >>
> > >>
> > >> "chrysanhy" <[email protected]> wrote in message
> > >> news:[email protected]...
> > >> > I have the following code to extract the URLs from the anchor tags
> of
> an
> > >> > HTML page:
> > >> >
> > >> > $html = new DOMDocument();
> > >> > $htmlpage->loadHtmlFile($location);
> > >> > $xpath = new DOMXPath($htmlpage);
> > >> > $links = $xpath->query( '//a' );
> > >> > foreach ($links as $link)
> > >> > { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
> > >> >
> > >> > If I have a link <a href="http://X.com";>YYYY</a>, how do I extract
> the
> > >> > corresponding YYYY which is displayed to the user as the text of the
> > >> link
> > >> > (if it's an image tag, I would like a DOMElement for that).
> > >> > Thanks
> > >> >
> > >>
> > >>
> > >>
> > >> --
> > >> PHP General Mailing List (http://www.php.net/)
> > >> To unsubscribe, visit: http://www.php.net/unsub.php
> > >>
> > >>
> > >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Dan Brown is a frequent poster here and developer on the PHP team.
Dan has not posted to the PHP list for quite a while and is not responding to 
my emails directly to him.
Does anyone know if he's OK?
If anyone has knowledge can they please reply to me directly - off list.
Thanks,
Angus

--- End Message ---
--- Begin Message ---
Angus Mann wrote:

> Dan Brown is a frequent poster here and developer on the PHP team.
> Dan has not posted to the PHP list for quite a while and is not
> responding to my emails directly to him. Does anyone know if he's OK?
> If anyone has knowledge can they please reply to me directly - off
> list. Thanks,

Take a look at Dans posting from 3 August.



-- 
Per Jessen, Zürich (28.4°C)


--- End Message ---
--- Begin Message ---
I have a script in /home/username/script.sh with permissions 777. I
can SSH into the server and execute ./script.sh to run the script, but
calling it from exec in PHP does not run it. What should I start
checking?

Thanks.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--- End Message ---
--- Begin Message ---
Dotan Cohen wrote:
I have a script in /home/username/script.sh with permissions 777. I
can SSH into the server and execute ./script.sh to run the script, but
calling it from exec in PHP does not run it. What should I start
checking?

Thanks.

Check the include path. Try using the complete path to the file. And make sure the user PHP is running has read permissions to the directories upwards the hierarchy.


--

With warm regards,
Sudheer. S
Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, 
Personal: http://sudheer.net


--- End Message ---
--- Begin Message ---
> Check the include path. Try using the complete path to the file. And make
> sure the user PHP is running has read permissions to the directories upwards
> the hierarchy.
>

Thanks. I am using the complete path to the script:
exec("/home/username/script.sh");

In the /home/username/ directory there are other files, such as
database_connection.inc that I regularly include_once in my PHP
scripts, so I know that PHP has read access to that directory.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--- End Message ---
--- Begin Message ---
Dotan,

Please copy your script in the Linux include paths. Such as /usr/local/bin
and give it neccecary permission and try your script again.

If you still have any problem, we understand that it is no related script
path problem and permissions.

Maybe there is some problems on your php script.

Thanks 


-----Original Message-----
From: Dotan Cohen [mailto:[email protected]] 
Sent: Sunday, August 16, 2009 9:46 PM
To: Sudheer Satyanarayana
Cc: php-general.
Subject: Re: [PHP] Cannot exec in my own directory

> Check the include path. Try using the complete path to the file. And make
> sure the user PHP is running has read permissions to the directories
upwards
> the hierarchy.
>

Thanks. I am using the complete path to the script:
exec("/home/username/script.sh");

In the /home/username/ directory there are other files, such as
database_connection.inc that I regularly include_once in my PHP
scripts, so I know that PHP has read access to that directory.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

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


--- End Message ---
--- Begin Message ---
> Please copy your script in the Linux include paths. Such as /usr/local/bin
> and give it neccecary permission and try your script again.
>

I do not have root access on this machine. That is why I run the
script from /home/username/

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--- End Message ---
--- Begin Message ---
I am sanitizing user-entered data before storing in mysql with this function:

function clean_mysql ($dirty) {
    $dirty=trim($dirty);
    $dirty=str_replace ("--", "", $dirty);
    $dirty=str_replace (";", "", $dirty);
    $clean=mysql_real_escape_string($dirty);
    return $clean;
}

Is this good enough to prevent SQL injection attacks? Should I add
anything else? Thanks!

Dotan Cohen

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

You can use htmlentities(), htmlspecialchars() and strip_tags() functions
when you show your saved data on your web pages. mysql_real_escape_string
function saved data into mysql DB with a secure way. But when you try to
show data you still have to control it.

Thanks.
Caner.

-----Original Message-----
From: Dotan Cohen [mailto:[email protected]] 
Sent: Sunday, August 16, 2009 9:43 PM
To: php-general.
Subject: [PHP] Sanitizing mysql inserts of user data

I am sanitizing user-entered data before storing in mysql with this
function:

function clean_mysql ($dirty) {
    $dirty=trim($dirty);
    $dirty=str_replace ("--", "", $dirty);
    $dirty=str_replace (";", "", $dirty);
    $clean=mysql_real_escape_string($dirty);
    return $clean;
}

Is this good enough to prevent SQL injection attacks? Should I add
anything else? Thanks!

Dotan Cohen

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


--- End Message ---
--- Begin Message ---
What you are doing here is potentially altering valid user information
coming into MySQL. For example, if someone legitimately enters in --
or ; into some string that is going to be put into MySQL, some comment
or such, then what is put in, and then put out if you display it,
won't be the same.

You should in pretty much all cases be safe with just using the
mysql_real_escape_string, which takes care of the - for you as well.

Adam.

On Sun, Aug 16, 2009 at 11:42 AM, Dotan Cohen<[email protected]> wrote:
> I am sanitizing user-entered data before storing in mysql with this function:
>
> function clean_mysql ($dirty) {
>    $dirty=trim($dirty);
>    $dirty=str_replace ("--", "", $dirty);
>    $dirty=str_replace (";", "", $dirty);
>    $clean=mysql_real_escape_string($dirty);
>    return $clean;
> }
>
> Is this good enough to prevent SQL injection attacks? Should I add
> anything else? Thanks!
>
> Dotan Cohen
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Adam Randall
http://www.xaren.net
AIM: blitz574

--- End Message ---
--- Begin Message ---
> You should in pretty much all cases be safe with just using the
> mysql_real_escape_string, which takes care of the - for you as well.
>

If I remember correctly, TFM once stated that mysql_real_escape_string
does not prevent SQL injection attacks, though I am hard pressed to
think of what it _is_ for, then. I now see that the manual has this
note:
"Note: If this function is not used to escape data, the query is
vulnerable to SQL Injection Attacks."

Does that necessarily imply this:
"If this function is used to escape data, the query is not vulnerable
to SQL Injection Attacks."?

Logically, it does _not_ mean the same thing.


-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--- End Message ---
--- Begin Message ---
2009/8/16 Caner Bulut <[email protected]>:
>
> Hi Dotan,
>
> You can use htmlentities(), htmlspecialchars() and strip_tags() functions
> when you show your saved data on your web pages. mysql_real_escape_string
> function saved data into mysql DB with a secure way. But when you try to
> show data you still have to control it.
>

Thank you Caner. This is the function that I use to escape HTML after
it has been pulled out of the database:

function clean_html ($dirty, $noNewlines=0) {
    $dirty = strip_tags($dirty);
    $dirty = str_replace("\r\n", "\n", $dirty);
    $dirty = str_replace("\r", "\n", $dirty);
    if ($noNewlines==1) { $dirty = str_replace("\n", " ", $dirty); }
    $dirty = ereg_replace( ' +', ' ', $dirty);
    $dirty=trim($dirty);
    $dirty = str_replace("&amp;", "&", $dirty);
    $dirty = str_replace("&", "&amp;", $dirty);

    $clean=htmlentities($dirty);
    return $clean;
}



It is rather convoluted but straightforward in my opinion. In addition
to preventing XSS attacks, it converts newlines to *nix-style and
limits them to just two newlines in a row (or none, depending on
application). It also limits spaces to a single space and ensures that
all ampersands are escaped properly before sanitation with
htmlentities.

Dotan Cohen

--- End Message ---
--- Begin Message ---
anybody out there with a ultimate solution, speed optimzed?

im going now for an ultimate solution, this repeating problem sucks

[email protected]



--- End Message ---
--- Begin Message ---
On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote:

> tedd wrote:
>> Hi gang:
>>
>> Here's another exercise to consider.
>>
>> This is a date entry problem where the user can enter a date in various
>> forms, but the return will be in a consistent format.
>>
>> For example, a user might enter a date in the form of:
>>
>> August 5, 2009
>> Aug 05 2009
>> Aug 5, 9
>> 08/05/09
>> 8-5-9
>> 8 05 2009
>> 8,5,9
>>
>> Or any combination thereof.
>>
>> However, the resultant date will be standardized to: Aug 5, 2009.
>>
>> Extra points for solving this for Euro as well as US date formats (i.e.,
>> 5 Aug, 2009 vs Aug 5, 2009).  And, extra extra points for accommodating
>> month brevity, such as "A" for August and "Mar" for March and so on.
>
> But the real problem here is 05/08/09 is still August 5 2009 .....
> So teaching customers to use 2009.08.05 removes the hassle of needing to 
> know
> where your target site is based!
>
> But as has been said, the real solution is a date picker.

I *hate* date pickers. They slow down input. I can type 082309<Enter>
faster than I can ever do it with a date picker. The date class knows
I'm in America and since it's a six-digit date, it must be mmddyy. (Yes,
for those of you *not* in America, I agree our dates are goofy. I think
we all ought to be on the metic system, too, but America and the UK seem
intent on sticking to Imperial measure.)

Paul


-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
i agree on date pickers and js is .... well

use individual fields for day month and year, make month and year as drop
down and u have no problem at all

make live easier

ralph

"Paul M Foster" <[email protected]> wrote in message
news:[email protected]...
> On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote:
>
> > tedd wrote:
> >> Hi gang:
> >>
> >> Here's another exercise to consider.
> >>
> >> This is a date entry problem where the user can enter a date in various
> >> forms, but the return will be in a consistent format.
> >>
> >> For example, a user might enter a date in the form of:
> >>
> >> August 5, 2009
> >> Aug 05 2009
> >> Aug 5, 9
> >> 08/05/09
> >> 8-5-9
> >> 8 05 2009
> >> 8,5,9
> >>
> >> Or any combination thereof.
> >>
> >> However, the resultant date will be standardized to: Aug 5, 2009.
> >>
> >> Extra points for solving this for Euro as well as US date formats
(i.e.,
> >> 5 Aug, 2009 vs Aug 5, 2009).  And, extra extra points for accommodating
> >> month brevity, such as "A" for August and "Mar" for March and so on.
> >
> > But the real problem here is 05/08/09 is still August 5 2009 .....
> > So teaching customers to use 2009.08.05 removes the hassle of needing to
> > know
> > where your target site is based!
> >
> > But as has been said, the real solution is a date picker.
>
> I *hate* date pickers. They slow down input. I can type 082309<Enter>
> faster than I can ever do it with a date picker. The date class knows
> I'm in America and since it's a six-digit date, it must be mmddyy. (Yes,
> for those of you *not* in America, I agree our dates are goofy. I think
> we all ought to be on the metic system, too, but America and the UK seem
> intent on sticking to Imperial measure.)
>
> Paul
>
>
> -- 
> Paul M. Foster



--- End Message ---
--- Begin Message ---
Hi friends, I'm trying to get an encrypting program working to possibly use
for password insertion into a db.

I set up a function that runs str_replace on a string (user supplied) two
times. It searches for a single letter or number, and replace it with a
pair. The next str_replace searches that new string for different pairs, and
replaces them with a three-character string (symbol, character, character).
I'm using % as my symbol, so I'm pretty sure this isn't the issue.

It encodes, but the resulting string is way longer than expected!

I set sup a decode function, with the same str_replace values, just with the
replaces flipped. This works to return to me my original value, but I have
to decode about 6 times (after encoding once). Basically, running a string
through the encoding function will decode back to its original value, but I
have to run it through the decode function multiple times to do so.

Here is an example of my code:

[code]

<?php
//ENCRYPT FUNCTIONS
function format_string($string,$functions)
{ $funcs = explode(",",$functions);
    foreach ($funcs as $func)
    {
        if (function_exists($func)) $string = $func($string);
    }
    return $string;
}
function enc_string($string)
{  $search = array("a","b","c","d","e","f","g","h","i",".........."); //62
values
 $replace = array("j9","k8","q7","v6","..........."); //62 values
 $string = str_replace($search, $replace, $string);
 $search2 =
array("9k","8q","7v","6w","5x","4y","3z","2j","................"); // 126
values
 $string = str_replace($search2, $replace2, $string);
 return $string;
}
function scrub($input)
{ $string = format_string($input,"strip_tags,trim");
 $string = enc_string($string);
 return $string;
}
if(isset($_POST['input']))
{ $input = $_POST['input'];
 $enc_password = scrub($input);
}
//DECRYPT FUNCTIONS
function format_string2($string2,$functions)
{ $funcs = explode(",",$functions);
    foreach ($funcs as $func)
    {
        if (function_exists($func)) $string2 = $func($string2);
    }
    return $string2;
}
function dec_string($string2)
{ $search3 = array("%A1","%B2","%C3","........"); // 126 values
 $replace3 = array("9k","8q","7v","......."); //126 values
 $string2 = str_replace($search3, $replace3, $string2);
 $search4 = array("j9","k8","q7","......"); //62 values
 $replace4 = array("a","b","c","..........."); //62 values
 $string2 = str_replace($search4, $replace4, $string2);
 return $string2;
}
function scrub_set2($input2)
{ $string2 = format_string2($input2,"strip_tags,trim");
 $string2 = dec_string($string2);
 return $string2;
}
if(isset($_POST['input2']))
{ $input2 = $_POST['input2'];
 $dec_password = scrub_set2($input2);
}
?>
<body>

<form (posts to itself) >
<input type="text" name="input" id="input" value="<?php if(isset($input))
echo $input; ?>" />
 <input type="text" name="output" id="output" value="<?php
if(isset($enc_password)) echo $enc_password; ?>" <?php
if(!isset($enc_password)) echo "readonly='readonly'"; ?> />
<input type="submit" name="submit" value="Encrypt" />

[/code]

I have a feeling that php is running the functions through the str_replace
functions multiple times. It doesn't seem to mess with the unique-ness I had
to build into it (in order to preserve the string for decoding), but it
makes me nervous if it runs it through multiple times. Does anyone know why
the encoding step results in such a long string? And why do I have to run
decode on the result so many times to change it back?

Any and all help would be greatly appreciated!

--- End Message ---
--- Begin Message ---
Hello,

I realize this is more of an html question than a php, but I was hoping
someone here would know what's going on.

I am linking to a stylesheet and it is requiring me to use *.css
extension. I want to use a .php extension (and have the php engine
generate css). However, whenever i use a .php extension the link tag
does not seem to work.

This works!
<link rel="stylesheet" type="text/css"
href="http://localhost:8080/some.css"; />

This doesn't work but I don't understand why not???
<link rel="stylesheet" type="text/css"
href="http://localhost:8080/some.php"; />

The page http://localhost:8080/some.php displays the css exactly the
same as http://localhost:8080/some.css

Why can't I link to a css file by using a different extension?

Thanks in advance,
dK
`

--- End Message ---
--- Begin Message ---
Of course not, just send the corresponding mime type to the file extension
.css
Probably header('Content-Type: text/css');

Good luck ;)

On Sun, Aug 16, 2009 at 11:37 PM, Daniel Kolbo <[email protected]> wrote:

> Hello,
>
> I realize this is more of an html question than a php, but I was hoping
> someone here would know what's going on.
>
> I am linking to a stylesheet and it is requiring me to use *.css
> extension. I want to use a .php extension (and have the php engine
> generate css). However, whenever i use a .php extension the link tag
> does not seem to work.
>
> This works!
> <link rel="stylesheet" type="text/css"
> href="http://localhost:8080/some.css"; />
>
> This doesn't work but I don't understand why not???
> <link rel="stylesheet" type="text/css"
> href="http://localhost:8080/some.php"; />
>
> The page http://localhost:8080/some.php displays the css exactly the
> same as http://localhost:8080/some.css
>
> Why can't I link to a css file by using a different extension?
>
> Thanks in advance,
> dK
> `
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Daniel Kolbo wrote:
> Hello,
> 
> I realize this is more of an html question than a php, but I was hoping
> someone here would know what's going on.
> 
> I am linking to a stylesheet and it is requiring me to use *.css
> extension. I want to use a .php extension (and have the php engine
> generate css). However, whenever i use a .php extension the link tag
> does not seem to work.
> 
> This works!
> <link rel="stylesheet" type="text/css"
> href="http://localhost:8080/some.css"; />
> 
> This doesn't work but I don't understand why not???
> <link rel="stylesheet" type="text/css"
> href="http://localhost:8080/some.php"; />
>
> The page http://localhost:8080/some.php displays the css exactly the
> same as http://localhost:8080/some.css
> 
> Why can't I link to a css file by using a different extension?
> 
> Thanks in advance,
> dK
> `
> 
Sorry, I am pretty sure i figured out why.  I think it has to do with
Content-Type header.
Thanks,
dK
`

--- End Message ---
--- Begin Message ---
On Sun, Aug 16, 2009 at 4:37 PM, Daniel Kolbo <[email protected]> wrote:

> Hello,
>
> I realize this is more of an html question than a php, but I was hoping
> someone here would know what's going on.
>
> I am linking to a stylesheet and it is requiring me to use *.css
> extension. I want to use a .php extension (and have the php engine
> generate css). However, whenever i use a .php extension the link tag
> does not seem to work.
>
> This works!
> <link rel="stylesheet" type="text/css"
> href="http://localhost:8080/some.css"; />
>
> This doesn't work but I don't understand why not???
> <link rel="stylesheet" type="text/css"
> href="http://localhost:8080/some.php"; />
>
> The page http://localhost:8080/some.php displays the css exactly the
> same as http://localhost:8080/some.css
>
> Why can't I link to a css file by using a different extension?
>
> Thanks in advance,
> dK
> `
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Oh, I think it's part of the spec. You could always use .htaccess rules to
parse .css files as .php, this will keep search engines happy and browsers
happy as well.

-- 
- Adam Shannon ( http://ashannon.us )

--- End Message ---
--- Begin Message ---
is_dir()

<http://ca3.php.net/is_dir>

is_file()

<http://ca3.php.net/manual/en/function.is-file.php>

George Langley


On 15-Aug-09, at 5:45 PM, Clancy wrote:

On Sat, 15 Aug 2009 10:33:07 +0100, [email protected] (Ashley Sheridan) wrote:

On Sat, 2009-08-15 at 09:56 +0200, Ralph Deffke wrote:
can u upload ur own files ?
can u create a directory ?

Yes.

are u using a ftp client ?

No; I'm using straight PHP FTP


"Clancy" <[email protected]> wrote in message
news:[email protected]...
I have just got access to a new server, and am playing with
upload/download procedures. I
looked in the root directory, and see several objects which I assume to be
directories.
However I was surprised to find there does not appear to be any command to
determine if an
object is a file or directory, either in PHP FTP or plain FTP. I could
try to change to
them, or download them, but this seems overkill.  Am I overlooking
something obvious?



That answer doesn't seem to quite come close even to answering the op
question.

Have you looked at ftp_rawlist which returns a detailed list of files,
along with their permissions and directory flags? Or you could use
ftp_size to determine the size of a file, which should be nothing for a
directory.

Thanks,

Yes; I found ftp_rawlist eventually, but I still haven't found a definition of the return
code, though I think I know most of it.

I guess that even a null file will hve some length? I will probably use the leading 'd'
in the return code to test for directories..

(And I spent a long time trying to work out how 'drwxr-xr-x 2 riordan riordan 512 Jul 31 06:40 cgi-bin' could contain lots of spaces, before I remembered that, as a result of one
of the weirder design decisions,  HTML suppresses trailing spaces.)


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



--- End Message ---

Reply via email to