-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp-unserialize.html
More file actions
267 lines (238 loc) · 7.97 KB
/
php-unserialize.html
File metadata and controls
267 lines (238 loc) · 7.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
73
74
75
76
77
78
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Unserializer Playground</title>
<meta name="description" content="Local PHP unserializer tool to safely convert PHP serialized strings to human-readable format. Run PHP unserialize() locally in your browser.">
<meta name="keywords" content="PHP, unserialize, serialization, local tool, PHP playground, web development">
<meta name="robots" content="index, follow">
<meta name="author" content="Utkarsh Patel">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="PHP Unserializer Playground">
<meta property="og:description" content="Local PHP unserializer tool to safely convert PHP serialized strings to human-readable format">
<meta property="og:type" content="website">
<link rel="canonical" href="php-unserializer.html">
<style>
:root {
--primary: #465D91;
--surface-tint: #465D91;
--on-primary: #FFFFFF;
--primary-container: #D9E2FF;
--on-primary-container: #001944;
--surface: #FAF8FF;
--on-surface: #1A1B20;
--surface-variant: #E1E2EC;
--outline: #757780;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
margin: 0;
padding: 20px;
background: var(--surface);
color: var(--on-surface);
font-family: 'Roboto', sans-serif;
min-height: 100vh;
}
.playground-container {
max-width: 1200px;
margin: 0 auto;
border: 1px solid var(--outline);
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
height: calc(100vh - 40px); /* Account for body padding */
}
.toolbar {
display: flex;
gap: 16px;
padding: 16px;
background: var(--surface-variant);
border-bottom: 1px solid var(--outline);
align-items: center;
flex: 0 0 auto;
}
button {
background: var(--primary);
color: var(--on-primary);
border: none;
cursor: pointer;
transition: opacity 0.2s;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 16px;
border-radius: 4px;
font-size: 14px;
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
button:hover:not(:disabled) {
opacity: 0.9;
}
.editor-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
padding: 20px;
flex: 1;
min-height: 0; /* Important for preventing overflow */
overflow: hidden;
}
textarea {
width: 100%;
height: 100%;
padding: 16px;
border: 1px solid var(--outline);
border-radius: 4px;
background: var(--surface);
color: var(--on-surface);
font-family: 'Roboto Mono', monospace;
resize: none;
font-size: 14px;
overflow-y: auto;
}
#output {
width: 100%;
height: 100%;
padding: 16px;
border: 1px solid var(--outline);
border-radius: 4px;
background: var(--surface);
white-space: pre-wrap;
overflow-y: auto;
font-family: 'Roboto Mono', monospace;
font-size: 14px;
}
.error {
color: #BA1A1A;
background: #FFDAD6;
padding: 8px;
border-radius: 4px;
margin-top: 8px;
}
.status {
margin-left: auto;
font-size: 14px;
color: var(--outline);
}
.title {
font-size: 16px;
font-weight: 500;
color: var(--on-surface);
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&family=Roboto+Mono&display=swap" rel="stylesheet">
</head>
<body>
<div class="playground-container">
<div class="toolbar">
<span class="title">PHP Unserializer in Browser using WebAssembly</span>
<button id="runButton" disabled>
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
<path d="M8 5v14l11-7z"/>
</svg>
Unserialize
</button>
<span id="status" class="status">Initializing PHP...</span>
</div>
<div class="editor-container">
<textarea id="code" spellcheck="false" placeholder="Enter PHP serialized string here...">a:2:{i:0;s:5:"Hello";i:1;s:5:"World";}</textarea>
<div id="output"></div>
</div>
</div>
<script type="module">
let php;
const output = document.getElementById('output');
const runButton = document.getElementById('runButton');
const status = document.getElementById('status');
let outputBuffer = '';
let phpVersion = '';
let isGettingVersion = false;
function updateOutput(text, isError = false) {
if (isError) {
output.innerHTML += `<div class="error">${text}</div>`;
} else {
output.textContent = text;
}
}
function clearOutput() {
output.textContent = '';
outputBuffer = '';
}
async function getPhpVersion() {
let versionOutput = '';
isGettingVersion = true;
try {
await php.run('<?php echo PHP_VERSION;?>');
isGettingVersion = false;
return phpVersion;
} catch (e) {
console.error('Error getting PHP version:', e);
isGettingVersion = false;
return '8.3.0';
}
}
async function initPHP() {
try {
const { PhpWeb } = await import('https://cdn.jsdelivr.net/npm/php-wasm@0.0.9-alpha-27/PhpWeb.mjs');
php = new PhpWeb();
// Main output handler
php.addEventListener('output', (event) => {
if (isGettingVersion) {
phpVersion = event.detail.trim();
} else {
outputBuffer += event.detail;
updateOutput(outputBuffer);
}
});
php.addEventListener('error', (event) => {
updateOutput(event.detail, true);
});
await php.ready;
// Get and store PHP version after initialization
await getPhpVersion();
status.textContent = `PHP ${phpVersion} Ready`;
runButton.disabled = false;
clearOutput();
} catch (e) {
status.textContent = 'Failed to initialize PHP';
updateOutput(`Failed to initialize PHP: ${e.message}`, true);
console.error('Failed to initialize PHP:', e);
}
}
async function unserializeData() {
if (!php) return;
try {
runButton.disabled = true;
status.textContent = 'Processing...';
clearOutput();
const serializedData = document.getElementById('code').value;
const code = `<?php
try {
$data = unserialize('${serializedData.replace(/'/g, "\\'")}');
var_export($data);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>`;
await php.run(code);
} catch (e) {
updateOutput(e.message, true);
} finally {
runButton.disabled = false;
status.textContent = `PHP ${phpVersion} Ready`;
}
}
runButton.addEventListener('click', unserializeData);
initPHP();
</script>
</body>
</html>