-4

I'm trying to like my page but the url parameters are ignored

Here is my code:

<style type="text/css">
.float-all {
    float: left;
    width: 82px;
    height: 30px;
    overflow: hidden;
    margin: 2px;
    padding: 4px 2px;
}
.post-btn-share {
    width: 100%;
    overflow: auto;
}

    <link rel="canonical" href="http://mypage.com/view_photo.php" />
    </head>
 <div class="post-btn-share">
<div class="addthis_toolbox addthis_default_style">
    <div class="float-all">
 <iframe src="http://www.facebook.com/plugins/like.php?href=http://mypage.com/view_photo.php?       img=32&user=1&xx=&send=true&layout=standard&width=300&show_faces=true&action=like&colorscheme=light&font&height=80" frameborder="0" style="border:none;" scrolling="no" width="320" height="240"></iframe>
    <div class="float-all">

    </div>
    <div class="float-all">

    </div>
</div>

And view_photo code

<?php 
    session_start();

?>

<div class="dev-ajuste">
<?php 

    require_once('script/require_raiz.php');
    $login = new login();
    $login->log_isset();
    //$login->info_user();
    $janela = new Janelas('script/system/config.ini','perfil');
    $janela->info_visualiza_foto($_GET['img'],$_GET['user']);
?>
</div>
 <!--=======Cabeçalho e chamadas de scripts do documento=======-->
<?php include_once("head.php"); ?>
 <!--=======Barra de navegação=======-->
<?php include_once("navbar.php"); ?>
<div id="janela" class="perfil"></div>
<div id="info"   class="<?php echo $_GET['user'];?>"></div>

 <!--=======Header=======-->
<?php include_once('box_foto.php'); ?>

    <!--=======Propaganda=======-->
    <?php include('addsense.php');?>

    <!--=======Área dos posts=======-->
     <?php include('post_area.php');?>

 <!--=======Rodapé do documento=======-->
<?php include_once("footer.php"); ?>
 <!--=======Seguranca de Login=======-->
8
  • I think you need to urlencode the parameters. Commented Apr 17, 2013 at 12:24
  • Looks like you might want to URL-encode some of that. I doubt any reasonable parser is going to make sense of it. Commented Apr 17, 2013 at 12:24
  • 1
    Every occurrence of &amp; needs to be &. Commented Apr 17, 2013 at 12:24
  • 1
    @illDev: php.net/manual/en/function.urlencode.php Commented Apr 17, 2013 at 12:25
  • 1
    @illDev: Your edit didn't URL-encode anything. Given the URL in that iframe, it would be impossible for any parser to know how to apply those parameters. Do they apply to the outer URL or the inner URL? There's no way to know. You need to URL-encode anything that gets passed as a parameter to the primary resource so that it can parse those parameters. Commented Apr 17, 2013 at 12:37

2 Answers 2

1

(Turning a comment chain into a potential answer)

I really don't think you've understood. Look at the URL being used in the iframe:

http://www.facebook.com/plugins/like.php?href=http://mysite.com/view_photo.php?img=34&user=1&xx=&;send=true&;layout=standard&;width=300&;show_faces=true&;action=like&;colorscheme=light&;font&;height=80

In a URL, parameters being sent to the resource start at the ? character. But you have two ? characters. Do the parameters start at the first one or the second one? A parser has no way to know. When a & is encountered, is that separating a parameter for the outer URL (the first ?), or one being enclosed with the inner URL (the second ?)? A parser has no way to know.

The format needs to be like this:

http://someresource?parameter1&parameter2&etc

If one of those parameters is also a URL with its own parameters, that entire parameter needs to be URL-encoded so it doesn't confuse the rest of the URL for which it's being used as a parameter. Any parser has to be able to clearly identify what goes with the inner-URL and what goes with the outer-URL. It will URL-decode the inner one for you when it needs to use it.

PHP provides a function to do this. So does JavaScript. You can use whichever you'd like. All you do is pass it the string to be encoded (which would be your inner URL with whatever parameters need to go to that URL) and it will return the encoded string (which would be the parameter to send to your outer URL).

(Also, why do you have all those semi-colons? You don't separate URL parameters with semi-colons. I'm not sure where you got that idea.)

Sign up to request clarification or add additional context in comments.

5 Comments

I did copy from the official facebook page and there have somi-colons. But in my case, how I encode the url? see my view_photo..what I need to do there?
and I have only one ? where did you see 2? The first is the sintaxe from facebook .... look felipems.com.br/blog/?p=88
@illDev: That's not the syntax from Facebook. That's the syntax from somebody's blog. And that somebody is incorrect. Look at your URL. There is a ? after like.php and there is another ? after view_photo.php. Two. And there should not be semi-colons. Facebook doesn't have them, and the blog you showed me doesn't have them. I don't know where you got them but they shouldn't be there.
@illDev: You can perform the URL encoding either in your PHP code or your JavaScript code. (Or manually if the URL isn't dynamic.) You just need to end up with an encoded URL. Where you do it is entirely up to you and not really determined from the code in the question. You can see some examples here: stackoverflow.com/questions/2540944/…
I did test my encoded url in facebook debug and the result was Redirect Path URL entered: http%3A%2F%2mypage.xom%2Fvisualizar_foto.php%3Fimg%3D55%26user%3D2%26xx%3D original: mypage.com/visualizar_foto.php?img=55&user=2&xx 302: mypage.com/02-facelogin.php
0

Go to this page and check the link of the like button which is show in the picture below:

enter image description here

You right click and inspect it. You see:

enter image description here

You see that it is urlencode'd. And the reasoning is very well explained by David :)

2 Comments

where? pls , copy the link of the like button
it's right? <script> var url = urlencode('mypage/visualizar_foto.php?img=55&user=2&xx='); alert(url); </script> <iframe src="facebook.com/plugins/like.php?href=" + url + "&send=true&layout=standard&width=300&show_faces=true&action=like&colorscheme=light&font&height=80" frameborder="0" style="border:none;" scrolling="no" width="320" height="240"></iframe>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.