PHP snippet id in url

I have a pretty dilemma here, and I would like to receive some suggestions from the community. Here is my problem:

I created a website with a lot of dynamic content, all content is pulled through AJAX and displayed through JS. The way I currently allow direct links to my content is to change the fragment identifier on the fly using JS, here is an example:

http://www.mysite.com/home#/123

Where 123 is the content identifier. When the content is closed, it again disables the fragment identifier.

This works great, and when people load the page, my AJAX request successfully requests the article “123”. But I just implemented the Facebook button on all of the articles, and now I hit a brick wall.

Basically, how Facebook discovers that thumbnails and headers and URLs to link to your “favorite” content are checking the meta tags of the URL passed to fb, for example, iframe. He does this by executing a GET request at the URL, checking the contents of the meta tags, and then displaying it on Facebook.

The problem is that the fragment identifiers are not passed to the server, so I have no way in PHP (I know) to dynamically generate these meta tags with content from a specially requested article.

For example, I wanted to be able to do something like this:

$id_vals = get_id_values($hash_fragment);
echo '<meta property="og:title" content="'.$id_vals['title'].'" />';

Perhaps your first thought came up: why not use a GET request or query string? i.e:.

http://www.mysite.com/home?id=123

, Javascript URL-, . , . "" , - , :)

, . , , :

fb get, - .

:

  • Facebook , , Facebook.
  • - , URL-, ID (.. , GET ). , FB , .

! , .

EDIT: , , , Facebook , . !

EDIT EDIT: "mix" - window.location PHP header(), Facebook , .

.

+5
3

URL- hashbang #!, Facebook Google AJAX.

URL-, #!, , GET ?_escaped_fragment_=. GET, .

+3

index.php ['refer'], Navigasyon.js id /kill , , , !

<?php session_start(); ?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Boom - test</title>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/Navigasyon.js"></script>
    </head>
    <body onLoad="if (location.href.indexOf('/kill')==-1) location.replace(location.href+'/kill')">
        <?php
//echo $_GET['url'];
//echo parse_url();
//echo $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"].$_SERVER['PHP_SELF'];;
        if (isset($_SESSION['refer']))
            echo $_SESSION['refer'];
        ?>
    </body>
</html>

Navigasyon.php ! ajax navg.php , , php a/kill frag,

var whereAmI = window.location.hash;
var prsdUrl = window.location.hash.split("/");
var a = 0; //#!
var b = 1; //Sayfa dil
var c = 2; //Sayfa id

if(prsdUrl[a] == "#!")
{
    $.post("navg.php", {
        refer: whereAmI
    },
    function(data) {
        //if(data='ref') document.location.reload();
        if(data==whereAmI) {
            if(prsdUrl[c] != 'kill') {
                document.location.reload();
            }
        } 
    });
}

navg.php , !

<?php
session_start();
$_SESSION['refer'] = $_POST['refer']; ?>
<?php echo $_SESSION['refer'];
?>
+2

PHP parse_url , -, parse_url fragment

$url = 'http://www.mysite.com/home#/123';
$parts = parse_url($url);
$fragment = $parts['fragment']; // => '/123'

, , component PHP_URL_FRAGMENT

$fragment = parse_url($url, PHP_URL_FRAGMENT); // => '/123'
0
source

All Articles