<?php
require_once ("RestHandler.php");
$param="";
if(isset($_GET["param"]))
{
$param = $_GET["param"];
}
//var_dump($param);
if(strpos($param,'studentlogin')!==false) // for handling student login requests
{
$param = explode("-",$param);
$param = explode(",",$param[1]);
$stuID = explode("=",$param[0]);
$stuID = $stuID[1];
$pass = explode("=",$param[1]);
$pass = $pass[1];
$restHandler = new RestHandler();
$restHandler->checkStudentLogin($stuID,$pass);
}
else if(strpos($param,'teacherslist')!==false)
{
$restHandler = new RestHandler();
$restHandler->getTeachersList();
}
else if(strpos($param,'questionslist')!==false)
{
$restHandler = new RestHandler();
$restHandler->getQuestionsList();
}
?>
This is the URL to get vale.
If I call this then it works properly.
http://localhost/xampp/api/index.php?param=questionslist
Response in JSON
[{"questionID":"1","statement":"How are you?"},{"questionID":"2","statement":"What is your name?"}]
However for log in (studentlogin) I can't figure out how to pass the value.
To pass array in url do like this
http://localhost/path/index.php?param[]=param1¶m[]=param2¶m[key]=param3&name=name etc.
To pass values to via url, use whole details when click the link(submit or anything).
for example in your category:
try this:
http://localhost/xampp/api/index.php?param=text-text=[studentID],text=[password]
remove [studentID] with ID and [password] with PASSWORD.
the student details was send via url. this may work.
Related
I am troubleshooting CAPTCHA problem in someone Else's code, where the form method is "POST"
But in the action.php file the code is like this:
$key=substr($_SESSION['key'],0,5);
$number = $_GET['img_code'];
if($_GET['img_code']){
if($number==$key)
{
echo "done";
exit();
}
else
{
echo false;
exit();
}
}
I have tried to var_dump($_GET['img_code']) and as expected I am getting null value.
but if I am doing it var_dump($_POST['img_code']) I am getting the correct value.
but once I am setting it to POST, I start getting error "captcha not entered correctly.
Any help will be greatly appreciated.
UPDATE:
FORM METHO
<form action="{$Site_Root}signup.php" method="post" class="frmRegister tutor-registration" name="frmRegister" id="frmRegister" enctype="multipart/form-data" >
Further Update:
If I am using $_REQUEST['img_code'] and then doing a var_dump I am getting the matching string for $key and $number like
string(5) "f065a" string(5) "f065a"
but problem is when I am applying this as a condition for example:
I am getting - "captcha not entered correctly."
if(isset($_POST['email'])){
if ($key==$number){ // condition line is added by me
if(!empty($_FILES['photo']['name']))
{
$_POST['photo'] = fileUpload($_FILES['photo'],TUTOR);
$thumb->image($physical_path['Tutor'].$_POST['photo']);
$thumb->size_width(120);
$thumb->jpeg_quality(100);
$filename = $thumb->get2(); //small_thumb_
}
else
{
$_POST['photo'] = "";
}
$tutor_id = $tut->Insert($_POST);
$to_email = $_POST['email'];
global $mail;
$mail = '';
$mail = new htmlMimeMail();
$mail->setFrom($config[WC_CONTACT_US]);
//Set Cc
// $mail->setCc(array($config[WC_CONTACT_US]));
$mail->setSubject('Welcome to TuitionJobsPortal.com!');
$tpl2 = new Smarty;
$tpl2->template_dir = $physical_path['EmailTemplate'];
$tpl2->compile_dir = $physical_path['Site_Root']. 'templates_c/';
$tpl2->debugging = DEBUG;
$tpl2->assign(array("membername" => $_POST['tutor_name'],
"vcode" => $_POST['verification_code'],
"tutor_id" => $tutor_id,
"Templates_Image" => $virtual_path['Site_Root'].'templates/images/',
"Site_Root" => $virtual_path['Site_Root'],
));
$content = $tpl2->fetch('registration'. $config['tplEx']);
$mail->setHtml($content);
$result = $mail->send(array($to_email));
header("location: signup.php?signup=true");
exit();
}
} //this is added.
I don't think you can access $_POST data from $_GET , so either change form method to GET or access posted data using $_POST['img_code'] .
You can use the $_REQUEST global variable, it can do the work of both GET and POST,
i have some problem, i made some local website using php.
I have a file called functions.php which this is the code:
public function saveAll($idmt_salesarea, $thn_bln, $no_pesanan, $tgl_pesan, $idms_langganan, $idms_kodebarang, $quantity, $harga, $jumlah, $disc_cash, $disc_kredit){
$message = "Waiting input...";
try{
$con = new db();
$conn = $con->connect();
$query = "INSERT INTO mt_pesanan(idmt_salesarea,thn_bln,no_pesanan,tgl_pesan,idms_langganan, idms_kodebarang,quantity,harga,jumlah,disc_cash,disc_kredit) VALUES ($idmt_salesarea, '$thn_bln', '$no_pesanan', '$tgl_pesan', $idms_langganan, $idms_kodebarang, '$quantity', $harga, $jumlah, '$disc_cash', '$disc_kredit')";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn) . " " . mysqli_errno());
if($result == 1){
$message = "Success";
} else if($result == 0){
$message = "Failed";
}
}catch(Exception $exc){
echo $exc->getCode();
}
$con->disconnect();
return $message;
}
i Take the input parameter from file called: index.php and pass the parameter using AJAX Jquery. The parameter itself is sent and pointing to file called insert.php
here's the insert.php file:
<?php
include_once 'functions.php';
$idmt_salesarea = isset($_GET['salesarea']);
$thn_bln = isset($_GET['thn_bln']);
$no_pesanan = isset($_GET['nopes']);
$tgl_pesan = isset($_GET['tglpes']);
$idms_langganan = isset($_GET['idlangganan']);
$idms_kodebarang = isset($_GET['idbarang']);
$quantity = isset($_GET['quantity']);
$harga = isset($_GET['harga']);
$jumlah = isset($_GET['jumlah']);
$disc_cash = isset($_GET['disc_cash']);
$disc_kredit = isset($_GET['disc_kredit']);
if (($disc_cash == null) || ($disc_kredit == null)) {
$disc_cash = 0;
$disc_kredit = 0;
}
$insert = new functions();
$insert->saveAll($idmt_salesarea, $thn_bln, $no_pesanan, $tgl_pesan, $idms_langganan, $idms_kodebarang, $quantity, $harga, $jumlah, $disc_cash, $disc_kredit);
?>
but when i check the error, that is the variable that cannot get from insert.php file (using $_GET statement).
How proper way to gain the variable? because all the parameter is set.
I know this is combining object oriented style and old fashion php coding. Any ideas?
thanks in advance.
UPDATE
here's the index.php file using jquery ajax to sent the data
function sendAll(){
var tgl_pesan = $('#dpc').val();
var sales_area = $('#sales_area').val();
var nopes = $('#no_pesanan').val();
var thnbln = getTahunBulan();
var id_langganan = $('#kode_langganan').val();
var id_barang = $('#kode_barang').val();
var quantity = getQuantity();
var harga = $('#harga').val();
var jumlah = $('#jumlah').val();
var disc_cash = $('#cash').val();
var disc_kredit = $('#kredit').val();
var max = $('#max').val();
$.ajax({
type:"POST",
**url:"insert.php",**
data:{
salesarea:sales_area,
thn_bln:thnbln,
nopes:nopes,
tglpes:tgl_pesan,
idlangganan:id_langganan,
idbarang:id_barang,
quantity:quantity,
harga:harga,
jumlah:jumlah,
disc_cash:disc_cash,
disc_kredit:disc_kredit,
max:max
},
success:function(msg){
alert("Data Inserted");
},
error:function(msg){
alert("Data Failed to save" + msg);
}
});
the ajax itself is pointing to file insert.php which the insert.php is executing function from another file called functions.php
The problem is with this code:
$idmt_salesarea = isset($_GET['salesarea']);
$thn_bln = isset($_GET['thn_bln']);
$no_pesanan = isset($_GET['nopes']);
$tgl_pesan = isset($_GET['tglpes']);
$idms_langganan = isset($_GET['idlangganan']);
$idms_kodebarang = isset($_GET['idbarang']);
$quantity = isset($_GET['quantity']);
$harga = isset($_GET['harga']);
$jumlah = isset($_GET['jumlah']);
$disc_cash = isset($_GET['disc_cash']);
$disc_kredit = isset($_GET['disc_kredit']);
For each of those variables, you are assigning the result of isset(), which will evaluate to either TRUE or FALSE. If you want to bind the actual value of your $_GET input, change each line from this syntax:
$idmt_salesarea = isset($_GET['salesarea']);
To
$idmt_salesarea = isset($_GET['salesarea']) ? $_GET['salesarea'] : '';
However this code isn't really maintainable, and I would also recommend using arrays instead of passing that many arguments to your saveAll() method.
In response to your update
If you are sending an AJAX request with type: "POST", you cannot access your input data via the PHP $_GET super global, you have to use $_POST. However, what I said before is still valid, as you aren't binding values to your variables properly.
Although I do not get what you are saying completely, still based on your description the problem can be you sending the variable using ajax call. If the ajax call is async you might not get the value by the time you use it.
So you can either set async:false in the ajax call (which is not a good way) or trigger any thing that uses that variable from within the success callback handler of the ajax call.
It would be really helpful if you can share the piece of code which explains the following statement of yours.... "i Take the input parameter from file called: index.php and pass the parameter using AJAX Jquery. The parameter itself is sent and pointing to file called insert.php"
I have an array with user information and a web service on a site I can query for the status of a user (online/offline). What I would like to do is query the site every x seconds for the status of each user.
There are about 10 users and belwois an example of the array. I can change the array is needed. Only thing I need to enter manually is the username and full name. The "status" I can call from the server.
$users = array
(
"username"=>array("Fullname","Status"),
"johndoe"=>array("John Doe","Online"),
"janedoe"=>array("Jane Doe","Offline")
);
This is an example of the url I can use to query the site (the query returns only the users status (Online or Offline):
http://thesite.com:80/webservice/user/username/
This is the code I can use to get a specific user status:
$url = 'http://thesite.com:80/webservice/user/johndoe/';
$get = fopen($url, "r");
if ($get) {
while (!feof($get)) {
$state = fgets($get, 4096);
}
fclose($get);
}
echo "User johndoe is: ".$status;
// Output: User johndoe is: Online
Now I only need help with iterating through the users and site every x seconds and update the array with each user status in the last array field for the user.
Please note that below I use php and fopen as this is a cross-domain get function and I could not get ajax/jquery to work. I do not have the option to modify the webservice server.
Thanks :)
You need to create a cronjob script that runs every x seconds. That script should be an asynchronous request to this PHP function.
public function updateUsers(){
$users = $_SESSION['users'];
foreach($users as $username=>$data) {
$url = 'http://thesite.com:80/webservice/user/'.$username.'/';
$get = fopen($url, "r");
if ($get) {
while (!feof($get)) {
$status = fgets($get, 4096);
}
fclose($get);
}
$users[$username][] = $status;
}
$_SESSION['users'] = $users;
}
A guide for posting asynchronous requests . http://petewarden.typepad.com/searchbrowser/2008/06/how-to-post-an.html
Hope it helps :)
If your $users array don't changes, you can do this:
foreach($users as $username=>$userdata) {
$url = 'http://thesite.com:80/webservice/user/'.$username.'/';
$get = fopen($url, "r");
if ($get) {
while (!feof($get)) {
$state = fgets($get, 4096);
}
fclose($get);
}
$users[$username][1] = $state;
}
If you can change your $users array to be associative like this:
$users = array(
"username"=>array("fullname"=>"Fullname","status"=>"Status"),
"johndoe"=>array("fullname"=>"John Doe","status"=>"Online"),
"janedoe"=>array("fullname"=>"Jane Doe","status"=>"Offline")
);
That would let you use more key/values and a bit safer.
I’m using drupal to create some custom form that submit to a third party, and I’m trying to bundle my form results - some of which have some conversion functions applied to them - to send to the form recipient.
I’ve used Drupal’s drupal_http_request function on simple forms and its’ worked well, but now that some of my results give value to vars, I’m not sure how to create a keyed array that continues to pass the value of the var.
I know that when I send my form directly to my third party, they receive the correct result, however I am trying to send them the results but redirect to a page in my own site, so i know my form works at least - and it’s just this function of using the trying encode so i have control over redirect that doesn’t.
but I don't even know if a keyed Array can have variables as it's values or not, or if it's a matter of syntax
This is my code:
function formshare_nameform_submit($form_id, &$form_state) {
// Lookup share matrix return value
$shareMatrixValue = setShareMatrixValue($form_state['values']['image_id']);
$langResultsCode = setLangForShare($langCode);
$gender = setGenderForShare($form_state['values']['gender']);
$first_name = $form_state['values']['first_name'];
$last_name = $form_state['values']['last_name'];
$email = $form_state['values']['email'];
$email_friend1 = $form_state['values']['email_friend1'];
$email_friend2 = $form_state['values']['email_friend2'];
$email_friend3 = $form_state['values']['email_friend3'];
$message = $form_state['values']['massage'];
$optin = $form_state['values']['optin'];
$category = $form_state['values']['category'];
$image_id = $shareMatrixValue;
$id_langue = $form_state['values']['id_langue'];
// Make an array of values to pass to 3rd party.
$pass_these = array();
$pass_these['shareMatrixValue'] = $shareMatrixValue;
$pass_these['langResultsCode'] = $langResultsCode;
$pass_these['gender'] = $gender;
$pass_these['first_name'] = $first_name;
$pass_these['last_name'] = $last_name;
$pass_these['email'] = $email;
$pass_these['email_friend1'] = $email_friend1;
$pass_these['email_friend2'] = $email_friend2;
$pass_these['email_friend3'] = $email_friend3;
$pass_these['message'] = $message;
$pass_these['optin'] = $optin;
$pass_these['category'] = $category;
$pass_these['image_id'] = $image_id;
$pass_these['id_langue'] = $id_langue;
// Post the data to 3rd party.
$url = 'http://mythirdpartysite.com';
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$data = drupal_query_string_encode($pass_these);
drupal_http_request($url, $headers, 'POST', $data);
}
you can either store the variable by reference with &$var or simply store the name of the variable in the array and use $$array['key']; to get the $var value
best thing is create an stdClass object and store the vars as atributes, it works like an associative array but it's cleaner
i am sending some value to a php file like this:
$.post('php/xxx.php', { username: userName } );
and the php file echo'es out a var $test
how can i get it back into the js?
i was thinking to use this:
var get_back = $.get('php/xxx.php', ... );
but i am not sure how...
thanks
edit:
here is my php file:
include("connect.php");
$get_username = $_POST['username'];
$username = '';
$username = mysql_real_escape_string($get_username);
echo $get_username;
$result = mysql_fetch_assoc(mysql_query("SELECT username FROM database WHERE username='$username' LIMIT 1"));
if($result !== FALSE) {
echo $username;
}
i want to get back this echo $username; value
The various ajax functions in jQuery (ajax, post, get) accept callback functions where you can handle the returned data:
//define username outside so that
//it's available outside of the scope
//of the callback function
var username;
$.post('php/xxx.php',
{ username: userName },
function(data){
//per the comment below,
//assuming data will simply
//be the username
username = data;
});