$newRequesterPass=mysql_real_escape_string($_POST['userPass']);
$static_salt = 'M0AaE|}{<}|{&*#^AhEQ';
$dynamic_salt = mt_rand();
$newRequesterPass = sha1($dynamic_salt . $password . $static_salt);
$newRequesterDynamSalt = $_POST($dynamic_salt);
I get error: Function name must be a string
How do I get this code to $_POST correctly:
$newRequesterDynamSalt = $_POST($dynamic_salt);
$_POST is an array, you access arrays with [], so:
$_POST[$dynamic_salt]
But, it seems you confused server side and client side into one script.
The fix I gave is just for the specific error, not for the algorithm u try to implement.
Related
I am writing some code to create fields automatically, which will save me a load of time. I have got most of my code working, but I have came across one error with the code, which is preventing me from achieving my final goal.
The code is as follows:
while ($i <= $numFields) {
$type = "\$field{$i}_Data['type']";
$name = "\$field{$i}_Data['name']";
$placeholder = "\$field{$i}_Data['placeholder']";
$value = "\$field{$i}_Data['value']";
echo '<input type="'.$type.'" name="'.$name.'" placeholder="'.$placeholder.'" value="'.$value.'">';
$i++;
}
The $numFields variable is defined at the top of my script, and I have worked out that it is something to do with how I am setting the variables $type, $name etc.
The end result is to create inputs depending on properties set in variables at the top of the script, The only issue I am having is with the settings of the variables, as said above.
If any extra code/information is needed, feel free to ask.
Thank you.
NOTE - There is no physical PHP error, it's purely an error with this:
"\$field{$i}_Data['value']";
There are a few ways we could write this one out, but they are all extensions of variable expansion and/or variable-variables.
Basically, we just need to put the variable name in a string and then use that string as the variable (much like you're currently doing with $i inside the string):
$type = ${"field{$i}_Data"}['type'];
$name = ${"field{$i}_Data"}['name'];
// ...
However, if you don't mind an extra variable, this can be written more cleanly by saving it like so:
$data = ${"field{$i}_Data"};
$type = $data['type'];
$name = $data['name'];
// ...
I have been attempting to use steam api to display a persons name. When I insert there steamid in directly it works however, when I try to use a variable it doesn't work. The thing that confuses me is that I have this exact same code for my queue that works however this does not work. I have looked around and I believe I am doing this right but for some reason it is not working. Any help here would be great. Thanks.
<?
$name = 76xxxxxxxxxxx;
$response = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/? key=xxx&steamids={$name}&format=json";
$middle = (file_get_contents($response));
$json = json_decode($middle, true);
$b = $json['response']['players'][0]['personaname'];
print_r($b);
?>
Your $name variable needs to be wrapped in quotes.
$name = "76xxxxxxxxxxx";
This will properly create your response variable
I am trying to save form data to a file, this is what I have so far:
if(isset($_POST['connect'])) {
$host = "$dbuser=" . $_POST["host"];
$root = $_POST["root"];
$pass = $_POST["pass"];
}
I'm trying to write the form data to a file with the variable $dbhost="Formdata";
and I get this error:
Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\dev\admin2.0\install\index.php on line 55`
$host = '$dbhost="' . $_POST["host"] . '"';
echo $host;
Try this. You don't need to echo unless you are attempting to print to the page.
I'm not really sure what you trying to accomplish, but if you want to write some data to a file (for example), you could try something like this:
<?php
if (isset($_POST['connect'])) {
file_put_contents("file.txt", "$dbuser={$_POST["host"]}");
}
Also keep in mind that notation:
"$dbuser="
will expand variable in place (1), if a variable $dbuser exists, because you are using double quotes.
With single quotes you will need string concatenation operator . like this:
<?php
if (isset($_POST['connect'])) {
file_put_contents("file.txt", '$dbuser=' . $_POST["host"]);
}
But, if this all about plain debug, maybe print_r($_POST); will be sufficient?
Hope this helps!
PHP Reference: Strings (please read section "Variable parsing").
I'm able to access my $_POST array values, but can't seem to get the correct syntax for returning only the "data" part of the array. If I run var_dump($_POST["attributes"]);, I receive the following in the response callback(which is exactly what I expected):
string '{
"device_maker" = unknown;
"device_model" = Simulator;
"first_visit" = "1387478168.109";
"last_visit" = "1388358490.638";
latitude = "37.78583526611328";
locale = en;
longitude = "-122.4064178466797";
"opted_in" = 1;
"opted_out" = 0;
"os_platform" = "iPhone OS";
"os_version" = "7.0.3";
"this_visit" = "1387478168.109";
"user_id" = 1;
}' (length=389)
If I try to access any one of the attributes separately, like var_dump($_POST["attributes"]["device_model"]);, all I get in return is string '{' (length=1). I'm apparently missing a key idea on parsing this data. How do I parse "attributes" so I can place each one of the listed values into an insert statement(I've got that part ready to go once I get the data)? Granted, my php is very rusty. So I may be overlooking something obvious.
It's frustrating to see the data I need and not know how to correctly access it. So, any help is appreciated. Please ask if you need clarification.
Apparently the string being retrieved in your POST is not valid JSON. If you can't replace the values being sent to the server, you can always do a (dirty) workaround:
First, replace some characters to make it a valid json:
$jsonStr = str_replace('=', ':', $_POST["attributes"]);
$jsonStr = str_replace(';', ',', $jsonStr);
$jsonStr = str_replace(',}', '}', $jsonStr);
Then we can try to parse it using the json_decode function:
$jsonArray = json_decode($jsonStr);
Now you can access it as a regular associative array, e.g.:
echo $jsonArray['device_model'];
What you show here looks like JSON encoded data - it's a single string so there is no $_POST["attributes"]["device_model"].
You can access the data embedded in the attributes variable by converting it from JSON:
$a_string='{
"device_maker" = unknown;
"device_model" = Simulator;
"first_visit" = "1387478168.109";
"last_visit" = "1388358490.638";
latitude = "37.78583526611328";
locale = en;
longitude = "-122.4064178466797";
"opted_in" = 1;
"opted_out" = 0;
"os_platform" = "iPhone OS";
"os_version" = "7.0.3";
"this_visit" = "1387478168.109";
"user_id" = 1;
}';
// or $astring=$_POST['attributes']
$data=json_decode($a_string);
print $data['device_model'];
....but you need to verify the origin of the data - if it' not JSON, then this will break at some point.
I have this code for scraping team names from a table
$url = 'http://fantasy.premierleague.com/my-leagues/303/standings/';
$html = #file_get_html($url);
//Cut out the table
$FullTable = $html->find('table[class=ismStandingsTable]',0);
//get the text from the 3rd cell in the row
$teamname = $FullTable->find('td',2)->innertext;
echo $teamname;
This much works.. and gives this output....
Why Always Me?
But when I add these lines..
$teamdetails = $teamname->find('a')->href;
echo $teamdetails;
I get completely blank output.
Any idea why? I am trying to get the /entry/110291/event-history/33/ as one variable, and the Why Always Me? as another.
Instead do this:
$tdhtml = DOMDocument::loadHTML($teamdetails);
$link = $tdhtml->getElementsByTagName('a');
$url = $link->item(0)->attributes->getNamedItem('href')->nodeValue;
$teamdetails = $teamname->find('a')->href;
^^^^^^^^^---- never defined in your code
I also fail to see how your "works" code could possibly work. You don't define $teamname in there either, so all you'd never get is the output of a null/undefined variable, which is...no output all.
Marc B is right, I get that you don't have to initialize a variable, but he is saying you are trying to access a property of said variable:
$teamdetails = $teamname->find('a')->href;
^^^^^^^^^---- never defined in your code
This is essentially:
$teamname = null;
$teamname->find('a')->href;
The problem in your example is that $teamname is a string and you're treating it like a simple_html_dom_node