Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-04-2010, 12:41 AM   PM User | #1
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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.
elitis is offline   Reply With Quote
Old 12-04-2010, 12:57 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,044
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Describe more what it does ...
PHP can't read specific form fields in real time like JS can.
mlseim is offline   Reply With Quote
Old 12-04-2010, 12:58 AM   PM User | #3
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Old 12-04-2010, 01:22 AM   PM User | #4
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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.
elitis is offline   Reply With Quote
Old 12-04-2010, 01:42 AM   PM User | #5
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,044
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 12-04-2010, 01:59 AM   PM User | #6
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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..
elitis is offline   Reply With Quote
Old 12-04-2010, 06:32 PM   PM User | #7
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
bump.
elitis is offline   Reply With Quote
Old 12-04-2010, 07:00 PM   PM User | #8
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,044
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 12-04-2010, 07:07 PM   PM User | #9
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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
elitis is offline   Reply With Quote
Old 12-04-2010, 10:09 PM   PM User | #10
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,044
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 12-05-2010, 12:34 AM   PM User | #11
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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.
elitis is offline   Reply With Quote
Old 12-05-2010, 01:02 AM   PM User | #12
Lamped
Super Moderator


 
Join Date: Feb 2009
Location: England
Posts: 539
Thanks: 8
Thanked 63 Times in 54 Posts
Lamped will become famous soon enough
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
Lamped is offline   Reply With Quote
Old 12-05-2010, 02:05 AM   PM User | #13
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,044
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 12-05-2010, 02:45 AM   PM User | #14
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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..
elitis is offline   Reply With Quote
Old 12-05-2010, 02:53 AM   PM User | #15
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
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.
elitis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:14 AM.


Advertisement
Log in to turn off these ads.