Syntax or Variable error in PHP - php

Is there any problem with this PHP code? It displays nothing. Please help.
<?php
date_default_timezone_set('Asia/Kuala_Lumpur');
$date_time = date('Y-m-d H:i:s');
$host = $_SERVER['HTTP_HOST'];
$device = Detect::deviceType();
$device_brand = Detect::brand();
$operating_system = Detect::os();
$browser_name = Detect::browser();
$service_host = Detect::ipHostname();
$service_org = Detect::ipOrg();
$ip_country = Detect::ipCountry();
echo $host;
echo $date_time;
echo "IP: ". $ip_country;
?>

1) Your script is calling Detect class, but I don't see from where it comes. Are you including a file containing its declaration?
2) Is Detect class "mute", ie, works without verbose response?
3) If you are not getting any errors, try to add to your script first lines
error_reporting(2047);
ini_set("display_errors",1);

Related

Writing .php file using php code

Hi there I'm trying to write a .php file using this code, server replying this error : syntax error, unexpected '0' (T_LNUMBER) in
I wanna know how can I write integer in php file as you can see
$status1 = \''0'\';
This code having problem, anybody please tell me what to do.
<?php
if(isset($_POST['user1'])){
$data = urldecode('%3C').'?php
$user1 = \''.$_POST['user1'].'\';
$pass1 = \''.$_POST['pass1'].'\';
$status1 = \''0'\';
$user2 = \''.$_POST['user2'].'\';
$pass2 = \''.$_POST['pass2'].'\';
$status2 = \''0'\';
$user3 = \''.$_POST['user3'].'\';
$pass3 = \''.$_POST['pass3'].'\';
$status3 = \''0'\';
$user4 = \''.$_POST['user4'].'\';
$pass4 = \''.$_POST['pass4'].'\';
$status4 = \''0'\';
$user5 = \''.$_POST['user5'].'\';
$pass5 = \''.$_POST['pass5'].'\';
$status5 = \''0'\';
$user6 = \''.$_POST['user6'].'\';
$pass6 = \''.$_POST['pass6'].'\';
$status6 = \''0'\';
$user7 = \''.$_POST['user7'].'\';
$pass7 = \''.$_POST['pass7'].'\';
$status7 = \''0'\';
$user8 = \''.$_POST['user8'].'\';
$pass8 = \''.$_POST['pass8'].'\';
$status8 = \''0'\';
$user9 = \''.$_POST['user9'].'\';
$pass9 = \''.$_POST['pass9'].'\';
$status9 = \''0'\';
$user10 = \''.$_POST['user10'].'\';
$pass10 = \''.$_POST['pass10'].'\';
$status10 = \''0'\';
?'.urldecode('%3E');
$fx=fopen('datauser.php','w');
fwrite($fx,$data);
fclose($fx);
if($fx === false) {
header("Location: ./tokensettings.php?save=err");
}
else {
header("Location: ./tokensettings.php?save=success");
}
}
?>
Thank you so much.
Here is how my form looks like.
If you still want to do it your way you need to use the \ correctly for each ' to be included in the string even those in [ ] - not saying the final string produced would actually work but it is based on your code and my best guess at your desired result
<?php
$string1=' \'\'.$_POST[\'user1\']\'\';';
$string1=$string1.'\'\'0\'\';';
echo $string1;
?>
The whole urlencoding stuff is not needed at all, your quoting and escaping is messy and incorrect. and why not simply use file_put_contents? Use HEREDOC to avoid messy escaping.
file_put_contents('datauser.php', <<<CONTENT
<?php
\$user = '{$_POST['user']}';
\$pass = '{$_POST['pass']}';
\$status = '0';
CONTENT
);
but if you really want to use files as data storage, I would encourage you to save it in a data format like xml or json instead of writing php.
// save data to file ($_POST used as example...)
file_put_contents('user.json', json_encode($_POST));
// read data
$data = json_decode(file_get_contents('user.json'));

URL Error 2912 in fopen($url, "r")

I receive "error 2912" when I request a URL through fopen($url, "r") in PHP
Example:
It is actually on an sms API. I initiated some variables to substitute for some required fields.
$url = api.smartsmssolutions.com/smsapi.php?username=myusername&password=mypassword&sender=".$sender."&recipient=".$d3."&message=".$const_msg;
As per error 2912 your Recipient is empty. The correct format given is
http://api.smartsmssolutions.com/smsapi.php?username=YourUsername&password=YourPassword&sender=SenderID&recipient=234809xxxxxxx,2348030000000&message=YourMessage
Check by changing the url as below
$username = "YOUR_USERNAME";
$password = "YOUR_PASSWORD";
$sender = "YOUR_ID";
$d3 = "2348922223,2569878987";
$const_msg = "YOUR_MESSAGE";
$url = "http://api.smartsmssolutions.com/smsapi.php?username={$username}&password={$password}&sender={$sender}&recipient={$d3}&message={$const_msg}";
Error code 2912=Recipient is empty.
Please check correct value send by parameter.
The problem was that the variables were not initiated properly.
I had to use UrlEncode() in parsing the variables to the fopen($url).
Like This.
$urlt = "http://api.smartsmssolutions.com/smsapi.php?username=".UrlEncode($username)."&password=".UrlEncode($password)."&sender=" . UrlEncode($sender)
."&recipient=234" . UrlEncode($d3)
.",&message=" . UrlEncode($const_msg);

variables in url are being truncated

I am passing a website and a message through a url to another webpage. The website in its self contains some get variables. The problem comes from the fact that when the site and the message is passed, the site variables are being truncated. I have searched for a way to solve this and did not understand what others were doing. Thanks for the help in advance. The code is below:
<?php
$I_D = 0;
$EI_D = 1;
$site = "orowland/eval.php?eval=$I_D&stats=$EI_D";
header("location:message.php?message=Site has been created&site=$site");
?>
In message.php:
<?php
if (isset($_GET['message']))
{
$message = $_GET['message'];
$site = $_GET['site'];
echo $message;
echo $site;
}
?>
Output on page:
orowland/eval.php?eval=0
But the expected output is:
orowland/eval.php?eval=0&stats=1
It is probably a good idea to urlencode() that string as it contains spaces
So do
<?php
$I_D = 0;
$EI_D = 1;
$site = "orowland/eval.php?eval=$I_D&stats=$EI_D";
$message = urlencode('Site has been created');
$url = "message.php?message=$message&site=$site";
header("location: $url");
?>

PHP - Class not found after being included

I've search the answer about this question , but it doesn't solve my problem.
I have include these class
include "class/config.class.php";
include "config/config.php";
include "class/db.mssql.class.php";
on my check_login.php
and when i tried to login , after i have done type username and password, it does not do anything. Instead it show error when i use firebug .
Fatal error: Class 'cfgConn' not found in D:\wamp\www\mapis\config\config.php on line 2
this is what config.php looks like..
<?php
$cfgConn = new cfgConn();
$confMs = $cfgConn->getConf("mssql_configuration");
$dbHostMs = $confMs['host'];
$dbPortMs = $confMs['port'];
$dbNameMs = $confMs['dbName'];
$dbUserMs = $confMs['user'];
$dbPasswordMs = $confMs['pass'];
this is the path of config.php
D:\wamp\www\mapis\config\config.php
I did not see where is the error. The web is fine before i change my WAMP from 2.2 to 2.4, and after that this is what happen.
Note : the class/config.class.php was included just fine. it does not show error, instead it show the output at Firebug.
Can anybody show me what is wrong with my code?
Additional :
This is cfgConn class defined and the file name is config.class.php
<?
class cfgConn
{
function getConf($chs)
{
switch($chs)
{
//SQLServer Connection
case "mssql_configuration" : {
$c['host'] = "IT-KUNTO";
$c['dbName'] = "MAP";
$c['port'] = "";
$c['user'] = "rafi";
$c['pass'] = "P#ssw0rd";
}break;
}
return $c;
}
}
?>
In config.php file include config.class.php like this.
<?php
include "class/config.class.php";
$cfgConn = new cfgConn();
$confMs = $cfgConn->getConf("mssql_configuration");
$dbHostMs = $confMs['host'];
$dbPortMs = $confMs['port'];
$dbNameMs = $confMs['dbName'];
$dbUserMs = $confMs['user'];
$dbPasswordMs = $confMs['pass'];

cakephp error while saving data

i am working on a cakephp 2.x ... well the scenario is that i am sending messages to my webapp ... there are almost 509 messages ... the problem is it is saving some messages into db and on some messages it gives me an error on android console ... ...so first thing i want to ask what u all think that where the actual problem lies or can be lie..and the other think is there a way that i can throw some exception error on data which is not saving into the db .. so i can track the particular messages which is not saving into and causing the problem ...i need some help in debugging this code
here is my code
public function message(){
$this->loadModel('Message');
if ($this->request->isPost()){
$json = $this->request->data('json');
$data = json_decode($json, TRUE);
foreach($data as $datas){
$date = $datas['date'];
$mobileNo = $datas['mobileNo'];
$mobileNo = AllSecure::replaceDashesAndSpaces($mobileNo);
$body = $datas['body'];
$timestamp = $date/1000;
$date = date('Y-m-d h:i' , $timestamp);
$this->request->data['Message']['mobileNo'] = $mobileNo;
$this->request->data['Message']['body'] = $datas['body'];
$this->request->data['Message']['type'] = $datas['type'];
$this->request->data['Message']['User_id'] = $datas['idUser'];
$this->request->data['Message']['dateTime'] = $date;
$count = $this->Message->checkTextMessages($mobileNo,$body,$date,$datas['idUser']);
if($mobileNo!=null){
if($count>0){
}else{
$this->Message->create();
$this->Message->save($this->request->data
}
}
}
}
}
well i solved my problem by self ... i dont know why it is causing the problem ... so i did this .. and it works
foreach($data as $datas){
$i=0
$this->request->data['Message'][$i]['mobileNo'] = $datas['mobileNo'];;
$this->request->data['Message'][$i]['body'] = $datas['body'];
$this->request->data['Message'][$i]['type'] = $datas['type'];
$this->request->data['Message'][$i]['User_id'] = $datas['idUser'];
$i++;
if($mobileNo!=null){
}
}
$isSave = $this->Message->saveAll($this->request->data["Message"]);
echo $isSave;

Categories