Jump to content

cURL Help


killah

Recommended Posts

I am currently stuck on a solution. Let me explain, i have built a script which will take my test site & register the account, after that it then log's the account in.

 

After the account has logged in. I need it to send it to another script.. Ok i got the script working to this part. The script basicly work's like this.

 

Post form data -> register.php -> login.php -> mailbox.php?action=send

 

so far that work's and send's the mail. My problem stand's that the user were sending to, can be anything. This is why i have came here.

 

I need my curl script to send to usersonline.php and get a name inbetween a url link (<a href='viewuser.php?u=xx'>YY</a> xx => id, YY => name), i need to grab YY and put it in an array, so i can use it later on.

 

Is there anyway to grab a name inbetween a html tag using cURL?

 

I have the rest covered by going to usersonline.php and all.

 

Thank's.

Link to comment
Share on other sites

Idk much about DOM, I've only heard it's the better option.

 

Regex would probably be something like this

 

preg_match($curl_return, '/<a href=\'viewuser\.php?u=[a-z]\'>([a-z])<\/a>/isS', $matches);
print_r($matches);

Link to comment
Share on other sites

This is what i got:

 

$mat = htmlentities(curl_exec($log));
preg_match('~<a href=\'viewuser.php?u=(.?)\'>(.?)</a>~isS', $mat, $matches);
print_r($matches);

 

except it doesnt pick up the \'viewuser.php?u=xx\'

 

if i change my pattern to '~<a>' it picks up every link on the site.

Link to comment
Share on other sites

Ok, let me explain this bit.

 

Basicly it log's into a full layout site, thus is why im using htmlentities/htmlspecialchars..

 

I need to search then for &lta href='viewuser.php?u=[0-9]'>[a-z0-9 _-!]</a>

 

Hope you can maybe figure a solution to that :P

Link to comment
Share on other sites

Here's an update.

 

curl_setopt($log, CURLOPT_URL, $url.'/usersonline.php');
$mat = str_replace(array('<','>'),array('[',']'), curl_exec($log));
echo $mat;
$mat = preg_replace('~\[a href=\'viewuser.php?u=(.*)\'\](.*)\[/a\]~is','[pid]$2[/pid]', $mat);
preg_match('~\[pid\](.*)\[/pid\]~is', $mat, $matches);
print_r($matches);

 

It displays:

 

[a href=viewuser.php?u=2]Kyle[/a]

 

But it simply won't grab the bit inside ]YY[

 

 

I just noticed your using preg_match when it's supposed to be preg_match_all, but now my array returns:

 

Array ( [0] => Array ( ) [1] => Array ( ) )

Link to comment
Share on other sites

<?php

$curl_return = '<a href=\'viewuser.php?u=something\'>username</a>';

$curl_return = str_replace(array('<', '>'), array('[', ']'), $curl_return);


preg_match('/\[a href=\'viewuser\.php\?u=[a-z]+\'\]([a-z]+)\[\/a\]/i', $curl_return, $matches);
print_r($matches);

Come on..surely you can adapt this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.