Am using facebook share code, but dont know how to customize the url part so that user who is on that url page should be shared instead of default url.
My current code is like
<a onclick="window.open('http://www.facebook.com/sharer/sharer.php/?
u=mycarhelpline.com', 'newWindow', 'width=600, height=400'); return false;"
href="http://www.facebook.com/sharer/sharer.php/?u=mycarhelpline.com" target="_blank"
rel="nofollow">
I need to customize the line
?u=mycarhelpline.com
with a php code that so that url which is been accessed by the user should come in share window instead of default home page.
(Know that Share option is deprecated, but sharing works for me - look for help to customize the code of sharing url
Thanks
Edited
Hi have put in revised code, i know am doing some error - pl help n suggest for rectification
<?php
$server_name = 'mycarhelpline.com';
$current_path = $_SERVER['REQUEST_URI'];
$sharerpath = 'http://www.facebook.com/sharer/sharer.php/?u='.$server_name .'/'.$current_path;
?>
<a onclick="window.open('http://www.facebook.com/sharer/sharer.php/?u='.$sharerpath', 'newWindow', 'width=600, height=400'); return false;"
href="http://www.facebook.com/sharer/sharer.php/?u='.$sharerpath''" target="_blank"
rel="nofollow"><img src="/templates/mycar_home/images/facebook.png" alt="Share on Facebook" /></a>
Now when i put ?> after tag, its showing server error and is not displaying page and when put before http://www.facebook.com/sharer/sharer.php/?u='.$sharerpath
If I understand correctly, you want the share plugin to simply share the current page the user is on. For this you will have to customize the plugin. Every time you place the share code on your page, you'll have to specify what page the user is on.
You can use parameters within the $_SERVER variable for this. You already know the server name, then you have the REQUEST_URI which is the URI which was given in order to access this page. So if you combine them you should reach a final URL for each page.
$server_name = 'mycarhelpline.com';
$current_path = $_SERVER['REQUEST_URI'];
$sharerPath = 'http://www.facebook.com/sharer/sharer.php/?u='.$server_name .'/'.$current_path;
References -
$_SERVER
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.
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
I hope someone can help me with this issue. So, I have a large website (1000+ webpages) and I want to put an iframe window on every page. My aim is to make this iframe load specific content according to the parent url address of each page on my website.
For example, when the user on my site loads www.mysite.com/Page-1, I want the iframe window to show ExternalPage-A, or when the user loads www.mysite.com/Page-2, I want the iframe to show ExternalPage-B.
Can someone give me an advise how to do it? Should I make a separate php document that will load in the iframe, where to put all the external links? Then, I should take somehow the parent url and tell the php document which link to be displayed. I am not very familiar with php and that is why I am asking.
Thanks!
Don't use $_SERVER['HTTP_REFERER'] because it won't always contain any data. This is set at the user's end, it cannot be trusted and isn't always set.
You would be better with your referring URL's and corresponding iframe URL's in a database. But putting a database to one side for a moment you could do something like this:
<?php
function get_iframe_url ($page) {
$page = parse_url ($page, PHP_URL_PATH);
/* Substitute the below IF statement for a database lookup
if you have lots of pages */
if ($page == '/news.php') {
return 'http://www.bbc.co.uk/news/';
} elseif ($page == '/contact.php') {
return 'http://www.yellowpages.com/';
}
}
?>
Then you can include this on every page:
<iframe src="<?php echo get_iframe_url ($_SERVER['REQUEST_URI']); ?>"></iframe>
I am building a facebook like button , in the href tag i want to keep my own custom url stored in php variable. But the like button doesn't shows with it. Any solution
CODE
<?php echo '<fb:like href=" '.$urlToLink.' " width="450" layout="box_count" show_faces="false" send="false"></fb:like>'; ?>
$urlToLink has somethig like this-> "http://localhost/website/view.php?asdpfimi34mmksd"
Put the URL in the debugger and check it for Errors/Warnings: https://developers.facebook.com/tools/debug
Also, try the URL in the Plugin generator: https://developers.facebook.com/docs/reference/plugins/like/ - and see if it gets rendered correctly.
And i hope you´re not serious with "localhost", because that will not work, of course. Facebook does not have access to your localhost, and the URL you provide has to be accessible in public, without any user login.
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