0

I'm working on a easier way of an existing page of mine and got a little problem. I've tried to use $_GET to make it smaller, yet I get a lot of problems with this method.

Here's what I got:

$oc_a = file_get_contents('./'.$_GET.'/oc_info.html', true);

This is currently above this:

if ($_GET['pony'] == 'darkheart') die($header."<br><br>".$oc_a."<br>".$oc_b."<br>
        <table style='width=80%;'>
            <tr>
                <td>
                    ".$oc_c."
                </td>
            </tr>
        </table>
        ");

And this is the error:

Notice: Array to string conversion in /home/rikuu/htdocs/twitter/index.php on line 12 Warning: file_get_contents(./Array/oc_info.html): failed to open stream: No such file or directory in /home/rikuu/htdocs/twitter/index.php on line 12

Can anyone tell me what I've done wrong so far?

2
  • 2
    $_GET is an associative array of key value pairs, so this is almost certainly not what you want. What are you wanting to get out of using $_GET? I would guess you are trying to do something like './'.$_GET['pony'].'/oc_info.html' but please don't do this without ensuring your document root is locked down to prevent something like ?pony=../../../../etc/passwd Commented Jul 22, 2014 at 2:42
  • Well I'm trying to get the word after "pony=", in this case it's "darkheart" Commented Jul 22, 2014 at 2:44

1 Answer 1

2

You're getting that error because $_GET is an array. For example, for the url https://example.com/subdir?pony=cheerilee&apple=company, this:

echo($_GET['pony']);
echo("<br>");
echo($_GET['apple']);

Will return:

cheerilee
company

So if your url was https://example.com/subdir?pony=darkheart, your code would look like this:

$ocA=file_get_contents('./'.$_GET['pony'].'/os_info.html',true);
if($_GET['pony']==='dearkheart') ...

Edit: as sberry pointed out, you should definitely make sure to lock down the directory. You could just check to make sure $_GET['pony'] doesn't contain .. or /

If you want to look at the variables you get with $_GET, run var_dump($_GET); which will return something that looks like:

array(2) { ["pony"]=> string(4) "dearkheart" } 

This tells you all the array values in $_GET

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.