1

Ok so yesterday I was working on a PHP API all day (2:30PM - 3:30AM CT). The user/client/front end of the API can submit a filename or link to the API so it can view it, edit it, or delete it.

But that's a problem because if the user can do that that means they could edit or delete the website with the client.

So I'm wondering can I store a bunch of variables that are equal to links, so when the client submits, the API will see if that link is unauthorized or authorized

Could you do it like this

<?php
$myArray = array( //Unauthorized Links 
    $link1 => "http://example.com" //First Link
);
?>

Then check the links using $myArray?

If you need the API code I'll provide it.

2
  • Use quotes in string values in array Commented Jul 23, 2016 at 18:04
  • @Rishi Ok sorry bout that got in a rush, but problem still persists. Commented Jul 23, 2016 at 18:07

1 Answer 1

1

use this code and it will work for you

<?php
    $myArray = array(
        1 => 'http://example-1.com',
        2 => 'http://example-2.com',
        3 => 'http://example-3.com',
        4 => 'http://example-4.com'
    );

    foreach($myArray as $key => $value){
        echo 'link '.$key.' = '.$value.' <br>';
    }
?>
Sign up to request clarification or add additional context in comments.

5 Comments

Notice: Undefined variable: link1 in on line 1 Notice: Undefined variable: link2 in on line 1 Notice: Undefined variable: link3 in on line 1 Notice: Undefined variable: link4 in on line 1 Notice: Undefined variable: linkn in on line 1 link = example-1.com link = example-2.com link = example-3.com link = example-4.com link = example-n.com
@abrad1212; sorry it's my fault, test it now
Thanks the links are being displayed! Now I'm going to integrate this with my API I'll DM you if I can't get it working. :)
Ok so would doing something like this work? } elseif (isset($_POST['filename']) and $_POST['filename'] == $Links) { die("Sorry you may not access that link"); } Because I'm trying it and right now it's not working
Ok I think I isolated my problem from the previous comment, my problem is that foreach has the $value and I'm needing to use that throughout the whole script! Should I just put it on top of the script and close it at the bottom? So i can use $value throughout the whole script.

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.