954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

URL in PHP

I need a help here, There's an error every time I add a link in my php file.
Example:

<php
$link = "twitter.com";
echo "<a href = '".$link."'> link </a>";
?>

on click, the address would be change on "http://localhost/project/twitter.com" whch is supposed to be "twitter.com"
I've tried placing

<?php
$link = "twitter.com";
echo "<a href = '../../".$link."'> link </a>";
?>


but still it doesn't work. $link is stored in the database.
I'm new here. Please help me.

helpmmeworld
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

try like this

$link = "www.twitter.com";
<a href ="<?=$link?>"> link </a>
raju_boini525
Junior Poster in Training
53 posts since Aug 2009
Reputation Points: 10
Solved Threads: 7
 

That happens because if you don't put a protocol in a link it will be interpreted as a subdirectory so if you want to make an external link you should put

http://|https://|ftp://


etc so in your case it would be

$link = "http://www.twitter.com";
<a href ="<?=$link?>"> link </a>
ax8l
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 2
 

You can try these kind of things without www. or http:// in your browser but not with the codes, code strictly first refers to your local. So that only it retrieves your php localhost and tried from there.

rajarajan07
Nearly a Posting Virtuoso
1,447 posts since May 2008
Reputation Points: 167
Solved Threads: 239
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: