- 1
Как-то долго на PHP говнокода не появляется, все научились писать что ли?
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+142
Как-то долго на PHP говнокода не появляется, все научились писать что ли?
+142
public function api() {
...
if ($this->validate()) {
if ($store_info) {
$url = $store_info['ssl'];
} else {
$url = HTTPS_CATALOG;
}
if (isset($this->session->data['cookie']) && isset($this->request->get['api'])) {
...
$curl = curl_init();
// Set SSL if required
if (substr($url, 0, 5) == 'https') {
curl_setopt($curl, CURLOPT_PORT, 443);
}
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_USERAGENT, $this->request->server['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url . 'index.php?route=' . $this->request->get['api'] . ($url_data ? '&' . http_build_query($url_data) : ''));
if ($this->request->post) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->request->post));
}
curl_setopt($curl, CURLOPT_COOKIE, session_name() . '=' . $this->session->data['cookie'] . ';');
$json = curl_exec($curl);
curl_close($curl);
API в опенкарте. Ну, короч, приходит пользователь, дергает АПИ, а я сам в контроллере дергаю свое АПИ. Такая практика.
https://github.com/opencart/opencart/blob/4a151334efc702729071bd8d45a7e4af4e07b3ef/upload/admin/controller/sale/order.php#L2152
+142
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
session_start();
require "db.php";
$id = $_GET["id"];
pagedel($id);
header ("location: index.php");
function pagedel($id){ // функция удаления страниц
$sql = "DELETE FROM mesage WHERE id=$id";
mysql_query($sql) or die (mysql_error());
}
?>
не работает фукция удаления строки
+141
<?php
require_once 'db.php';
error_reporting(E_ALL);
//полученный масиф (B!) на предыдущей страницы методом Post
$first_name = filter_input(INPUT_POST, 'first_name');
$email = filter_input(INPUT_POST, 'email');
$phone = filter_input(INPUT_POST, 'phone');//PHONE BLYAD
$text = filter_input(INPUT_POST, 'text');
$date = date("Y-m-d H:i:s");
//Теперь сделаем запрос к базе, который внесет наши данные в таблицу:
$query = $dblink->prepare("INSERT INTO `claims` (`date`,`first_name`, `email`, `phone`, `text`) VALUES (?, ?, ?, ?,?);");
$result = $query->execute (array($date, $first_name, $email, $phone, $text));//MAYBE IT'S CAN RAISE PDOException, see more in documentation
//Если запрос пройдет успешно то в переменную result вернется true
if($result)
{ $URL="http://masterdnepr.dp.ua/";
header ("Location: $URL");
}
else {echo "Ваши данные не добавлены";
}
?>
Вот так заработало
+142
<form method="post" action="/php/form.php" id="add_form">
<label>Как к Вам обращаться:</label>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-user"></span>
<input type="text" class="form-control" name="first_name" placeholder="Имя" aria-label="...">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<label>Email (не публикуется):</label>
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-envelope " id="basic-addon1"></span>
<input type="text" class="form-control" name="email" placeholder="Электронная почта" aria-describedby="basic-addon1">
</div>
<label>Телефон (не публикуется):</label>
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-phone"></span>
<input type="text" class="form-control" name="phone" placeholder="телефон" aria-describedby="basic-addon1">
</div>
</div>
<center><label>Опишите суть ситуации:</label></center>
<div>
<center><textarea name="text" required="" rows="8" style="width: 510;"></textarea></center>
</div>
<dl>
</dl>
</div>
<div class="modal-footer"><center>
<button type="button" class="btn btn-danger" data-dismiss="modal">Отказаться</button>
<button type="submit" class="btn btn-success" data-toggle="tooltip" data-placement="right" title="После Вашей заявки,мастер свяжеться с Вами в ближайшее время">Заказать мастера</button>
</center>
</div>
</div>
</form>
вот сама форма
+143
<?php
require_once 'db.php';
error_reporting(E_ALL);
//полученный масиф (B!) на предыдущей страницы методом Post
$first_name = filter_input(INPUT_POST, 'first_name');
$email = filter_input(INPUT_POST, 'email');
$phone = filter_input(INPUT_POST, 'phone');//PHONE BLYAD
$text = filter_input(INPUT_POST, 'text');
$date = date("Y-m-d H:i:s");
//Теперь сделаем запрос к базе, который внесет наши данные в таблицу:
$query = $dblink->prepare("INSERT INTO `claims` (`time`,`first_name`, `email`, `phone`, `text`) VALUES (?, ?, ?, ?,?);");
$result = $query->execute (array($date, $first_name, $email, $phone, $text));//MAYBE IT'S CAN RAISE PDOException, see more in documentation
//Если запрос пройдет успешно то в переменную result вернется true
if($result)
{echo $URL="http://masterdnepr.dp.ua/#home";
header ("Location: $URL");}
else {echo "Ваши данные не добавлены";
}
?>
не приходят данные.Пишет Ваши данные не добавлены
+142
//Search from title,content,category,address,zipcode,city
if ($s_for !== '' && $s_cat !== '' && $s_to !== '') {
$query = "SELECT *
FROM
$wpdb->posts
INNER JOIN $wpdb->term_relationships
ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
LEFT JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
WHERE
$wpdb->posts.post_status = '$cc_post_status'
AND $wpdb->posts.post_type = '$cc_post_type'
AND ($wpdb->posts.post_title LIKE '%$s_for%'
OR $wpdb->posts.post_content LIKE '%$s_for%')
AND (($wpdb->postmeta.meta_key = '$cc_meta_address' AND $wpdb->postmeta.meta_value LIKE '%$s_to%')
OR ($wpdb->postmeta.meta_key = '$cc_meta_city' AND $wpdb->postmeta.meta_value = '$s_to')
OR ($wpdb->postmeta.meta_key = '$cc_meta_zipcode' AND $wpdb->postmeta.meta_value = '$s_to'))
AND $wpdb->term_relationships.term_taxonomy_id = {$s_cat}
GROUP BY ID {$limit}";
//Search from title,content
} elseif ($s_for !== '' && $s_cat == '' && $s_to == '') {
$query = "SELECT *
FROM
$wpdb->posts
INNER JOIN $wpdb->term_relationships
ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
INNER JOIN $wpdb->terms
ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->terms.term_id
WHERE
$wpdb->posts.post_status = '$cc_post_status' AND post_type = '$cc_post_type'
AND ($wpdb->terms.name = '$s_for' or post_title like '%$s_for%' or post_content like '%$s_for%')
GROUP BY ID {$limit}";
//Search from title,content and category
} elseif ($s_for !== '' && $s_cat !== '' && $s_to == '') {
$query = "SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->term_relationships
ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
WHERE
$wpdb->posts.post_type = '$cc_post_type'
AND
$wpdb->posts.post_status = '$cc_post_status'
AND
($wpdb->posts.post_title LIKE '%$s_for%' OR $wpdb->posts.post_content LIKE '%$s_for%')
AND
($wpdb->term_relationships.term_taxonomy_id = {$s_cat})
GROUP BY ID {$limit}";
//Search from category,zip,address and city
} elseif ($s_for == '' && $s_cat !== '' && $s_to !== '') {
$query = "SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
INNER JOIN $wpdb->term_relationships
ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
WHERE
$wpdb->posts.post_type = '$cc_post_type'
AND $wpdb->posts.post_status = '$cc_post_status'
AND
($wpdb->term_relationships.term_taxonomy_id = {$s_cat})
AND (($wpdb->postmeta.meta_key ='$cc_meta_address' AND $wpdb->postmeta.meta_value LIKE '%$s_to%')
OR ($wpdb->postmeta.meta_key ='$cc_meta_city' AND $wpdb->postmeta.meta_value = '$s_to')
OR ($wpdb->postmeta.meta_key ='$cc_meta_zipcode' AND $wpdb->postmeta.meta_value = '$s_to'))
GROUP BY ID {$limit}";
//Search from category
} elseif ($s_for == '' && $s_cat !== '' && $s_to == '') {
$query = "SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->term_relationships
ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
WHERE
$wpdb->posts.post_type = '$cc_post_type'
AND $wpdb->posts.post_status = '$cc_post_status'
AND
($wpdb->term_relationships.term_taxonomy_id = {$s_cat})
GROUP BY ID {$limit}";
//Search from address,city and zipcode
} elseif ($s_for == '' && $s_cat == '' && $s_to !== '') {
$query = "SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
WHERE
$wpdb->posts.post_type = '$cc_post_type'
AND $wpdb->posts.post_status = '$cc_post_status'
AND (($wpdb->postmeta.meta_key ='$cc_meta_address' AND $wpdb->postmeta.meta_value LIKE '%$s_to%')
OR ($wpdb->postmeta.meta_key ='$cc_meta_city' AND $wpdb->postmeta.meta_value = '$s_to')
OR ($wpdb->postmeta.meta_key ='$cc_meta_zipcode' AND $wpdb->postmeta.meta_value = '$s_to'))
GROUP BY ID {$limit}";
//Search from tags,title,content and zipcode,city,address
} elseif ($s_for !== '' && $s_cat == '' && $s_to !== '') {
// And so on .... until all possible combinations of arguments
Classicraft wordpress theme ... luckily he had only 3 arguments :D
+142
<?php
// cfg.php
class DBcfg {
static $dbopt = array
(
'db_serv' => '',
'db_user' => 'h3ld1k',
'db_pass' => '',
'db_name' => '',
'db_prefix' => 'bp'
);
}
?>
<?php
// core.php
$database = @mysqli_connect("", "", "", "");
if( mysqli_connect_errno() )
{
exit( "Не удалось подключиться к БД! Ошибка: " . mysqli_connect_error() . "" );
}
Ну вот так както =)
+143
<? foreach ($arResult["SIZES"] as $skuId => $size): ?>
<? if ($skuId == $arResult["SKU_ID"]): ?>
<option value="<?= $skuId ?>" selected="selected" data-product-size="<?= $size ?>"><?= $size ?></option>
<? else: ?>
<option value="<?= $skuId ?>"
data-product-url="<?= $arResult["SKU_LIST"][$skuId]["DETAIL_PAGE_URL"] ?>"
data-product-size="<?= $size ?>"
<? if ($skuId == $arResult["SKU_ID"]) echo 'selected="selected"' ?>><?= $size ?></option>
<? endif ?>
<? endforeach; ?>
+144
<?php
$startNumber = 0;
function LittlePart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
echo $BigPart . ' + (' . $i . ') = ' . number_format($number, 2, ',', ' ') . PHP_EOL;
$i++;
} while ($i <= 3);
}
function MidPart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
LittlePart ($BigPart . ' + (' . $i . ')·π', $number);
$i++;
} while ($i <= 3);
}
function QuadradPart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
MidPart ($BigPart . ' + (' . $i . ')·π²', $number);
$i++;
} while ($i <= 3);
}
function CubePart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
QuadradPart ($BigPart . '(' . $i . ')·π³', $number);
$i++;
} while ($i <= 3);
}
CubePart('', 0);
Система счисления по основанию π. Пока с целыми числами.
http://ideone.com/EUYEKA