Php link code
Moderator: General Moderators
Php link code
Is ther any code I can put into my php pages that will create a link as follows:-
The domain the link will be on is domain1.com
and for each page within that domain I need it to produce a link for the same page but on a different domain.
for example, say I had a page http://www.domain1.com/foobar.php
I need a link at the bottom of the page that links to http://www.domain2/foobar.php with the text 'old page'
As my site has thousands of pages genrated from a template I can't create a manual link for each one so I need some code that will generate it.
Any help would be fantastic and much appreciated.
Thanks
The domain the link will be on is domain1.com
and for each page within that domain I need it to produce a link for the same page but on a different domain.
for example, say I had a page http://www.domain1.com/foobar.php
I need a link at the bottom of the page that links to http://www.domain2/foobar.php with the text 'old page'
As my site has thousands of pages genrated from a template I can't create a manual link for each one so I need some code that will generate it.
Any help would be fantastic and much appreciated.
Thanks
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
look into using parse_url()
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Example 1. parse_url() example
Code: Select all
$ php -r 'print_r(parse_url("http://username:password@hostname/path?arg=value#anchor"));'
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
$ php -r 'print_r(parse_url("http://invalid_host..name/"));'
Array
(
[scheme] => http
[host] => invalid_host..name
[path] => /
)A little too complex for my needs.
Worked for my needs.

Code: Select all
<a href="<?php echo "http://www.domain2.com".$_SERVER['PHP_SELF'] ?>">Old Page
</a>Drat
Found a flaw in it.
Although that code works on a lot of my pages. On my store section my pages use mod rewrite so it takes a http://www.domain1.com/product_info.php?products_id=1 page and rewrites it to http://www.domain1.com/product-name.html but the code generated on the page for my link using the above code just states the http://www.domain2.com/product_info.php which isn't what I need.
Anyone know a work around for this?
Found a flaw in it.
Although that code works on a lot of my pages. On my store section my pages use mod rewrite so it takes a http://www.domain1.com/product_info.php?products_id=1 page and rewrites it to http://www.domain1.com/product-name.html but the code generated on the page for my link using the above code just states the http://www.domain2.com/product_info.php which isn't what I need.
Anyone know a work around for this?
Thanks for the help so far. 
Still not quite right though...
If I use the following code:-
It returns the following link http://www.domain2/catalog/index.phpcPath=1_31
Thats wrong on two accounts
1) there should be a ? between php and cpath like index.php?cPath=1_31
2) Thats the un altered link before modrewrite changes catalog/index.php?cPath=1_31 to /catalog/category_name.html so the link that its generating to the old page is one that the search engines would of had indexed anyway so is irrelevent.
Anyone know of a fix? I need it to link to exactly whats shown in the adress bar with the only difference being the domain name.
Still not quite right though...
If I use the following code:-
Code: Select all
<a href=" <?php echo "http://www.domain2.com".$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'] ?>" class="emailNav1">Old page</a>Thats wrong on two accounts
1) there should be a ? between php and cpath like index.php?cPath=1_31
2) Thats the un altered link before modrewrite changes catalog/index.php?cPath=1_31 to /catalog/category_name.html so the link that its generating to the old page is one that the search engines would of had indexed anyway so is irrelevent.
Anyone know of a fix? I need it to link to exactly whats shown in the adress bar with the only difference being the domain name.
Last edited by fredski on Mon Oct 10, 2005 8:04 am, edited 1 time in total.
Cheers Nathaniel,
That did the trick just fine
The following code gives me exactly whats displayed in the address bar with a different domain name
Magic, now when the search engine comes to my new pages it will see the link to the old page, follow it and find a 301 back to the page on new domain. That way it will know to take out the old pages from its index and replace with the new ones much better than if I just had a 301 on the old domain without any links on the new.
That did the trick just fine
The following code gives me exactly whats displayed in the address bar with a different domain name
Code: Select all
<a href=" <?php echo "http://www.domain2.com".$_SERVER['REQUEST_URI'] ?>" class="emailNav1">Old page</a>