In Codeigniter, I have a database containing a link of a site.
Each item(event) has a link to the event page.
Site
But instead of going to the desired site, it just adds the link to the existing url like this: http://web.site.local/index.php/evenementen/www.referedsite.com
when checking the html code it shows the following:
Site
Does anyone know how to make it go to www.referedsite.com instead of making it add this to the existing link?
You need to put HTTP://
Site
In codeignitor you can use
echo anchor('', 'Site');
// Prints: Site
Read CI Anchor
try
Site
Related
I've created a page with an article. On top of that there's a title. If people try to click this title I want them to be redirected to the same page.
Like this: https://gyazo.com/74350b4fe91c670c4101449ee1c928a4 If I click on the article it just refreshes the page.
I can't do this manually for every article because I'm using a script.
The code I've written looks like this:
echo ' <h1 class="entry-title">'.$row['postTitle'].'</h1>';
As you can see I wrote
<a href="/">
and that's will not redirect me / refresh the page i'm viewing.
This is how it looks for me: https://gyazo.com/8a15ae274d8a7240b07100395460568d
as you can see it does not redirect me to the same page when i click the title.
How can I do this?
To make your custom PHP blog post template be able to display a title link that points back to the page, one way is to make use of your $row[.... variable.
Provided that,
your URLS will look like your screenshots, such as http://localhost/viewpost.php?id=8 when running locally and for example http://www.yourwebsite.com/viewpost.php?id=8 when online
you know how to refer to the post's id that is used in the ...viewpost.php?id=8, for example $row['postID']
you don't yet have any variable or means to refer to your current domain http://localhost when local or http://www.yourwebsite.com when online
Then, I recommend a two-part approach:
Somewhere at the top of your code, or perhaps in an include you might use for such code-reuse purposes, define for example $host:
$host='http://' . $_SERVER['SERVER_NAME'];
Then, for your actual title link::
echo ' <h1 class="entry-title">' . $row['postTitle'] . '</h1>';
Explanation
Separated HTML from the concatenation dots . with spaces, to be easier to read, as well as to support any helper programs such as fmt that you might use for wrapping long lines, so they have spaces to use for wrapping lines.
Uses PHP's predefined $_SERVER variable's SERVER_NAME , which, combined with the http://, the $host will be http://localhost when local and http://www.yourwebsite.com when online.
Define $host as a variable once at the top of the page, because it is clearer that way and likely you will have a use for it elsewhere on the page, so this helps avoid having to repeat yourself writing 'http://'.$_SERVER['SERVER_NAME'] everywhere else you may need to start forming the absolute URL
$host is then combined with the pattern for the rest of the URL, to assemble the absolute URL
Absolute URL is helpful so that if a user saves your article to their computer, then later clicks the title link on their locally saved article, the user can still correctly reach the original online page
As the article author, setting a link this way also means it can serve as a permalink, which helps with search engine optimization (SEO)
Please use # in href attribute! that will redirect you on the same page.
Problem solved. I used
echo '<h1>'.$row['postTitle'].'</h1>';
Thank you everyone.
Hi, I want to redirect my page to another website, I used anchor tag but when I click on this it will add my website name also
http://au.pricecomparereview.com/www.theiconic.com.au/Rococo-Textured-Mini-Skirt-113532.html
Please tell me about this . I am new in php I am using oscommerce
www.theiconic.com.au/Rococo-Textured-Mini-Skirt-113532.html
use like this, you may be missing http://
www.theiconic.com.au
If you want a PHP approach try this:
// Declare url variable
$url = "http://www.theiconic.com.au/Rococo-Textured-Mini-Skirt-113532.html";
// Use it to create the <a> with php
echo "www.theiconic.com.au";
Or with html use the PHP assing tags:
www.theiconic.com.au
I think your anchor tag would be like this presently:
www.theiconic.com.au
Change it to
www.theiconic.com.au
and it will work fine.
Not sure if this is possible but wanted to know if htaccess has a trick...
Say I have anchor tag href like this -
Click here
I have changed the URL structure using mod_rewrite but wanted to know if i can hide the actual URL in href using htaccess.
i.e when a user hover over the anchor tag, the browser displays http://example.com/index.php?id=12345 at the bottom. All I want the browser to display is http://example.com/index/12345 without changing it manually on all my pages.
Thanks for the help !
Why don't you change the link to the following?
Click here
As you can change the .htaccess I expect that you own or adminstrate this domain. So it should be possible.
If the links are generated by PHP code, then I suggest you to implement and use a translation function like:
function beautify($ugly) {
// your logic comes here
return $nice; // ;)
}
... and wrap it around the existing code that currently outputs the urls. This would have two advantages:
It's easy and more failsafe to migrate to the new url scheme
From now on you have control over all url related code using a single function
I agree, htaccess can't help you. I guess you'll have to change them manually.
I wish I could be of more help
No. htaccess is for processing input to the web server, not data sent back from the server.
If you use jQuery you could have it rewrite the href when the page loads using something like this.
$(function(){
$("a").each(function() {
this.href = 'some_new_url that you made based on the one in this.href';
});
});
I am trying to formulate a link to another page in my directory. It can either be done in the php code or the html. However for some strange reason, and only on this page, everytime i generate a url to a new page, the url generated is the page i am on + the url i want to go to.
For example, if i am on mysite.php and formulate a link to go to purchase.php then the generated url is mysite.php/purchase.php
Does anyone know why this might be?
<h1>Success</h1>
Link text
<?php
...
...
?>
this is essentially all i have with an echo saying hi! . What happens is, if i am currently on home.php the above url becomes path/home.php/page.php
You should create url for /purchase.php instead of purchase.php.
You can read more about what's the difference in here.
Hello I am trying to figure out how to make it so when someone clicks a link on my search results it will open in a new window and in the new window have an iframe that displays the url. I am not sure how to go about doing this. I have
$row['url']
that displays the url for each result to use.
To be more specific I am trying to do what filestube does. I like the feature a lot and would like to use something like it on my site. Here is an example url to show you want I mean http://www.filestube.com/5a4c10249bd9fce003e9/go.html
when the link is clicked on filestube it will open a page like this. I have seen lots of sites do this but filestube is what pops in my head right now. Can anyone provide me with a code example or try to explain how to do this? thanks.
You need to redirect to a URL inside of your application, example my_url.php and post to it in parameters the URL you want to show. Than in that script, load an iFrame with that URL.
Example of my_url.php?url=http://www.google.ca:
<div>You Header</div>
<iframe src="<?php $_GET['url']"></iframe>
<div>Your Footer</div>
The link should point to another PHP page. Something like this.
http://www.google.com
In your open-link.php, write your iframe code.
<iframe src="<?=$_GET['url']?>"></iframe>
Assuming you have PHP file named external.php
Make that PHP file accept a $_GET parameter.
Pass the URL as a param
Use that URL to point the iframe in that PHP file to whatever URL is passed