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.
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 ~
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)
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
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.
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
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.
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
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.
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.
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.
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;
?>
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.