Jump to content

How to read incoming url ? Read hyperlink from same site


oli22

Recommended Posts

Trying to get this done:

 

Page_1 has many external links, when certain links are clicked i do not want user to go directly to page, but rather go to a special add page_2 where user must click a second time on the link to finally get there.

 

The add page_2 must show on screen the name of the initial link from page_1, it must change accordingly with the link it came from page_1,once on page_2 the hyperlink redirects outside the site.

 

So far i am thinking give an id to the div or "<a href..." on page_1 then somehow have page_2 detect that id and fill in the variable for the final external link. Other wise is there a way to detect a url from incoming?

 

I guess a similar example is how some domain name sellers landing page will indicate the name of the site. Such as "Thisdomain.com" is for sale. same landing page but the name changes according to the domain that was typed.

 

 

 

I tried to apply this many ways and i don't know how. I am really new to php so i will ask if you can please explain further.

Here is the basic code layout:

 

How exactly would you do it, for example if i had a link for  http://www.google.ca

 

Page1.php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

<body>

<div>

<a href="page2.php?url=<?=urlencode($url_clicked)?>">Link Title</a>

</div>

</body>

</html>

 

Page2.php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

 

<div>

 

$_GET['url']

 

</div>

</body>

</html>

 

$url_clicked was just an example of a possible URL. Just replace it with the link you want if you are not generating the URLs dynamically.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div> 
<a href="page2.php?url=<?=urlencode("http://mysite.com")?>">Link Title</a>
</div>
</body>
</html>

 

Then for accessing the URL:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<div> 

<?=$_GET['url']?>

</div>
</body>
</html>

 

Is the URL variable populated in the address bar in your browser when you click the link?

 

Your server might not have short tags enabled so you may have to do this:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div> 
<a href="page2.php?url=<?php echo urlencode("http://mysite.com"); ?>">Link Title</a>
</div>
</body>
</html>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<div> 

<?php echo urldecode($_GET['url']); ?>

</div>
</body>
</html>

 

Ok it is partially functional !

 

It is  effectively returning the " http://mysite.com " value to page2.php so i inserted it into a hyperlink like this:

 

Proceed to: <a href="<?php echo urldecode($_GET['url']); ?>">          </a>

 

Finally how do i get the value of "Link Title" on page1.php to appear in the  <a href.....>  make it appear here      </a>

 

The reason is many outbound links will go to the same add page before user leaves site

 

so far i was trying to use the same technique, but still haven't found.

You'll need to pass that info through the first url as well.

 

<a href="page2.php?url=<?php echo urlencode("http://mysite.com"); ?>&title=<?php echo urlencode("Link Title"); ?>">Link Title</a>

 

Then similar on page 2.

 

<a href="<?php echo urldecode($_GET['url']); ?>"><?php echo urldecode("Link Title"); ?></a>

;) That was almost it except that

 

<a href="<?php echo urldecode($_GET['url']); ?>"><?php echo urldecode("Link Title"); ?></a>

 

is---------------------------------------------------------------- <?php echo urldecode($_GET['title']);?></a>

 

I guess you wanted to see if i was listening! As i said links will go to this add page and i the only thing i want to edit on this page is the adds. The rest is automatic.

 

Thank you so much for your help

 

This is fresh of the shelf so i may still develop this idea further:

Like the capacity to turn this script on and off, still got energy today?

  • 1 month later...

Hi i'm back

 

Now i would like to be able to turn this script on and off depending on if i want to show users an exit message or not when they click external link.

So instead of having link go from page1 to page2 to external link, hyperlink would go from page1 directly to external link.

 

I was thinking that it would be possible with a if/else and a true/false boolean, what do you suggest?

 

This is the script so far:

<body>

<div>

<a href="page2.php?url=<?php echo urlencode("http://www.google.ca"); ?>&title=<?php echo urlencode("google"); ?>">google</a>

 

 

 

</div>

</body>

 

page2:

<body>

 

<div>

 

proceed to<a href="<?php echo urldecode($_GET['url']); ?>"> <?php echo urldecode($_GET['title']);  ?> </a>

 

</div>

</body>

 

 

This is my amateur logic so far, but of course it is mot working, help me please anyone!

 

I have modified the second page like this:

 

<body>

 

<div>

<?php

$ad_linker=TRUE;

$URL= <?php echo urldecode($_GET['url']); ?> ;

?>

 

<?php

if ($ad_linker=TRUE)

                  {

                  echo "proceed to<a href="<?php echo urldecode($_GET['url']); ?>"> <?php echo urldecode($_GET['title']);  ?> </a>" ;

                  }

else($ad_linker=false)

                  {

                  echo "header("Location: $URL ")";

                  }

 

?>

 

</body>

This is another idea for page2, but still not working Parse error on -->$linker=TRUE ???

 

<body>

 

<div>

<?php

$linker=TRUE

 

if(linker==TRUE)

{

echo "proceed to" <a href= <?php echo urldecode($_GET['url']); ?>> <?php echo urldecode($_GET['title']); ?>  </a>

}

else

{

echo header('Location: '.$_GET['url']); exit();

 

}

?>

</body>

 

Could someone please help me clean and fix it?:'(

ok  Pikachu2000 i did this

<body>

 

<div>

<?php

$linker=TRUE;

 

if(linker==TRUE)

{

echo "proceed to" <a href= <?php echo urldecode($_GET['url']); ?>> <?php echo urldecode($_GET['title']); ?>  </a>;

}

else

{

echo header('Location: '.$_GET['url']); exit();

 

}

?>

</body>

but i get error here:

Parse error: parse error, expecting `','' or `';'' in C:          on line 19

Line19 is

echo "proceed to" <a href= <?php echo urldecode($_GET['url']); ?>> <?php echo urldecode($_GET['title']); ?>  </a>;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.