I can not get parameter $_GET with it value contain character: '#'.
I have the follow code:
<iframe src="http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=<span style="color: #ff0000;">Empty content.</span>">
and when I change or eliminate the character: '#' all work fine. for example:
<iframe src="http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=<span style="color: ff0000;">Empty content.</span>">
How I can get the parameter (text_content) value complete?
Note: I'm testing in PHP get this parameter/value $_GET['text_content'].
Thanks
You'll want to urlencode() any strings you pass in through GET requests and urldecode() them once you grab them from $_GET.
http://www.php.net/manual/en/function.urlencode.php
The quotes in your string are also causing issues. Try this for your top iframe:
<iframe src="http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=%3Cspan%20style%3D%22color%3A%20%23ff0000%3B%22%3EEmpty%20content.%3C%2Fspan%3E">
You need to use url_encode function, because whatever comes after # won't be considered as part of URL(browsers don't send that part to server).
You should really use urlencode before sending it to your php script for handling, and then use urldecode to output it normally.
Maybe try:
<iframe src="<?php urlencode('http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=<span style="color: #ff0000;">Empty content.</span>'); ?>">
to fetch it:
urldecode($_GET['text_content']);
Related
How do I properly escape a href properly in my html anchor tag link and still be able to retrieve the data I send through the url for use in the next page.
My code looks like this:
<a href='course.php?id=".encrypt($courseid)."'>".$result->row('title')."</a>
You need to URL-encode the value to preserve URL-syntax, and since you're putting that URL into HTML you should HTML-encode it too:
printf('%s',
htmlspecialchars(rawurlencode($courseid)),
htmlspecialchars($result->row('title')));
See http://php.net/htmlspecialchars, http://php.net/rawurlencode, http://php.net/printf.
On the other side the value will be available in $_GET['id'] (you do not need to decode it in any way there).
i am getting a querystring parameter like companyname=Larson&tubro. Its a single string. But my script is just breaking it after '&'. What is the solution to take this as a single string in PHP. I tried like the below:
<A onclick="window.open('comparitive_files/price_add.php?supplier_name= + urlencode({$supplier_name})&tender_id={$tender_id}','mywindow','width=1200,height=800,scrollbars=yes,resizable=yes')"
href="#">
You are trying to use php functions outside of php. Try something like this.
echo '<A onclick="window.open(\'comparitive_files/price_add.php?supplier_name='.urlencode($supplier_name).'&tender_id='.$tender_id.',\'mywindow\',\'width=1200,height=800,scrollbars=yes,resizable=yes\')" href="#">';
You can try urlencode
urlencode($var);
Use urlencode for encoding
urlencode($companyname);
and urldecode for decoding
urldecode($companyname)
& is used to seperate variables in a querystring. Instead use &.
To prevent any other illegal characters from getting in your querystring, use urlencode()
Let's say I have the following URL: pic.php?t=1&p=23
When I try phpThumb.php?src=/pic.php?t=1&p=23, I get Forbidden parameter: p.
Anyone knows if there's a way around it?
You need to URLEncode that ampersand if you are trying to pass p=23 to pic.php. Try replacing the & with %26.
What you are effectively doing there is passing p=23 as a parameter to phpThumb.php, which obviously it doesn't like...
What you probably want to do is 'phpThumb.php?src='.urlencode('/pic.php?t=1&p=23');
Read this and this.
urlencode() the URL before passing it to phpThumb.
You can URL encode the ampersand to make it part of the content of the parameter in the querystring. This way, the whole /pic.php?t=1&p=23 gets passed as the src.
phpThumb.php?src=/pic.php?t=1%26p=23
The %26 is the encoded version of the &.
Use urlencode().
Given this PHP code:
<a onclick="javascript:window.location.href='<?php echo $url;?>'"
What if there is a ' in $url?
I tried using json_encode($url) but it won't be able to handle this.
json_encode will work. You just have to use it the right way:
<a onclick="javascript:window.location.href=<?php echo htmlspecialchars(json_encode($url)); ?>">
This will work since json_encode already returns an JavaScript expression with quotes. And htmlspecialchars is needed to escape possible HTML meta characters.
I am using file_get_contents to grab a page, but i need to replace some data in the contents of the page before echoing it.
I have this so far (this script runs on domain2.com)
<?php
$page = file_get_contents('http://domain.com/page.html');
str_replace('href="/','href="http://domain.com','$page');
echo $page;
?>
The problem is, that when the page displays, some links on the domain.com page read:
<a href=/about.html>
Which when i call in my script, are prepending it with the incorrect domain. I tried using str_replace, to look for
href="/
and replace it with
href="http://www.domain.com/
But its not working. Any clues?
fixed it
$pagefixed = str_replace("href=\"/","href=\"http://www.domain.com/","$page");
Thanks all
You'll either need to use a regular expression (preg_replace) or 2 str_replaces since quotes vary.