PHP trouble using #File_Get_Contents And cURL - php

So im basically trying to call an API that is supposed to ping a given IP address, but everything ive been trying hasn't been working, they used to work in the past because these are just snippets i gathered from an old project that used to work just fine, now they dont work, ive checked to see if it logged any PHP errors, but there was nothing in the logs.
Here are my sample codes:
cURL:
<?php
if (Isset($_POST['submit'])){
$host = $_POST['host'];
$url = "http://someapi.com/ping/?host=".$host;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
}
?>
<input type="text" name="host" placeholder="IP" />
<input type="submit" name="submit" value="Geo Locate" />
<br>
<center>
<?php echo $data; ?>
</center>
</form>
#File_Get_Contents
<form action="" method="POST">
<?php
If(Isset($_POST['submit'])){
$host = $_POST['host'];
$api = #File_Get_Contents("http://someapi.com/ping/?host=" .$host. "");
echo $api;
}
?>
<input type="text" name="host" placeholder="IP" />
<input type="submit" name="submit" value="Geo Locate" />
<br>
<center>
<?php echo $api; ?>
</center>
</form>
could it be something wrong with my hosting service maybe?

Related

Send SMS via API integration using php

The following code contain HTML and PHP code.I integrated SMS API with HTML , but it's not working.It doesn't display me any error message. I need you to help me in this regard.I want to send SMS through this API successfully.HTML part contain the structure of SMS sending fields and PHP actually contains API code.
<pre>
<!DOCTYPE html>
<html>
<head>
<title>
Sending SMS using PHP
</title>
</head>
<body>
<form method="post">
<br><br>
<label>Mobile Number:</label>
<input type="text" name="num">
<br><br>
<label>Country Code:</label>
<select name="code">
<option value="">Select Here</option>
<option value="92">Pakistan - +92</option>
<option value="91">India - +91</option>
<option value="1">USA - +1</option>
</select>
<br><br>
<label>Enter Message</label>
<input type="text" name="message">
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
if (isset($_POST["submit"])) {
// Authorisation details.
$username = "example#gmail.com";
$hash = "some_hash";
// Config variables. Consult http://api.txtlocal.com/docs for more info.
$test = "0";
// Data for text message. This is the text message data.
$sender = "API Test"; // This is who the message appears to be from.
$numbers = $_POST["code"] . $_POST["num"]; // A single number or a comma-seperated list of numbers
$message = $_POST["message"];
// 612 chars or less
// A single number or a comma-seperated list of numbers
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('http://api.txtlocal.com/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); // This is the result from the API
curl_close($ch);
if (!$result) {
?>
<script>
alert('Message Not Sent...!')
</script>
<?php}
else{
#print result
echo $result;
?>
<script>
alert('Message Sent Sucessfully...!')
</script>
<?php
}
}
?>
</pre>

How to pass a variable from an html form to a php script?

I have watched some tutorials on how to pass a variable from a form to a php file, and cannot get anything to happen when I click the submit button. I am making a page that searches the Clash of Clans API to display the clan searched.
I just need to have the form submit the clan tag to the php script.
Here is my code. The file is a php file and the form action is blank because the php is in the file.
<?php
header('Content-Type: text/html; charset=UTF-8');
if (isset($_POST['submit'])) {
$clantag = $_POST['var'];
}
$token = Token Goes Here;
$url = "https://api.clashofclans.com/v1/clans/" . urlencode($clantag);
$ch = curl_init($url);
$headr = array();
$headr[] = "Accept: application/json";
$headr[] = "Authorization: Bearer ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$data = json_decode($res, true);
curl_close($ch);
echo "<pre>";
var_dump($data);
echo "</pre>";
?>
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="button" name="submit" value="Submit">
</form>
You should replace the type of the button from "button" to "submit"
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="submit" name="submit" value="Submit">
</form>

getting username from form and search in github api

I'm trying to search a user using the Github api, but I'm not sure what I'm doing wrong here.
My html form:
<form action="" method="get">
<div class="form-group">
<label >Buscar Usuario</label>
<input class="form-control" type="text" name="username">
</div>
<button type="submit" name="submit" class="btn btn-default">Procurar</button>
</form>
My php code:
<?php
function buscaUser()
{
$user= $_GET['username'];
$ch = curl_init();
$url ="https://api.github.com/search/users?q=".$user;
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result));
}
?>
YOu didn't call the buscaUser() anywhere
Do it this way:
<?php
function buscaUser($user) {
$ch = curl_init();
$url ="https://api.github.com/search/users?q=".$user;
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result));
}
?>
Then you can call the function and pass the submitted value:
<?php
echo buscaUser($_GET['username']);
?>
Should do!

Passing $_POST values with cURL link extern

Code for /www/formulair.php :
<html>
<head>
</head>
<body>
<form action="recive.php" method="POST">
<input type="text" name="name"/>
<input type="submit" value="Send me your name!">
</form>
</body>
</html>
Code for /www/recive.php :
<?php
include ("config.php");
?>
Code for /www/config.php :
<?php
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'http://localhost/test.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $_POST['name']);
curl_exec($ch);
curl_close($ch);
?>
Code for test.php :
<?php
if(isset($_POST['name'])) {
$fp = fopen('data.txt', 'a+');
fwrite($fp,$_POST['name']);
fclose($fp);
}
?>
Error :
Erreur : Notice: Undefined variable
What I should write in test.php to get the $_POST['name']?

curl and php html not logging in correcty i know curl functions work

I know my curl script works correctly. I can hardcode the email and pass in curl and it works fine, but now I am trying to create a php script to input it and it doesn't work. I will post links and code below.
I am using the input email#ccc.com:passss.
http://cyber-hosted.com/CH/index.html
<html>
<head>
</head>
<body>
<form action="n.php" method="post">
<input type="text" name="mail />
<input type="password" name="pass" />
</form>
</body>
http://cyber-hosted.com/CH/n.php
<?php
$usermail = $_POST['Mail'];
$pass = $_POST['pass'];
$url = "https://secure.tesco.com/register/default.aspx?vstore=0";
//
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $url);
curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, "form=fSignin&from=https%3A%2F%2Fsecure.tesco.com%2Fclubcard%2Fmyaccount%2Fhome.aspx&formData=bmV3UmVnPWZhbHNlJg%3D%3D&loginID=$usermail&password=$pass&seamlesswebtag=&confirm-signin.x=47&confirm-signin.y=18");
curl_setopt($h, CURLOPT_HEADER, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($h, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($h, CURLOPT_FOLLOWLOCATION, true);
//
$result = curl_exec($h);
echo $result;
?>
You typed mail with uppercase:
$usermail = $_POST['Mail'];
// here -----^
Change it to:
$usermail = $_POST['mail'];
Ah and I almost forgot the double quotes here:
<input type="text" name="mail />
<!-- here --------^ --->
It should be <input type="text" name="mail" />
Try giving the fields a value attribute
<input type="text" name="mail" value=""/>
<input type="password" name="pass" value=""/>
Also you are missing the submit button from your supplied code
<input type="submit" name="submit" value="Submit"/>
And finally you should URL encode the usermail and password parameters in the cURL request.

Categories