PHP redirect 301 example code
Example code
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.newsite.com/new-page.php");
header("Connection: close");
exit();
If using file name without .php as part of smoothly url - example:
$fileName = basename(__FILE__, '.php');
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.mysite.cz/auto-moto/".$fileName."/");
header("Connection: close");
exit();
Date: 23.07.2020 - 12:3177LW NO topic_id
AD
Další témata ....(Topics)
List of usefull JavaSript functions and constans
var 1_radian_to_degree = 180 / Math.PI; // 57,295779513082320876798154814105 degree
var 1_degree_to_radian = Math.PI / 180; // 0,01745329251994329576923690768489 radian
var 360_degree = 2 * Math.PI * 1_radian_to_degree;
parseInt("10.33") // returns 10 string to integer
parseFloat("10.33") // returns 10.33 string to float
// change sign
var a = -1;
a = a * -1; // +1
// random sign
a *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
var who_is = 58;
var type = (typeof who_is); // number
Math.E // natural logarithms, e, approximately 2.718281828459045
Math.LN10 // natural logarithm of 10, approximately 2.302585092994046
Math.LN2 // natural logarithm of 2, approximately 0.6931471805599453
Math.PI // approximately 3.141592653589793
Math.SQRT1_2 // square root of 1/2 which is approximately 0.7071067811865476
Math.SQRT2 // square root of 2, approximately 1.4142135623730951
Math.pow(4, 2) = 16 // 4 x 4 ... base 4 to the exponent 2 power
Math.abs(-5) absolute value of a number // return 5
Math.tan(degrees * Math.PI / 180) // get tangent from degrees
Math.tan(degree * Math.PI / 180)*adjacent = opposite
opposite / Math.tan(degree * Math.PI / 180) = adjacent
Math.acos(adjacent / hypotenuse) // angle of a right-angle triangle in radians
Math.atan(opposite / adjacent) // angle of a right-angle triangle in radians
var adjacent = Math.cos(radian) * hypotenuse; // leng of adjacent side
// find the point on a circle if you know the circle´s radius
var x = Math.cos(pointAngleInRadiansFromCentreOfCircle) * radius;
var y = Math.sin(pointAngleInRadiansFromCentreOfCircle) * radius;
Math.cbrt(64) // cube root of a number 4 (4 x 4 x 4)
Math.exp(xNumber) // returns e<sup>xNumber</sup> ... e == Math.E
Math.ceil() // always rounds a number up to the next largest integer
Math.ceil(1.001) // 2
Math.floor() // returns largest integer less than or equal to a given number
Math.floor(5.85) = 5
Math.floor(-5.15) = -6
const arrayA = [2, 3, 1];
Math.min(...arrayA) = 1;
Math.max(1, 3, 2) = 3;
Math.random() // returns 0.000.... - 0.99999999999
Math.random() * 3 // returns 0.000 - 2.99999999999
Math.round() // returns value of a number rounded to the nearest integer.
Math.round(0.9) // 1
Math.round(5.5) // 6
Math.round(5.05) // 5
Math.floor(Math.random() * 3) // returns 0, 1, 2
Date: 14.06.2020 - 08:38Jak získat obsah určité složky příklad v php.
/*************************
* vyhleda soubory s prislusnou koncovkou
* a vrátí nejmladsi soubor
* $extension
*/
function getFileFromDir($path, $extension)
{ // BEGIN function getFileFromDir
$fileReturn; $z = 0;
if (is_dir ($path)) {
$dh = opendir($path); // or die (" Directory Open failed !");
while ($file = readdir($dh)){
//print $file.'<br />';
if (is_file($path.$file)) {
//print $file.'<br />';
$ar = explode(".", $file);
if (count($ar) > 1) {
if (strtolower($ar[count($ar) - 1]) == $extension) { // "zip", "exe" or other extension
$fileReturn[$z][0] = date ("Ymd", filemtime($path.$file));
$fileReturn[$z][1] = $file;
$z++;
//break;
}
}
}
}
closedir ($dh);
}
if ($fileReturn) {
sort($fileReturn);
return $fileReturn[count($fileReturn) - 1][1];
}
} // END function getFileFromDir
/***************************
Textarea selection - získání pozice karety kurzoru.
// FOR Gecko Browser selectionStart / selectionEnd selection length
function getPos(){
if (typeof document.getElementById('idTextarea').selectionStart != 'undefined') {
var nPosCursor = document.getElementById('idTextarea').selectionStart;
var nEndPos = document.getElementById('idTextarea').selectionEnd;
return nPosCursor;
}
return 0; // or -1
}
// source by javascript-array.com/guides/javascript_faq/
//Internet Explorer 4+, Mozilla/Gecko/Firefox
function getCaretPos(obj)
{
obj.focus();
if(obj.selectionStart) return obj.selectionStart; //Gecko
else if (document.selection) //Internet Explorer
{
var sel = document.selection.createRange();
var clone = sel.duplicate();
sel.collapse(true);
clone.moveToElementText(obj);
clone.setEndPoint('EndToEnd', sel);
return clone.text.length;
}
return 0;
}
$country[0] = "cz"
$country[1] = "sk"
$country[2] = "de"
$country[3] = "uk"
$country[4] = "fr"
// this do same
$country[] = "cz"
$country[] = "sk"
$country[] = "de"
$country[] = "uk"
$country[] = "fr"
// or
$country = array('cz','sk','de','uk','fr');
// get array items count
$length = count($country);
for($i=0;$i<$length;$i++){
print $country[$i].'<br>';// cz sk de uk fr
}
// or like this
$country[50] = 'ca';
$country[10] = 'fr';
$country[20] = 'us'
// now country will index 51
$country[] = 'ru';
// or
$country = array('5'=>'cz','sk','de','uk','fr');
/*
Array
(
[5] => cz
[6] => sk
[7] => de
[8] => uk
[9] => fr
)
*/
// you can do this
$country["cz"] = 1571;
$country["sk"] = 1572;
$country["de"] = 1573;
$country["uk"] = 1574;
$country["fr"] = 1575;
print $country["uk"]; // 1574
// print all items key and value
foreach ($country as $key => $value){
print $key; // cz, sk, de, uk, fr
print $value; // 1571, 1572, 1573, 1574, 1575
}
Kontrola zda database existuje, zmena opravneni, vytvoreni nove, nebo jeji otevreni kdyz existuj
$path_to_database = "CESTA_K_SOUBOURU/database.sqlite";
// zmena opravneni / chmod permission
if(file_exists($path_to_database))
chmod($path_to_database,01777);
// otevreni , vytvoreni databaze
$db = new SQLiteDatabase($path_to_database);
vlozeni tabulky s nazvem test, mozno bezpecne vkladat text v UNICODE
$db->query("
CREATE TABLE test
(url VARCHAR(55),
title VARCHAR(55),
keywords VARCHAR(500),
content_of_page VARCHAR(2500),
date DATE(50),
revision DATE(50),
visit INTEGER(8),
PRIMARY KEY (url),
UNIQUE (url))");
// vlozeni dat do tabulky test
$query = $db->query("INSERT INTO test (url,title,keywords,date,c,visit) VALUES (""
.$url."",""
.$title."",""
.$"keywords."",""
.$datum."",""
.$text_of_page."",""
."1"."")", $error);
// update tabulky / radku, prepis jiz existujicich dat
$query = $db->query("UPDATE test SET $query = $dbb->query("UPDATE test SET obsah="".$text_novy
."", title="".$title_new
."", keywords="".$keywords_new
."", revision="".date("j.n.Y - H:i")
."" WHERE url="".$url.""", $error);
}
if (!$query) {
exit("Error in query: "$error"");
} else {
echo "Number of rows modified: ", $dbb->changes();
}
// vyber vsech dat z tabulky test
$resss = $db->unbufferedQuery("SELECT * FROM test");
// prochazeni vysledku vyberu z tabulky
foreach ($resss as $row) { // iterate through result object
print $row["url"];
print $row["title"];
// atd. .... etc. ....
} // end foreach
// presne hledani v tabulce nebo substring / pokud hledame jen substring tak dame % pred pokude ma byt cokoliv vpredu, nebo za pokud vzadu
// pokud jsou procenta vpredu i vzadu, tak najde napriklad predblablavzadu
$resss = $db->unbufferedQuery("SELECT * FROM test WHERE title LIKE %blabla%");
// ziskat setrideny vyber a max pocet vybranych poloze / na konec dotazu pridame:
ORDER BY title DESC LIMIT 50
// setridi podle tituku a vybere 50 radku
// smazani urciteho radku dle obsahu nektereho ze sloupcu
$ur = "www.domena.com/blahblah.php"
$query = $dbb->query("delete from test where url like "$ur"");
Editace: 23.7.2020 - 12:39
Počet článků v kategorii: 77
Url:php-redirect-301-example-code