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']);
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.
Started learning php this week and had many doubts, but this is one of them which i couldn't find solution(Maybe i didn't know the right keyword to search for).
Is it possible to read variables in URL as a function inside a php file,
for example :
http://mywebsite.com/demo_app/phone_api/login/harsha/harshapass
Here demo_app is the folder, phone_api is the php file, and i want to invoke the function login, where harsha and harshapass is the paramaters to that function.
You'll need 2 things for this.
The first is mod_rewrite, this is an apache module. With this module you can rewrite the URL like you want, so that /demo_app/phone_api/ will redirect to your php file.
I advice that you read a tutorial somewhere about this, for example here.
Second thing is that you need to parse the URL.
With $_SERVER['REQUEST_URI'] you get the URL. With explode and/or preg_match you can parse this string into the parts you want (function, parameters, whatever).
If you have a more specific question about this, you can ask this here (in a new topic).
Good luck!
Did you consider sending the values as $_GET variables and retrieving them in the page like so:
http://mywebsite.com/demo_app/phone_api?login=login&harsha=harsha&harshapass=harshapass
so you can get the values in the phone_api.php page like:
$login = $_GET['login'];
$harsha = $_GET['harsha'];
$harshapass = $_GET['harshapass'];
$login($harsha, $harshapass){
//your function code.
}
Maybe it'll be easier this way.
My PHP knowledge is very basic. I've built a child theme and the functions.php is all from bits and pieces found on the web. All works great at the moment, and I've reused it on another website. But in several places I had to manually input blog name, email address, etc. What I want is to make it reusable without any further interventions over it. I've covered all problems, but one: changing the default wordpress#example.com email.
// Changing default wordpress email settings
add_filter('wp_mail_from', 'new_mail_from');
function new_mail_from($old) {
return 'notifications#example.com';
}
This works, although to make it reusable without intervention I need to somehow retrieve the site's URL without http:// and www. I've made a test page and used:
$my_site = str_replace('www.','', $_SERVER['SERVER_NAME']);
echo 'notifications#'.$my_site;
It worked on the test.php file, but not in Wordpress' functions.php. The mail is sent and received, but the sender is 'notifications#' with nothing after #. I've used it as
return 'notifications#'.#my_site;
I've tried another approach:
$custom_email = 'notifications#'.str_replace('www.','', $_SERVER['SERVER_NAME']);
function new_mail_from($old) {
return $custom_email;
}
This one doesn't show any sender at all, it's from "unknown sender".
I've tried to work with site_url() instead of $_SERVER, but I haven't managed to make it work either. I didn't tried using home_url() because maybe in some cases home_url() will use a custom page (like a landing page).
Is there a way to solve this problem I have?
Thank you.
Ok, with a bit of help from a friend, I've found something that works:
function new_mail_from($old) {
$custom_email = 'notifications#'.str_replace('www.','', $_SERVER['SERVER_NAME']);
return $custom_email;
}
So basically all I need is to put $custom_email inside the function.
#MadBreaks Now... I know your advice was to avoid str_replace, but I didn't manage to understand parse_url and how to use it. Why isn't str_replace a good choice?
#Victory $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] did for me the same thing. Could you please tell me what's the difference? Or pros and cons in using each of them in this situation? Thank you.
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));
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