-3

Guys,

What I am trying to do is load google.com with cURL and no matter what link is on the page, be it a google link or another domain), I want the script to precede: http://mydomain.com/tracker.php?

So, if the page contains a link like this:

http://somedomain.com/

then that should be replaced with:

http://mydomain.com/tracker.php?http://somedomain.com/

And, if the page contains link like this:

http://subdomain.somedomain.com/dir/sub-dir/page.html

Then, I want it to be replaced to:

http://mydomain.com/tracker.php?http://subdomain.somedomain.com/dir/sub-dir/page.html

You get my point ?

Here's my code but I get error:

Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\test\CURL_experiment1.php on line 13

Here's my code:

<?php
$url = "http://google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);

$pattern = 'http://';
$replacement = 'http://mydomain.com/tracker.php?';
echo preg_replace($pattern, $replacement, $result);

?> 
3
Contributors
8
Replies
51
Views
2 Months
Discussion Span
Last Post by JamesCherrill
3

Troll alert:
UI posts the same questions on multiple sites and doesn't mark threads "solved" when he has an answer.
Just sayin'

-2

James,

Why don't you reply and see whether I do or not ?
I'll prove you're wrong!

-1

Tried the following but still not working:

<?php
$url = "http://google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);

str_replace("https://","http://mydomain.com/tracker.php?https://","$result");
str_replace("http://","http://mydomain.com/tracker.php?http://","$result");
str_replace("localhost","http://mydomain.com/tracker.php?$url","$result");
echo $result;

?>

In short, all links on google homepage should be preceded by:
[url]http://mydomain.com/tracker.php?[/url]

Any links containing "localhost" should be replaced with:
$url.
And, that $url should be preceded by:
[url]http://mydomain.com/tracker.php?[/url]

So, a link that looks like this:
localhost/contactus.html
should be replaced by:
[url]http://mydomain.com/tracker.php?http://google.com/contactus.html[/url]

In short, all links on google homepage should be preceded by:
[url]http://mydomain.com/tracker.php?[/url]

Any links containing "localhost" should be replaced with:
$url.
And, that $url should be preceded by:
[url]http://mydomain.com/tracker.php?[/url]

So, a link that looks like this:
localhost/contactus.html
should be replaced by:
[url]http://mydomain.com/tracker.php?http://google.com/contactus.html[/url]

Edited by UI

-3

rproffitt,

This has not been solved. If it was, I'd share the knowledge (along with the code) in all places I asked so nobody bothers replying to something already solved and also so that they may learn from it too. You can clearly see from those 2 links, they aren't solved yet.

Ignore codingforums. It's there that they have problems me asking same questions on other forums or cross referencing their answers (as they put it). The 2 who were frequent repliers (I won't name them as I don't like backbiting) became sarcastic and very possessive in a way for me to take their answers as bible and forget others in other forums. One even started abusing there all the programmers in all forums who have ever replied to me by claiming everyone's wrong and only he is right. That nobody's got a clue what they are doing). And, over there, they always jumped to conclusions misreading things. Fed-up of them. They were too frequent in biting and so I struck back one day going in my teasing mood and teased them Whenever I got the chance and that made them shut-up for good. (I hope I don;t have to behave the same here with the likes if diafol. Frankly, I don't like youngsters. They are downright stupidly short circuit and rude). Now, they're on the defence ignoring me. I don't flame anyone when they bite too often. Metaphorically speaking, I tickle their mouths and make them vomit. That teaches them to stop biting. Haven't had same behaviour in any other places at that level yet. Even here, until tonight (Diafol I suspect will be trouble here from now on and a real put-off for me here and so I might aswell barr him from my threads. I don't like his lashing outs with bad language. How can I barr him as I can clearly see he has started to jump to conclusions misreading my intentions (like the other 2 in the other forum).

Remember, even if I get answers elsewhere, the newbies here are not getting those answers from there (unless ofcourse, I share the answers here or they signup to those forums too). Therefore, even if you spend your precious time replying to any threads of mine here that have duplicates on other forums, the newbies here (who are or will be loyal to this forum and won't prowl other forums) will benefit from your answers and your time contributions won't go to waste. Think rashionally. You can imagine you are not replying only to me but this forum's newbie present & future audiences. If you look closely, my questions are basic standard questions any adv level thinking newbie would have. Therefore, the answers would be beneficial to all times & ages (so to speak). Atleast, you have to agree to that without any second thought.

Anyway, this is a good thread topic. Right ?
Once you learn the basics, you can build your own proxy. And, even a bot. At the moment, I'm into the former. Later, will get into the latter.

Good night! Going to sleep. The summer heat is doing my head in. Not feeling well. By the time I feel better and check for answers on all forums, I hope my problems get solved.

Edited by UI

1

You've broken a few rules. By not revealing cross posts folk here and all over would repeat the same work and waste their time.

Others have called you on this and I get the feeling you don't agree on the rules. My advice is to recant now.

0

I was given your rules link by your mod just now but nowhere it says:

  1. I can't open threads here with same title opened in other forums.
  2. I have to reveal those other threads from other forums to members of this forum.

So, exactly which rule have I actually broken in this forum's TOS ?
I need the clause names and numbers from you to check them out. Can you atleast do that before complaining any further ?

Unless, all this is mentioned in the TOS, I'm not to know. I'm not psychic. I can't go into peoples' heads and see who likes what and what not.

I'm afraid you are going off-topic in this thread which the mod doesn't like anyone going offtopic. And now making me go off-topic
You could have PMed me your mssg instead.

And so, before I end, I'd like to drag this thread back to it's topic ...

Edited by UI

1

See my post here re the rules and members expressing their views.

the mod doesn't like anyone going offtopic

DaniWeb is moderated according to the TOS and Posting Rules. Any likes or dislikes that a mod may have can be expressed just like any other member's, but they do not influence their activity as a moderator. The Posting Rules include "Do ensure that all posts contain relevant content and substance"

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.