Hi i'm facing error with the following code below
if(isset($_POST['get4']))
{
$pid = $_POST['get4'];
Currently want to implement is that i want to retrieve the get4 object & post the data to another url im.php
i tried this code
if(isset($_POST['get4']))
{
$pid = $_POST['get4'];
$_POST;$url=http://xyz . com/im.php
}
but not working .any answers?
If you are looking to send that variable to another page using GET , you can simply do like this..
if(isset($_POST['get4']))
{
$pid = $_POST['get4'];
}
header("location:yourpage.php?pid=$pid");
yourpage.php
if(isset($_GET['pid']))
{
echo $new_pid = $_GET['pid'];
}
(or)
If you are looking to send that variable using POST , Make use of cURL
EDIT :
if(isset($_POST['get4']))
{
$pid = $_POST['get4'];
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "yourpage.php");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,"pid=$pid"); //P5435
$response = curl_exec($curl);
echo $response;
Related
I'm doing a project and one of the requests is to automatically submit a form to a random site, which is specified from time to time
This is my cURL code :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dati_post);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Code to get POST parameters :
foreach ($html->find('form[method=post],form[method=POST]') as $forms_post) {
$n_formPOST++;
$formPOST_action = $forms_post->action;
foreach ($forms_post->find('input') as $input) {
if ($input->type == 'text') {
$dati_testo[$input->name] = "text";
} else if ($input->type == 'email' || $input->name == 'email') {
$dati_random[$input->name] = "emailrandom#gmail.com";
} else if ($input->type == 'hidden') {
$dati_random[$input->name] = $input->value;
} else {
$dati_random[$input->name] = "random";
}
}
foreach ($forms_post->find('textarea') as $textarea) {
if ($textarea->disabled != true) {
$dati_testo[$textarea->name] = "text";
}
}
foreach ($forms_post->find('button') as $bottone) {
if ($bottone->type == 'submit') {
$dati_random[$bottone->name] = "random";
}
}
The problem is that in some sites POST is done correctly and I receive the right answer, which corresponds to the answer I would receive by doing it manually.
On other sites, it seems that the form is not submitted.
I have repeatedly checked the URL that I insert in the cURL and also the data that I pass and if I use them manually it works.
I even tried using online tools that perform POST / GET passing the same URL and the same data that I get in my project and it works.
The url_post is made from url host+form action.
I don't understand if there is something wrong in my curl code, considering I'm pretty sure the data I'm passing to the curl are corrects to complete the POST.
Data :
Site URL : http://www.comune.ricigliano.sa.it/
Form Action : index.php?action=index&p=228
Url_post : http://www.comune.ricigliano.sa.it/index.php?action=index&p=228
POST data :
'qs' => 'something to research'
'Submit2' => 'Cerca'
You need to use the curl_exec() function in order to execute the cURL. It takes the $ch param, like such:
// Execute cURL
curl_exec($ch);
// Close cURL
curl_close($ch);
More info here
Having some trouble to grabbing redirect link with file_get_content I used these codes: the $link has a couple urls.
foreach ($link as $site) {
if (strpos($site, 'https://www.mecsumai.com/') === 0) {
$dom = getSiteContent($site);
$div = $dom->getElementsByTagName('iframe');
if ($div->length > 0) {
$iframeLink[] = $div[0]->getAttribute('src');
}
}
}
I grabbed here iframe urls which is like this:
https://www.mecsumai.com/bkn-summary?bid=16078001&bg1=999999&bg2=dddddd&wdt=100%&aln=center
But when try to enter this with file_get_content. I can't get the content of page. Because it will redirecting to this, when you try to enter:
https://www.mecsumai.com/bkn-summary/?bid=16078001&bg1=999999&bg2=dddddd&wdt=100%25&aln=center&newid=06078001
Last newid=line... is redirecting part. So I try this.
foreach($iframeLink as $results){
$opts = array('https' =>
array(
'follow_location' => 1,
)
);
$context = stream_context_create($opts);
$lastUrl[] = file_get_contents($results, false, $context);
}
print_r($lastUrl);
I'm getting no error, also getting the page content but not the whole of this page. The table is not coming?
Any idea to solve this?
I am not sure if file_get_contents allow such option, however you can use curl which does.
Here is an example.
function curl_get_contents($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
I have a while loop in which I set a redirection to url having some variables. The code is as follows :
while ($row = mysqli_fetch_array($sqlresult))
{
$message = "Shri/Smt/Ms. '".$row['1']."' , Your event '".$row['2']."' , '".$row['4']."' For CROA Sports 2018 is on '". $row['7']."' at ".$row['8'].":".$row['9']."";
header("Location: http://10.31.*.*/smsrcroa.asp?B1=RPM&F_MB_TO=".$row['10']."&F_SMS_T=".$message."");
}
When this while loop run, it sends SMS to only first record and redirects to specified location. The while loop could not be continued. I wish to continue the while loop.
Instead of redirecting use cURL which will call your URL without redirection. Here is function which can do that:
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Than replace your header(... with curl_get_contents(...
If you call this function in your code it will look like this:
while ($row = mysqli_fetch_array($sqlresult))
{
$message = "Shri/Smt/Ms. '".$row['1']."' , Your event '".$row['2']."' , '".$row['4']."' For CROA Sports 2018 is on '". $row['7']."' at ".$row['8'].":".$row['9']."";
curl_get_contents("http://10.31.*.*/smsrcroa.asp?B1=RPM&F_MB_TO=".$row['10']."&F_SMS_T=".$message."");
}
Same as you also redirect from below url so that this will back in while loop
header("Location: http://10.31.*.*/smsrcroa.asp?B1=RPM&F_MB_TO=".$row['10']."&F_SMS_T=".$message."");
I wants to create a php script for alerts from my work website when new notice is published, so following the page url
http://www.mahapwd.com/nit/ueviewnotice.asp?noticeid=1767
from this page i want a variable for Date & Time of Meeting (Date and time seperately two variables)
Place of Meeting and Published On
please help me to create a perfect php script.
I tried to create following script but it gives to many errors
<?php
$url1 = "http://www.mahapwd.com/nit/ueIndex.asp?district=12";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
preg_match("/href=(.*)\", $data, $urldata);
$url2 = "http://www.mahapwd.com/nit/$urldata[1];
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data2 = curl_exec($ch);
preg_match("/Published On:</b>(.*)<\/font>", $data, $pubDt);
$PubDate = $pubDt[1];
preg_match("/Time of Meeting:</b>(.*) ", $data, $MtDt);
$MeetDate = $MtDt[1];
preg_match("/Time of Meeting:</b>$MtDt[1] (.*)</font>", $data, $MtTime);
$MeetTime = $MtTime[1];
preg_match("/Place of Meeting:</b>(.*)<\/font>", $data, $pubDt);
$PubDate = $pubDt[1];
?>
Hello i have done simple code for you. You can download simple_html_dom.php from http://simplehtmldom.sourceforge.net/
require_once "simple_html_dom.php";
$url='http://www.mahapwd.com/nit/ueviewnotice.asp?noticeid=1767';
//parse url
for ($i=0;$i<1;$i++) {
$html1 = file_get_html($url);
if(!$html1){ echo "no content"; }
else {
//here is parsed html
$string1 = $html1;
//now you need to find table
$element1=$html1->find('table');
//here is a table you need
$input=$element1[2];
//now you can select row from here
foreach($input->find('td') as $element) {
//in here you can find name than save it to database than check it
}
}
}
my problem is that i'm working with salesforce in wordpress, i'm not using wordpress-to-lead plugin, I have a form in a template and that form sends data to salesforce via cURL and also is posting data in database cause I have to generate a password and then send it to the user but its not working, is working salesforce but not saving data in the database, here is my code to post data in database and generate the password
$keysString = implode(", ", array_keys($blank_section));
unset($_POST['userId']);
$user_id = mysql_query("SELECT MAX(id) AS id FROM int_form_data");
$user_id = $user_id+11;
$passwordSend = 'INTELIGOS'.rand(10000, 5000000);
$array_user_id = array('user_id' => $user_id, 'password' => $passwordSend);
$posted_data = array_merge($_POST,$array_user_id);
foreach($posted_data as $k=>$v) {
$itfdatainfo[$k] = $v;
}
$itfkeys = array_keys($itfdatainfo);
$itfvalues = array_values($itfdatainfo);
if(isset($_POST['submit'])) {
$sql = "INSERT INTO int_form_data (".implode(',',$itfkeys).") VALUES('".implode("','",$itfvalues)."')";
$result = mysql_query($sql);
}
And here I use cURL to send data to Salesforce:
//Initialize the $query_string variable for later use
$query_string = "";
$kv = array();
//If there are POST variables
if ($_POST) {
//Initialize the $kv array for later use
//For each POST variable as $name_of_input_field => $value_of_input_field
foreach ($_POST as $llav => $value) {
//Set array element for each POST variable (ie. first_name=Arsham)
$kv[] = stripslashes($llav)."=".stripslashes($value);
}
//Create a query string with join function separted by &
$query_string = join("&", $kv);
}
//Check to see if cURL is installed ...
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
//The original form action URL from Step 2
$url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
//Open cURL connection
$ch = curl_init();
//Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($kv));
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
//Set some settings that make it all work
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Execute SalesForce web to lead PHP cURL
$result = curl_exec($ch);
//close cURL connection
curl_close($ch);
Anyone knows why is happening that? I have all the code in one template in wordpress
I'm looking at this INSERT INTO int_form_data (".implode(',',$itfkeys).") and thinking if some column name in $itfkeys needs to be enclosed in backticks then it would cause an sql error.