I'm trying to work on my new wordpress plugin, and I encountered an issue.
I'm setting a variable to contain something like this:
esc_html('likeit'.wp_generate_password(4))
And then - I want to call another function via GET, but it's sometimes breaking.
For example if I have: likeitA9&n, it will break at &.
Can you please tell me what's the best (and most secured) but simple way to handle this in my plugin?
Examples would be appreciated!
Thanks a lot!
P.S. - I did try to look at previous posts, but nothing that actually solved this :(
urlencode('likeit'.wp_generate_password(4));
or
rawurlencode('likeit'.wp_generate_password(4));
Related
I'm using the following library to give a update feature to my WordPress and this works fine with the code of documentation.
https://github.com/YahnisElsts/plugin-update-checker/blob/master/README.md
require 'plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/user-name/repo-name/',
__FILE__,
'unique-plugin-or-theme-slug'
);
But I'm really wondering where this '$myUpdateChecker' variable came from and how this is working, because I can't find any part of the library's files using this variable.
It seems to be totally independent for me.
Thank you in advance.
You're creating the variable right there. You can even name it something else if you want (eg. $update_checker), that shouldn't cause any issues in this particular case as the variable isn't being used anywhere else (according to your own words.)
For more details: PHP variables.
Calling $_GET['ip'] worked up until a recent wordpress update and now it's broken.
I don't know how Wordpress expects me to get the variable but the code I've been messing with and put together doesn't seem to work at all.
I'm clearly doing something wrong but I can't seem to wrap my head around making this work.
The code I'm trying to work with is here: https://pastebin.com/4iipisjU
UPDATE: The code works, the WPSupercache configuration file for nginx is what seems to have broken it.
You should be able to use get_query_var
<?php
$value = get_query_var( "paramA", "default value" );
?>
Also, $_GET['ip'] will refer to the query parameter IP that was passed as part of the request.
Is this actually what you are looking for? Or are you trying to see the IP of the client making the request? If the latter, this is incorrect.
Try change $get_ip_addr to:
$get_ip_addr = get_query_var('ip', $_GET['ip']);
I have continued my voyage into creating a extremely simple template engine.
Because I wanted to add logic to my template I eventually got back to the point that I allowed PHP tags into my code which I enabled by evalling the code.
Maybe not the best solution but when looking at the WordPress templates I noticed that the idea itself may not be that bad.
But now there still is one small problem left.
And that is that I want to translate the generated code.
But it has been evalled already. Hence parsed.
I thought of solving this problem by using ob_get_contents().
But this brought one more question and in case of errors it shows a white screen. (memory usage etc.)
Plus it still did not take away the problem of eval that it parsed the contents when evalled.
In short the class logic is:
Loading template files
Adding the contents
Compiling the template
Eval the code (but unfortunately also displaying the code)
Translate the code so I can translate the code parsed by a PHP script
I would love something like:
$code = eval('?>'.$tpl.'<?php');
$code = translate($code);
WriteCache($code);
SetDocumentHeader();
echo $code;
Would anyone know how to achieve this?
Thanks in advance!
$code = eval($tpl);
Check this out.
I'm using the following in my php code:
$file="query.txt";
$f=fopen($file,'a');
fwrite($f,"Query String:".$_SERVER['QUERY_STRING']."\n");
fclose($f);
It never returns anything. I'm simply trying to record the queried url when someone visits (i.e. http://example.com/index.php?q=string. Other $_SERVER fields seem to work just fine, it only seems to be the query string that doesn't work. Maybe there's something I need to setup in my .htaccess?
I'm hoping someone has an answer to how to get this to information to show.
This solved the problem:
$_SERVER['REDIRECT_QUERY_STRING']
solution from https://stackoverflow.com/a/11618256/1125006
i need to do a "file_get_contents" on a URL and there has to be data posted to the url before the contents are retrieved. is this possible? maybe something like
$contents = file_get_contents($_POST"http://www.example.com/");
so that i can then work with the $contents variable?
You cannot*** POST data using file_get_contents, you must use something like cURL
* I mark this because it is actually possible taking advantage of the third parameter which uses http context(see example one). However it really isn't worth your trouble if you have something like cURL.
Ah, I have tried to do this. Simply put you can't unless you install new extra software on your sever and go through A LOT of hassel and server load.
Best bet is to use GET if at all possible!
:)