What's wrong with this code? SimpleXMLElement [closed] - simplexml

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
$fn = $Cache_Path . '/n' . $Node . '.xml';
$store = file_get_contents( $fn );
SimpleXMLElement;
$xml = new ( $store );
$link = '';
Error:
Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '$' in.....

You probably mean:
$fn = $Cache_Path . '/n' . $Node . '.xml';
$store = file_get_contents( $fn );
$xml = new SimpleXMLElement ( $store );
$link = '';

Related

Lumen: Auto increment and Reset Transaction_ID Automatically every month

I trying to generate random transaction_id, with format "2000-yymmm-0000".
I already know how to set the transaction_id, but I have a problem with the auto-increment from "2000-yymm-0000" to "2000-yymm-0001", and reseting automatically to "2000-yymm-0000" at every new month.
I put this logic in different path of controller.
PS: I'm using Lumen 6.0 with Laravel 6.0.
I'm trying to create the increment with:
$number = sprintf('%04d', 0000);
$number++;
but it didn't work.
$year = 2000;
$time = date('ym');
$number = sprintf('%04d', 0000);
$transaction_id = $year . '-' . $time . '-' . $number;
$transaction_data = explode('-', $transaction_id);
$month = date("m", strtotime($transaction_data[0]));
I expect the result to automatically increment every time a new data is stored to the database. But the actual result is transaction_id being having always the same value 2000-yymm-0000.
What am I doing wrong?
I know it's weird to answer my own question, but i already find the solution.
in Models/Order.php
i create a function like this.
public function count()
{
$this->where(transaction_id)->count();
}
after that i call the function from Model/Order.php to OrdersController.php
public function create(Request $request)
{
$year = 2000;
$date = date('ym');
$total_data = $this->table->count();
$number = str_pad($total_data + 1, 4, 0, STR_PAD_LEFT);
$transaction_id = $year . '-' . $date . '-' . $number;
return $this->success('count all transaction id', $t_id);
}

How to fix this syntax error, please help me [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
when i run file its appear with error
Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/beddings/public_html/mybabystore.com.au/admin/categories.php on line 2364
here is my code
$contents[] = array(
'align' => 'center',
'text' => '<br><a href="' .
tep_href_link(
FILENAME_CATEGORIES,
'&cPath='. $cPath.'&cID='.$cID.'&checkall=1')
. '" onClick="setCheckboxes('mainForm', true); return false;">[Check All Products]</a> <a href="'
. tep_href_link(FILENAME_CATEGORIES, '&cPath='. $cPath.'&cID='.$cID)
. '" onClick="setCheckboxes('mainForm', true); return false;">[Un Check All]</a>'
);
The error is here, you need to escape your single quotes
setCheckboxes(\'mainForm\', true);
^----------^
//You are using this twice so escape the other one too
Try this You need to escape the single quotes
$contents[] = array('align' => 'center', 'text' => '<br>[Check All Products] [Un Check All]');
Try this one :
$contents[] = array('align' => 'center', 'text' => '<br>[Check All Products] [Un Check All]');

AES. Encrypt array of bytes in powershell [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.
I am need to encrypt array of bytes([byte[]]) in powershell script using AES cryptography method. I am find function that encode string:
[Reflection.Assembly]::LoadWithPartialName("System.Security")
function Encrypt-String($String, $Passphrase, $salt="My Voice is my P455W0RD!", $init="Yet another key", [switch]$arrayOutput)
{
$r = new-Object System.Security.Cryptography.RijndaelManaged
$pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)
$salt = [Text.Encoding]::UTF8.GetBytes($salt)
$r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32) #256/8
$r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
$c = $r.CreateEncryptor()
$ms = new-Object IO.MemoryStream
$cs = new-Object Security.Cryptography.CryptoStream $ms,$c,"Write"
$sw = new-Object IO.StreamWriter $cs
$sw.Write($String)
$sw.Close()
$cs.Close()
$ms.Close()
$r.Clear()
[byte[]]$result = $ms.ToArray()
if($arrayOutput) {
return $result
} else {
return [Convert]::ToBase64String($result)
}
}
Read code with comments at http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Script-410ef9df
Help change the function so that it encode array of bytes and not a string
Ssory for my english. Hello from Russia :)
I am do that i am need. New code:
[Reflection.Assembly]::LoadWithPartialName("System.Security")
$String=$buff #ARRAY OF BYTES TO ENCODE
$Passphrase="Pas"
$salt="My Voice is my P455W0RD!"
$init="Yet another key"
$r = new-Object System.Security.Cryptography.AesManaged
$pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)
$salt = [Text.Encoding]::UTF8.GetBytes($salt)
$r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32) #256/8
$r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
$r.Padding="Zeros"
$c = $r.CreateEncryptor()
$ms = new-Object IO.MemoryStream
$cs = new-Object Security.Cryptography.CryptoStream $ms,$c,"Write"
$cs.Write($String, 0,$String.Length)
$cs.Close()
$ms.Close()
$r.Clear()
[byte[]]$Encrypted = $ms.ToArray()

preg_match issue: Delimiter must not be alphanumeric or backslash

I know this issue has been discussed in different questions but the answers people have given don't seem to work on my end. I'm dealing with the following problem:
if ( (preg_match($suspect, $lowmsg) )
|| (preg_match($suspect, strtolower($_POST['name'])))
|| (preg_match($suspect, strtolower($_POST['email']))))
Now, people have been saying that if I put "/" in front and behind quotes like so '/email/' that this would solve the problem. I tried putting the / for email and name but it still brought me back to the same delimiter error.
I also get a final error of: Warning: Cannot modify header information - headers already sent by (my website's send.php:43) on line 61. Does this have anything to do with it or is this just an error as a result of the earlier error?
Here's the entire code for interested parties:
<?php
if(($_POST['email']=="")||($_POST['name']=="")||($_POST['message']==""))
{
echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
if($_POST['name'] == ""){ echo "<li>Name</li>"; }
if($_POST['email'] == ""){ echo "<li>Email</li>"; }
if($_POST['message'] == ""){ echo "<li>Message</li>"; }
echo "</ul><p>Please use your browser's back button to complete the form.</p></body></html>";
}
else
{
$message = "";
$message .= "Name: " . htmlspecialchars($_POST['name'], ENT_QUOTES) . "<br>\n";
$message .= "Email: " . htmlspecialchars($_POST['email'], ENT_QUOTES) . "<br>\n";
$message .= "Message: " . htmlspecialchars($_POST['message'], ENT_QUOTES) . "<br>\n";
$subject = htmlspecialchars($_POST['subject'], ENT_QUOTES);
$pagelink = htmlspecialchars($_POST['pagelink'], ENT_QUOTES);
$repemail = htmlspecialchars($_POST['repemail'], ENT_QUOTES);
$injection_strings = array ( "content-type:","charset=","mime-version:","multipart/mixed","bcc:","cc:");
foreach($injection_strings as $suspect)
{
if((preg_match($suspect, $lowmsg)) || (preg_match($suspect, strtolower($_POST['/name/']))) || (preg_match($suspect, strtolower($_POST['/email/']))))
{
die ( 'Illegal Input. Go back and try again. Your message has not been sent.' );
}
}
$headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: \"" . $_POST['/name/'] . "\" <" . $_POST['/email/'] . ">\r\n";
$headers .= "Reply-To: " . $_POST['/email/'] . "\r\n\r\n";
mail($repemail, $subject, $message, $headers);
header("Location: " . $pagelink . "");
}
?>
You can try other delimiters, such as / # ~
see regexp.reference.delimiters
Hope that helps.
EDIT: you do not need to do backslash inside $_POST
Use $_POST['name'] instead of $_POST['/name/']
EDIT: try
preg_match("/".$suspect."/i", strtolower($_POST['name']);
However, I dont think you would find any of your $injection_strings inside post name. You may need to rethink how you are searching. "content_type" is not going to match "text/html" with your current statement. You'd need to try other regex like
preg_match("/".$suspect."(.*)/i", strtolower($_POST['name'], $output);
So that it would $output[0], your "suspect" variable. I'm not sure if thats what you are looking for, but maybe sending you to the right track.
EDIT: Here.
If you want to look at say "cc:" and find what email it is, use this.
preg_match("/cc:(.*)/i",'cc:'.$_POST['email'],$output);
$output[0]; would equal your email.
To be compatible with your foreach loop, you may want to change it too,
switch this below code within your "if statements"
preg_match("/".$suspect."(.*)/i",$suspect.$_POST['email'])

Decryption code from the image [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I have two images: the one and the two.
How do I decode it?
This should get you started in the right direction, its un-tested and may contain syntax errors but should work.
<?PHP
$out = imagecreatetruecolor(400,400);
$in = imagecreatefrompng('questionq.png');
$dest_x = 0;
$dest_y = 0;
$dest_dir = 0;
function setImagePixel($color) {
global $out, $dest_x; $dest_y, $dest_dir;
imagesetpixel($out, $dest_x, $dest_y, $color);
if ($dest_dir == 0) {
if (++$dest_x == 399) {
++dest_y;
$dest_dir = 1;
}
} else {
if (--$dest_x == 0) {
++dest_y;
$dest_dir = 0;
}
}
}
for($count = 400; $count > 0; --$count) {
$offset = 400 - $count;
for($x = $offset; $x < $count ; ++$x) setImagePixel(imagecolorat($in, $x , $offset));
for($y = $offset; $y < $count ; ++$y) setImagePixel(imagecolorat($in, $count , $y ));
for($x = $count; $x > $offset ; --$x) setImagePixel(imagecolorat($in, $x , $count ));
for($y = $count; $y > $offset + 1; --$y) setImagePixel(imagecolorat($in, $offset, $y ));
}
imagepng($out, 'decoded.png');
?>
The correct answer to this puzzle will lead you to a Google Spreadsheet document. Which one that is is the next puzzle.
A little weird is that the decoded image is not easily readable, you first have to apply a "remove each second line" filter on it. Fortunately GIMP comes with such a filter built-in.

Resources