How can I?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bigjoe
Forum Newbie
Posts: 1
Joined: Thu Mar 04, 2004 3:04 pm

How can I?

Post by bigjoe »

I am trying to find/create a simple script that will tell me where a coded link lands. For example

http://www.awin1.com/tclick.php?id=11738&mid=72 lands at http://www.groovychocolate.com

I want to be able to input the awin url and output the groovychocolate url

Any ideas?

Rgds
geekdesign
Forum Newbie
Posts: 1
Joined: Thu Mar 04, 2004 3:46 pm

Post by geekdesign »

I hope I understand what you want so if the does not help can you be a little more specific. You want something like what they are doing.

First somewhere you have a table with some informations of links and whatever where each one has it own ID or something.

Second you create a script I don't know call it redirect.php or somthing like that. In that script you want to do the following.

Code: Select all

<?php

  //Connect to database
  //You may want to use error checking I am just stopping errors by using the @ sign
  $link_id = @mysql_connect("host", "username", "password");

  //Select your database
  @mysql_select_db("database", $link_id);

  //Query for pulling links from table
  $query = "SELECT url_link FROM table_name WHERE url_id = '$url_id';";

  //Get the results from the query
  $results = @mysql_query($query, $link_id);

  //Fetch the results
  $row = @mysql_fetch_row($results);

  //Get the url  
  $my_url = $row[0];

  //Close the database
  @mysql_close($link_id);

  //Redirect to the page
  header("Location: " . $my_url);
  exit;

?>
I hope this helps.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

hes nto asking for a script that does it, he is asking for a way to tell where someone else's script redirects to.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

And if that is the question... the answer is nowere!

These links are NOT coded you are talking about variables being passed in the URL corresponding to links stored in a database.

The onlyway you can know the links is by clicking on them or having access to the db table.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

or by making the request to that page and parse the Location header ;). Here is an example:

Code: Select all

$check=$_GET["check"];
$cx=curl_init($check);
curl_setopt($cx,CURLOPT_HEADER,true);
curl_setopt($cx,CURLOPT_NOBODY,true);
curl_setopt($cx,CURLOPT_RETURNTRANSFER,true);
$ret=curl_exec($cx);
preg_match("/Location: (.*)/",$ret,$matches);
echo $matches[1]."\n";
use it as follows:
http://yourhost.com/yourscript.php?chec ... 738&mid=72
Post Reply