variables in url are being truncated - php

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");
?>

Related

How to merge two PHP' include' to one PHP 'include' aand use to a PHP Page

guys currently I build a web site using PHP. I connect my website to the database using web services (url). The system is run as well. Then, I separate the web services by creating other PHP files, place the web services and include the PHP file to my web site. This is also running well. Below is the code:
add_factory.php
<?php
include("../../config/check.php");
if(isset($_POST['Submit']))
{
$Fac_ID = $_POST['Fac_ID'];
include("../../api/api_add_factory.php"); //include web services 1
if(empty($queryt)){
include("../../api/api2_add_factory.php"); //include web services 2
if(!empty($json2)){
header("Location:factory.php");
}else{
echo "
<script>alert('Something wrong, please try again')</script>
<script>window.location = 'factory.php'</script>
";
}
}
else{
echo "
<script>alert('The factory you want to add is already exist')</script>
<script>window.location = 'factory.php'</script>
";
}
}
?>
api_add_factory.php
<?php
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/selectFactory?Fac_ID=$Fac_ID";
$data = file_get_contents($url);
$json = json_decode($data);
$queryt = $json->factoryList;
?>
api2_add_factory.php
<?php
$url2 = "http://172.20.0.45/TGWebService/TGWebService.asmx/insertFactory?fac_id=$Fac_ID&fac_name=$Fac_ID";
$data2 = file_get_contents($url2);
$json2 = json_decode($data2);
?>
When you see at "add_factory.php", There's two include. Now, I want to use only single include that can call "api_add_factory.php" and "api2_add_factory.php". But I dont know how to do that since the "include" at "add_factory.php" is at different position.
Can anyone knows how to merge both include file into one and where i need to pu the include file at "add_factory.php"?
My suggestion would be to rewrite the contents of api_add_factory.php and api2_add_factory.php as functions.
This would allow you to control how and when they are called by the piece of code that includes them, rather than being executed immediately when the include is called.
Also, as a general rule of thumb, includes should all be called at the beginning of your file because otherwise they can become very difficult to keep track of.
So, I would say you can do something like this:
api_add_factory.php
<?php
function callApi1()
{
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/selectFactory?Fac_ID=$Fac_ID";
$data = file_get_contents($url);
$json = json_decode($data);
return $json->factoryList;
}
api2_add_factory.php
<?php
function callApi2()
{
$url2 = "http://172.20.0.45/TGWebService/TGWebService.asmx/insertFactory?fac_id=$Fac_ID&fac_name=$Fac_ID";
$data2 = file_get_contents($url2);
return json_decode($data2);
}
add_factory.php
<?php
include("../../config/check.php");
include("../../api/api_add_factory.php"); //include web services 2
include("../../api/api2_add_factory.php"); //include web services 2
if(isset($_POST['Submit']))
{
$Fac_ID = $_POST['Fac_ID'];
$queryt = callApi1();
if(empty($queryt)){
$json2 = callApi2();
if(!empty($json2)){
header("Location:factory.php");
}else{
echo "
<script>alert('Something wrong, please try again')</script>
<script>window.location = 'factory.php'</script>
";
}
}
else{
echo "
<script>alert('The factory you want to add is already exist')</script>
<script>window.location = 'factory.php'</script>
";
}
}
Actually, now that I am taking a look at my answer, I can see a possibility for a further improvement: since the contents of api_add_factory.php and api2_add_factory.php are actually the same apart from the url that gets called, you can do something like this:
api_add_factory.php
<?php
function callApi($url)
{
$data = file_get_contents($url);
return json_decode($data);
}
add_factory.php
<?php
include("../../config/check.php");
include("../../api/api_add_factory.php"); //include web services
$url1 = "http://172.20.0.45/TGWebService/TGWebService.asmx/selectFactory?Fac_ID=$Fac_ID";
$url2 = "http://172.20.0.45/TGWebService/TGWebService.asmx/insertFactory?fac_id=$Fac_ID&fac_name=$Fac_ID";
if(isset($_POST['Submit']))
{
$Fac_ID = $_POST['Fac_ID'];
$json1 = callApi($url1);
$queryt = $json1->factoryList;
if(empty($queryt)){
$json2 = callApi($url2);
if(!empty($json2)){
header("Location:factory.php");
}else{
echo "
<script>alert('Something wrong, please try again')</script>
<script>window.location = 'factory.php'</script>
";
}
}
else{
echo "
<script>alert('The factory you want to add is already exist')</script>
<script>window.location = 'factory.php'</script>
";
}
}
This way, we don't need to repeat the code of the function.

Russian Characters in URL PHP

I have scoured the internet and I'm either not finding the answer or I'm unable to implement it correctly.
Basically I am trying to implement a website in Russian on PHP. I have already got the website in English and French but bringing a whole new range of characters in has sort of broken the test site. My actual goal is to have the Cyrillic characters in the URL, similar to how Wikipedia are able to do it > https://ru.wikipedia.org/wiki/Компьютер and also still find this in the database to show the correct location information.
In my SQL database I have a range of locations, countries such as France, Germany, Australia etc. I have set it up so that the location page is generated dynamically from those entries using the $data['Name'] variable. Now... in the header.php file I use this to generate the location names from the database for the navigation:
<li class="dropdown">
Места
<ul>
<?php if (is_array($locations)) {
foreach ($locations as $key => $location) {
$name = strtolower(str_ireplace(" ","-", $location['name']));
if ($location['top_location'] == 1)
echo '<li>'.$location['name'].'</li>';
}
}
?>
</ul>
</li>
Where $name is replaced by database entries. If I change one of the database entries to Russian (Australia for example - Австралия) then the location page throws a 404 error as it's actually trying to find location/%D0%90%D0%B2%D1%81%D1%82%D1%80%D0%B0%D0%BB%D0%B8%D1%8F rather than location/Австралия.
My location page has the following code to get information from the database:
<?php
include './inc/utils.php';
if (isset($_GET['id'])) {
$name = str_ireplace("-"," ", $_GET['id']);
$result = get_data("Locations", array("name" => $name))[0];
}
else
$result = null;
if ($result != null) {
$data['Name'] = $result['name'];
$data['Url_Name'] = $_GET['id'];
$data['Image'] = $result['image'];
$data['Slider_Text'] = $result['slider_text'];
$data['Description'] = $result['description'];
$data['Country'] = $result['top_location'] != 0 ? true : false;
$data['Cars_In_Location'] = get_cars_in_location($result['id']);
$img_url = $MASTER['car_img_url'];
$link_url = $MASTER['base_url'].'car/';
$cities_id = explode(",", $result['related']);
foreach ($cities_id as $value) {
$data['Related'][] = get_data("Locations", array("id" => $value))[0];
}
}
else {
$data['Name'] = "";
$data['Url_Name'] = "";
$data['Image'] = "";
$data['Slider_Text'] = "";
$data['Description'] = "";
$data['Country'] = false;
$data['Related'] = "";
$data['Cars_In_Location'] = "";
}
if (empty($data['Name']) == true) {
header('HTTP/1.1 404 Not Found');
header('Location: '.$MASTER['base_url'].'404.php');
}
include 'header.php';
?>
I have tried using urldecode to no avail. I think I am missing something either on the SQL side or in one of the function files.
my header.php file contains both
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> and
header('Content-Type: text/html; charset=utf-8');
as well as my location page containing
header('Content-Type: text/html; charset=utf-8');
my .htaccess file has
AddDefaultCharset UTF-8
I don't know what else I'm missing.
You can see the page here:
https://redfoxluxurycarhire.com/ru/location/Австралия
I am using print_r($host_url) to correctly print the URL despite what it shows so you can see my issue. I am also able to echo Австралия onto the location pages with no problems or encoding.
Any help would be much appreciated as I'm wracking my brain as how to get this to work!
I would start checking if you have any file-systems encoding problem. Check your scripts are using UTF-8, I believe your MySQL database is OK. You should be able to decode requests with urldecode.

using $_GET['VALUE'] from a FORM using method POST

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,

PHP action inside PHP already running

Good Day
I am not sure if this is possible but any advice would be greatly be appreciated.
I have a code in PHP as below and would like to add additional PHP code Not sure how to explain it but maybe if I show code it would make some sence.
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl ="http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
$to = "'0827910119'";
?>
The above is the current code I have with some additional extra's not required here. I want to add the following to this code as part of Sitelok page manager
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl ="http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
<?php if (sl_ismemberof("RecAssist")){ ?>
$to = "'0827911119'";
<?php } ?>
<?php if (sl_ismemberof("Gold")){ ?>
$to = "'0827952558'";
<?php } ?>
?>
The "is a member of" is part of the sitelok code to exclude on HTML where a person does not have access to. I am not sure if I can run another inside the one running already. I know this can be done with IF and ELS most prob but the coding for the amount of groups will just be too much so hoped that somehow I can use the Sitelok section
Why not just use an if statement?
e.g.
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl = "http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
if (sl_ismemberof("RecAssist")){
$to = "'0827911119'";
} elseif (sl_ismemberof("Gold")) {
$to = "'0827952558'";
}
?>
The best an most maintainable way to achieve this would be to define all of your groups or w/e in an associative array and loop through it because it will be the most maintainable.
<?php
//Clickatell login
$user = "##";
$password = "##";
$api_id = "##";
$baseurl = "http://api.clickatell.com";
$text = urlencode("Recovery Assist Panic Activated (BETA TEST VERSION");
$groups = array(
"RecAssist" => "0827911119",
"Gold" => "0827952558",
);
$to = "";
foreach($groups as $k=>$v)
{
if(sl_ismemberof($k)) // $k is the RecAssist or Gold or w/e
{
$to = "'$v'"; // $v is those digits
// if $groups were to have 100 items or even 1,000 then there is no need to run sl_ismemberof() on the remaining items once we found what we are looking for. It would be a waste of time.
break; // break out of our loop
}
}
echo $to;
?>

Syntax or Variable error in 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);

Categories