Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts

    Is there any way to turn this javascript code into a php code?

    This may be confusing but I want to turn
    Code:
    javascript: array=document.getElementsByTagName('a'); for (x in array){ if (array[x].getAttribute('class')=="clickthru-link"){ alert(array[x].href); } } void(0);
    into a php code. If you don't understand I want to make a php code that does the same thing as that javascript code. I need it as a php code because there are some specific functions that would depend on it to work properly.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,381
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    Describe more what it does ...
    PHP can't read specific form fields in real time like JS can.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    PHP can not interact with html at page display, so you could not alert() anything, you could use the DOM functions to parse the page but you wont get to display anything at runtime without javascript ~
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by mlseim View Post
    Describe more what it does ...
    PHP can't read specific form fields in real time like JS can.
    It gets the link of a button (on a site. Not mine though) and displays it.
    Quote Originally Posted by firepages View Post
    PHP can not interact with html at page display, so you could not alert() anything, you could use the DOM functions to parse the page but you wont get to display anything at runtime without javascript ~
    well not that code exactly but a variation of it which displays the link (Which I know php can do using echo) instead of putting it in an alert box.

  • #5
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,381
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    So the idea is that you want PHP to "scrape" the other site, which means it
    scans through their HTML and finds the button you are looking for?

    Do you have an example of the "other site", where you're supposed to get the button link?

    I'm still not following the meaning or purpose of this.

  • #6
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by mlseim View Post
    So the idea is that you want PHP to "scrape" the other site, which means it
    scans through their HTML and finds the button you are looking for?

    Do you have an example of the "other site", where you're supposed to get the button link?

    I'm still not following the meaning or purpose of this.
    yes and no. I want it to locate the button, get the link the button takes you to, AND display the link (and as I said before I know php can do the last part with echo). There are multiple buttons though which I need the links of.

    But unfortunately I can't show you the other site because it requires a membership (free) to see the content
    Last edited by elitis; 12-04-2010 at 02:02 AM.

  • #7
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    bump.

  • #8
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,381
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    You have a few hurdles to cross.

    The first one is to get PHP to log into that other site:
    http://www.google.com/search?q=php+l...8ec2db23988f7d

    Then, you have to read the HTML and parse-out the links.
    Without seeing that other site ... nothing I can do to help you with that.

    I can tell you, it probably won't be easy.
    You might want to find out if the "other site" has some way for you to read a
    database or XML file (RSS feed or whatever) to get the information you need.

  • #9
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by mlseim View Post
    You have a few hurdles to cross.

    The first one is to get PHP to log into that other site:
    http://www.google.com/search?q=php+l...8ec2db23988f7d

    Then, you have to read the HTML and parse-out the links.
    Without seeing that other site ... nothing I can do to help you with that.

    I can tell you, it probably won't be easy.
    You might want to find out if the "other site" has some way for you to read a
    database or XML file (RSS feed or whatever) to get the information you need.
    well actually for the login part I was going to have it where you'd have to already be logged into the other site for it to work. The site is http://www.lockerz.com but as I said you have to have an account in order to see anything

  • #10
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,381
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    Your PHP script is not you.

    It doesn't matter if you're logged in or not.
    The PHP script runs from your webhost's server, and it's not human.
    It doesn't use a browser with cookies. You'll have to program the PHP
    script login using your personal login account username/password.

    That's why I mentioned you find out if the information you need can be
    provided by them via an API or RSS feed.

  • #11
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by mlseim View Post
    Your PHP script is not you.

    It doesn't matter if you're logged in or not.
    The PHP script runs from your webhost's server, and it's not human.
    It doesn't use a browser with cookies. You'll have to program the PHP
    script login using your personal login account username/password.

    That's why I mentioned you find out if the information you need can be
    provided by them via an API or RSS feed.
    Well I won't be the only one using it. So would a form asking for the user's username and password work? And I don't believe they have an api or rss feed.

  • #12
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    If they have an RSS feed, you shouldn't need the login details otherwise the API would be the way to go. Failing both, you'd need to do some pretty fancy stuff involving getting the user login via a form, communicating with the server via cURL (with cookies and possibly SSL) and lots of regex or SimpleXML parsing.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #13
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,381
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    See post #8.

    You have to use PHP CURL POST ... no other way to do it.

    You also have to ask users to give you their username and password,
    which is probably going to happen on an unsecure server?

    I think you are "bumping" this thread in order to get an easy answer from someone.
    Nothing I can think of is easy. sorry.

  • #14
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by mlseim View Post
    See post #8.

    You have to use PHP CURL POST ... no other way to do it.

    You also have to ask users to give you their username and password,
    which is probably going to happen on an unsecure server?

    I think you are "bumping" this thread in order to get an easy answer from someone.
    Nothing I can think of is easy. sorry.
    bumped this thread because it was getting close to the 2nd page. True, I'd like there to be an easy answer (who wouldn't, right?) but I expected there wouldn't be an easy way to do this. I have been looking at curl login's and the one I'm using isn't working. It just shows a blank page.

    Code:
    <?php
    // INIT CURL
    $ch = curl_init();
    
    // SET URL FOR THE POST FORM LOGIN
    curl_setopt($ch, CURLOPT_URL, 'lockerz.com/auth/login');
    
    // ENABLE HTTP POST
    curl_setopt ($ch, CURLOPT_POST, 1);
    
    // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
    curl_setopt ($ch, CURLOPT_POSTFIELDS, 'handle=blahblah&password=blahblah');
    
    // IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
    curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    
    # Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
    # not to print out the results of its query.
    # Instead, it will return the results as a string return value
    # from curl_exec() instead of the usual true/false.
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    
    // EXECUTE 1st REQUEST (FORM LOGIN)
    $store = curl_exec ($ch);
    
    // CLOSE CURL
    curl_close ($ch); 
    
    return $store;
    
    ?>
    Last edited by elitis; 12-05-2010 at 02:48 AM.

  • #15
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    also, I just made a test account so you can see exactly what I'm talking about/ trying to do.

    Go to lockerz.com and login with the details: email:e.holloway01@yahoo.com and combination (password) is hellboy98

    Then go to http://www.lockerz.com/profile/114798 The javascript code will display the links of the decalz (which are products). Hopefully this helps you understand more of what I'm trying to do.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •