I'm just learning to code and I don't know my way around yet. I already know how to redirect to another page with php. for example you go to http://example.com/test.php/ then you are redirected to http://example.com/test.txt with the following code:
"header('Location: http://example.com/test.txt);"
But now I'm not sure how to show the content of different files on your domain if the requested url has ?data=1 or ?seid=2 after the php. For example:
"http://example.com/test.php?data=request1" shows the text from "http://example.com/test1.txt"
"http://example.com/test.php?data=request2" shows the text from "http://example.com/test2.txt"
Have informed me so far that I have found something with $DataArray but don't know exactly how to use it? I tried something with it:
<?php
$DataArray = array(
"request1" => "test1",
"request2" => "test2"
if(isset($_GET['data'])) {
$data = str_replace(" ", "+", $_GET["data"]);
if(array_key_exists($data, $DataArray))
echo trim(json_decode(file_get_contents('data/'. $DataArray[$data] .'.txt'),JSON_UNESCAPED_SLASHES), '"');
else
echo "badrequest";
}
?>
Sadly that doesn't work for me so I don't know how to manage that.
Aucun commentaire:
Enregistrer un commentaire