Love2c0de Posted February 9, 2013 Share Posted February 9, 2013 (edited) Hi guys and girls, I'm passing some data through the url such as the name of a game to be used later in a query. Not highly sensitive but I wanted to rawurlencode it. Can't seem to ever be able to use functions within urls. Here is what I've got: <?php if(isset($_SESSION['username'])) { /* echo "<div id='home_link_div'>"; echo "<a href='?page=home'>ALL</a>"; */ echo "<a href='?page=home&g=",rawurlencode("Battlefield 3"),"'>BF3</a>"; /* echo "<a href='?page=home&g=Counter-Strike 1.6'>CS 1.6</a>"; echo "<a href='?page=home&g=Counter-Strike: Source'>CS:S</a>"; echo "<a href='?page=home&g=Deus Ex'>DX</a>"; echo "<a href='?page=home&g=Left 4 Dead 2'>L4D2</a>"; echo "<a href='?page=home&g=Call Of Duty: Modern Warfare 4'>MW3</a>"; echo "</div>"; */ } ?> Im just trying to get the first one to work then I can apply that to the others. I have commented the others out and spaced them down for readability. Thank you for any help you can give me. Kind regards, L2c. Edited February 9, 2013 by Love2c0de Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2013 Share Posted February 9, 2013 String concatenation is with . not , Quote Link to comment Share on other sites More sharing options...
kicken Posted February 9, 2013 Share Posted February 9, 2013 Not highly sensitive but I wanted to rawurlencode it. rawurlencode isn't there for protecting sensitive data, it's there because some characters are invalid in a URL and therefore have to be encoded. For example a space character needs to be encoded as either + or %20. echo "<a href='?page=home&g=",rawurlencode("Battlefield 3"),"'>BF3</a>"; That code works fine, and outputs: <a href='?page=home&g=Battlefield%203'>BF3</a> If your expecting something else you'll have to clarify what it is you are expecting. @Jessica echo actually accepts multiple arguments so doing echo $a, $b, $c is essentially the same as echo $a.$b.$c; but saves having to perform the concatenation step. Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted February 9, 2013 Author Share Posted February 9, 2013 In the example on php.net it shows the function being used with commas when concatenating and not periods which I thought was strange as I'd never seen that. http://php.net/manual/en/function.rawurlencode.php Regards, L2c. Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted February 9, 2013 Author Share Posted February 9, 2013 Thanks kicken. It's not working for me though, when I hover over the link and even when I click it, it's showing as g=Battlefield 3 still. Regards, L2c Quote Link to comment Share on other sites More sharing options...
kicken Posted February 9, 2013 Share Posted February 9, 2013 Browsers will typically unencode url's when displaying them so that it's easier to read a url. You just need to view the source and you'll see it properly encoded. Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted February 9, 2013 Author Share Posted February 9, 2013 Ah I see. It's working in the source but not in the url bar where I want it to. How would I go about doing that? Regards, L2c. Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted February 18, 2013 Author Share Posted February 18, 2013 (edited) Do I have to hardcode the spaces for example Deus%20Ex when passing the value through the URL? My colons appear to encode in the URL bar when using urlencode() but the spaces don't. I've seen on websites where you see the url encoded in the url bar and not just the source. Is there some kind of directive I need to change in php.ini? I've tried urlencode too but doesn't seem to encode anything but colons. Sorry disregard that whole post^^ Regards, L2c. Edited February 18, 2013 by Love2c0de Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.