Quick Question for php progammers

Discussion in 'PHP' started by neiq, May 3, 2010.

  1. #1
    Can data be passed to a database from a url just by putting a ? in the url for example:

    www.yourdomain.com?data

    could the index.php file be done in a mater to know to do an action such as save "data" to a database etc when the above is visited by a user ?
     
    neiq, May 3, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Yes:
    <?php
    if(isset($_GET['date'])){
    //run a mysql query or something...
    }
    ?>
    PHP:
     
    danx10, May 3, 2010 IP
  3. neiq

    neiq Peon

    Messages:
    464
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply and can php be done to save what ever is behind the ? (meaning any characters) Like .,%$ and so on
     
    neiq, May 3, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Place the following in index.php:

    <?php
    //this would give you whats behind the ?
    echo end(explode("?", $_SERVER['REQUEST_URI']));
    
    ?>
    PHP:
    Then with some php knowledge you can use that...let me know if you need more help - would help me by giving a better description as to what you want saved and why.
     
    danx10, May 3, 2010 IP
  5. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #5
    Yes, this is the basis of many SQL injection attacks.
    This page has some examples you can take a look at.
     
    zac439, May 4, 2010 IP
  6. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #6
    you can also use curl functions
     
    bartolay13, May 4, 2010 IP
  7. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #7
    you can also use file_get_content function for that
     
    roopajyothi, May 4, 2010 IP
  8. neiq

    neiq Peon

    Messages:
    464
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    neiq, May 4, 2010 IP
  9. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #9
    You should never run a query from the URL.

    ..what are you trying to do?
     
    zac439, May 4, 2010 IP
  10. neiq

    neiq Peon

    Messages:
    464
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    just tring to allow visitors to add to database via url as oppose to filling form.. so i take it it's not possible ?
     
    neiq, May 4, 2010 IP
  11. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #11
    Maybe something like this?

    <?php
    $input = trim(end(explode("?", $_SERVER['REQUEST_URI'])));
    
    if(!empty($input)){
    $input = strip_tags($input);
    $input = mysql_real_escape_string($input);
    //insert into db..
    mysql_query("INSERT INTO table_name (column_name) VALUES ('{$input}')");
    //added to database...
    }
    ?>
    PHP:
     
    danx10, May 4, 2010 IP
  12. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #12
    Even if you did it from a URL, they are filling out fields. It would be even harder in my opinion for them, as they would need to know SQL syntax, and need to debug their own code.
    There are so many things that can go wrong, I just don't know why you would want visitors to be able to do that..
     
    zac439, May 4, 2010 IP