I created a field in WP customizer and I'm trying to pull whatever value I enter from another file. Beforehand, this worked:
private $endpoint = "http://www.website.com/webservice/GetSearchResults.htm?ws-id=12345";
and now I am trying to do something like this (I'm new at this):
$website_api_key = echo get_theme_mod('website-api-key');
private $endpoint = "http://www.website.com/webservice/GetSearchResults.htm?ws-id=" . $website_api_key;
How do I get this to work correctly?
You are setting the variable in the url correctly. Now you just have to grab it. When you visit a webpage, you are using a GET request, so these "url variables" can be grabbed through the $_GET array.
All you have to do to accomplish this is do something like this:
$myvar = $_GET['ws-id'];
Here is a good article to give you more information on this
Related
How do you set a $GET variable?
Hi i have done this before, but my method is a bit hit and miss so i was wondering what is the correct way to do this.
My url is:
Franchise-Details.php?Franchise=Enfield/status=Driver
And i want to set the Franchise name and staff status as a variable as i will be using them continuously throughout my webpage.
This is what i have done:
$admin_status = mysqli_real_escape_string($dbc,$_GET['status']);
$fr_Area = mysqli_real_escape_string($dbc, $_GET['Franchise']);
But it does not work. No error messages, just shows nothing if i try to apply it, for example echo $fr_area;. If i change the get to session it works. But i want to use get.
I have also tried:
if (isset($_GET['status'])){
$admin_status = mysqli_real_escape_string($dbc,$_GET['status']);
}
if (isset($_GET['Franchise'])){
$admin_status = mysqli_real_escape_string($dbc,$_GET['Franchise']);
}
How can i improve this
Im trying to set a working variable i can use later on in my code, ive got an id in the url that references an attribute in an external data feed. You can see a copy of the xml feed HERE
the id comes in the url like this - /page.php?id=52115351
At the moment im setting my working variable as bellow, buts its just being set to the first instance of 'market' rather than being set against the instance thats got the same id as the one in the url.
$wh_odds = $wh_xml->response->williamhill->class->type->market->participant;
$wh_odds_attrib = $wh_odds->attributes();
$wh_odds_attrib['name'];//name
How would i implement $_GET['id'] with this block so that it would be making the working variable $wh_odds_attrib['name'] from the participant of the correct instance of 'market' in the xml feed ?
If you're using simpleXML you could try something like this:
$simpleXml = simplexml_load_file('test.xml');
$marketNode = $simpleXml->xpath("/oxip/response/williamhill/class/type/market[#id='{$_GET['id']}']");
$attributes = $marketNode[0]->participant->attributes();
echo $attributes['name'];
I am not entirely sure what you are attempting to do but you can just assign the $_GET['id'] to whatever you want, ie $id = $_GET['id'] allowing you to use it in string manipulation (via sprintf or whatever).
A little more information about what you are trying to do, would help
I know that CakePHP params easily extracts values from an URL like this one:
http://www.example.com/tester/retrieve_test/good/1/accepted/active
I need to extract values from an URL like this:
http://www.example.com/tester/retrieve_test?status=200&id=1yOhjvRQBgY
I only need the value from this id:
id=1yOhjvRQBgY
I know that in normal PHP $_GET will retrieve this easally, bhut I cant get it to insert the value into my DB, i used this code:
$html->input('Listing/vt_tour', array('value'=>$_GET["id"], 'type'=>'hidden'))
Any ideas guys?
Use this way
echo $this->params['url']['id'];
it's here on cakephp manual http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Controllers.html#the-parameters-attribute-params
You didn't specify the cake version you are using. please always do so. not mentioning it will get you lots of false answers because lots of things change during versions.
if you are using the latest 2.3.0 for example you can use the newly added query method:
$id = $this->request->query('id'); // clean access using getter method
in your controller.
http://book.cakephp.org/2.0/en/controllers/request-response.html#CakeRequest::query
but the old ways also work:
$id = $this->request->params->url['id']; // property access
$id = $this->request->params[url]['id']; // array access
you cannot use named since
$id = $this->request->params['named']['id'] // WRONG
would require your url to be www.example.com/tester/retrieve_test/good/id:012345.
so the answer of havelock is incorrect
then pass your id on to the form defaults - or in your case directly to the save statement after the form submitted (no need to use a hidden field here).
$this->request->data['Listing']['vt_tour'] = $id;
//save
if you really need/want to pass it on to the form, use the else block of $this->request->is(post):
if ($this->request->is(post)) {
//validate and save here
} else {
$this->request->data['Listing']['vt_tour'] = $id;
}
Alternatively you could also use the so called named parameters
$id = $this->params['named']['id'];
I am new to PHP.
I need a help regarding the methods of extracting DB name and table name from the given URL name.
For example, let's say, I have an URL like the one below:
/test.php?db=...&table=.../
How to extract the DB name and table name from this URL using PHP and use the result for other query purposes.
If you mean how to parse an existing URL for it's parameters:
parse_url() and parse_str() will help you strip the components of the url. You will primarily be looking at the following
$elements = parse_url($url);
$kvps = $elements->query;
$db = parse_str($kvps['db']);
$table = parse_str($kvps['table']);
But, if you mean how to GET variables from the current page before render:
<?php
$dbname = $_GET['db'];
$tablename = $_GET['table'];
?>
And yea, there are major security risks involved in opening up 'direct' access to your database this way. Best to obfuscate / encapsulate / wrap your functions in tasks like index.php&addUser=tim instead of index.php&insert=tim&db=boofar&table=users&dbuser=root&dbpassword=secure.
If you're just learning, what you're doing is fine, as long as you realize why it's wrong. If you're coding for production, you really need an alternate solution.
There are two ways to pass variables or data to another page.
GET (via the URL)
and
POST (usually a form submission)
You can alway get via
$_GET
http://php.net/manual/en/reserved.variables.get.php
or
$_POST
http://nl.php.net/manual/en/reserved.variables.post.php
I begin with vars.php:
<?php
include('goo.php');
$googl = new goo_gl('http://myurl.info?=sdfdsfs'.uniqid());
$url1 = $googl->result();
$link=$url1;
$message=$msgarray[rand(0,count($msgarray)-1)];
$picture="http://img6.imageshack.us/img6/4540/7.jpg";
?>
I want to feel http://mmyurl.info?=sdfdsfs'.uniqid() into the goo.gl api to spit out a shortened url
and then use this information in vars.php which is in the header''
this info is then used on another page where $link is called, but i can never get it to work properly
You should give a query string variable a name first:
$googl = new goo_gl('http://myurl.info?myvar=sdfdsfs'.uniqid());
Now you can access value of myvar via $_GET['myvar'].