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'].
Related
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
I am trying to pass a variable from javascript to PHP using a an AJAX request [$.get] but am getting nothing through the $_GET method. I am wondering why the variable email won't pass even though there is a value within it.
fetch.js
email = resp.emails[i].value;
$url = 'login.php'; //this file is on the same directory as fetch.js
//AJAX
$.get($url, {name: email});
login.php
$googleid = $_GET['name'];
echo $googleid; //nothing showing
If you need any more details please don't hesitate to ask.
EDIT I know I am going to get flamed for this but this was a typo. In my script I didn't make this mistake.
$googleid = $_GET['email'];
should be
$googleid = $_GET['name'];
Because your GET variable was name and email was value that assign to name (eg, name = test#example.com). So you should access it by $_GET['name']
It should be
$_GET['name'];
What is the line email = resp.emails[i].value;? Has that a value?
Since in JS you send GET variable named name then in PHP you have to access it by $_GET['name'], not $_GET['email']:
$googleid = $_GET['name'];
You have to use $_POST for a parameter request.
For get the parameter would be visible in the url what you probably dont want like login.php?email=my_email#domain.tld
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
Is it possible once I have retrieved a userid from a MySql database, for example, $userID, to then use that as a parameter in a HTML link, for example;
<href="http://www.site.com/?110938">
Thanks.
In PHP, anything you echo is sent to the browser. So you can simply echo that variable.
echo $userID;
Or to put it in the link:
<href="http://www.site.com/?<?php echo $userID ?>">
Of course that means you're trusting that $userID will contain valid data (and not some malformed HTML attempting to break your site and ruin your user's lives).
If it should always be a number, you can keep out potential bad data by forcing it to be an integer:
<href="http://www.site.com/?<?php echo (int) $userID ?>">
I believe what you are looking to do is use the GET method of retrieving data.
The GET method (as opposed to post) pulls all of the parameters out of the URL. For example, lets take a google maps search url:
http://maps.google.com/maps?q=Empire+State+Building,+NY&hl=en
Let us break down this URL:
http://maps.google.com/ - this is the location of the script
maps? - Maps is the name of the file that contains the script (if
they are using PHP); notice, there is a ? in the URL, indicating
that the GET method is being used. All information after the ?
pertains to the GET data.
q=Empire+State+Building,+NY& - this portion is the first GET
variable. They have decided to use the letter q as the name of
their GET variable, and the value is Empire+State+Building,+NY. The
& indicates that another variable will be specified.
hl=en - this is the second variable in their query.
If they were to use PHP to read these parameters, they would use the following code:
$var1 = $_GET['q']; //Has value Empire+State+Building,+NY as string
$vars = $_GET['hl']; //Has value en as string
If you wanted to have your user's ID be in the URL, and use that to interact with the database, the easiest way would be to use GET, such that your URL would look like this:
www.example.com/example.php?id=45828
Then in your script, you would use the following code to access that data and query the database with it:
$userid = $_GET['id'];
$query = "SELECT * FROM users WHERE userid=$userid;";
$query = mysql_escape_string( $query );
mysql_query( $query );
just pass the variable like <href="http://www.site.com/?var_name=<?php echo $userID;?>">
Im having a really simple issue but iv looked around and cant debug it for some reason, can someone point me in the right direction??
I have a php script which dynamically generates a link
<?php
$id = 1;
echo "<a href='http://www.example.com/page.php?id='$id'>click link</a>"
?>
On example.php I have...
$userId = $_POST['id'];
then I insert $userId query...
?>
For some reason the Post vairable is not being cause by the example.php script I can see it in the URL at the top of the page but they wont make sweet passionate php love. Any thoughts? I will mention I am doing this from within an IFRAME however I tried it simply and got the same result :(
I think you mean, on page.php you have...
If that is the case, you are sending the id parameter in a GET, not a POST. To access it in your other page you need to use:
$userId = $_GET['id'];
your variable is in $userId = $_GET['id'];.
another problem is a mess with ' symbols: should be
echo "<a href='http://www.example.com/page.php?id=$id'>click link</a>"
Sorry, but you ar sending data via GET NOT POST
access it via $_GET['id'];