How can i learn redirected page?

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
ozberk
Forum Newbie
Posts: 2
Joined: Sat Dec 06, 2008 2:27 pm

How can i learn redirected page?

Post by ozberk »

Hi, i have links that redirected to some pages like

http://www.domain.com/redirect.php?id=213

i want to learn page that redirected from this links.

how can i do it?

thank you....
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: How can i learn redirected page?

Post by dude81 »

Code: Select all

echo $_SERVER['HTTP_REFRER'];
... but people say, this source is usually not to be trusted
ozberk
Forum Newbie
Posts: 2
Joined: Sat Dec 06, 2008 2:27 pm

Re: How can i learn redirected page?

Post by ozberk »

no i cant explain clearly sorry....


http://www.domain.com/redirect.php?id=213 => http://www.domain2.com/news.php?id=23432

like this and i want to learn this from my web site... my database has link that redirect(domain.com in example), but i want to collect redirected original web site (domain2.com in example.)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How can i learn redirected page?

Post by requinix »

If you use cURL you can find out where you get redirected.

Code: Select all

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_NOBODY, 1);
curl_exec($curl);
 
$info = curl_getinfo($curl);
echo "Final location: ", $info["url"];
semas
Forum Newbie
Posts: 10
Joined: Sat Oct 25, 2008 11:00 am

Re: How can i learn redirected page?

Post by semas »

Code: Select all

$query = mysql_query("SELECT * FROM links WHERE id=\"{$_GET['redirect']}\""); //sends query t
if(mysql_num_rows($query) > 0){ //checks if there is record in mysql with id typed in url
    $row = mysql_fetch_array($query); //add line into array listed by id
    mysql_query("UPDATE links SET clicks=clicks+1 WHERE id={$_GET['redirect']}"); //my links has clicks so it updates it
    echo "              <meta http-equiv=\"REFRESH\" content=\"0;url={$row['link']}\">"; //makes browser redirect to that page  with id listed on url
}else {
    echo "              <meta http-equiv=\"REFRESH\" content=\"0;url=$site_link\">"; //else it redirects to main page
}
Im using this code to redirect
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: How can i learn redirected page?

Post by greyhoundcode »

Just personal preference, but I tend to execute redirects with:

Code: Select all

header("Location: $URL");
exit();
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: How can i learn redirected page?

Post by mmj »

semas wrote:

Code: Select all

$query = mysql_query("SELECT * FROM links WHERE id=\"{$_GET['redirect']}\""); //sends query t
if(mysql_num_rows($query) > 0){ //checks if there is record in mysql with id typed in url
    $row = mysql_fetch_array($query); //add line into array listed by id
    mysql_query("UPDATE links SET clicks=clicks+1 WHERE id={$_GET['redirect']}"); //my links has clicks so it updates it
    echo "              <meta http-equiv=\"REFRESH\" content=\"0;url={$row['link']}\">"; //makes browser redirect to that page  with id listed on url
}else {
    echo "              <meta http-equiv=\"REFRESH\" content=\"0;url=$site_link\">"; //else it redirects to main page
}
Im using this code to redirect
greyhoundcode wrote:Just personal preference, but I tend to execute redirects with:

Code: Select all

header("Location: $URL");
exit();
A little from the first post and a little from the second:

Code: Select all

 
header('Refresh: 0');
 
Perfect. :P
Post Reply