Results 1 to 7 of 7

Thread: PHP injection

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default PHP injection

    Does anyone know how I would go about injecting php into a php page each time an image is clicked dynamically? I want to write this code into the page:
    Code:
    <tr><td><?php $vidcount = $vidcount + 1; echo $vidcount; ?></td><td><input type="text" name="timecode<?php echo $vidcount; ?>" /></td><td><input type="text" name="videocomment<?php echo $vidcount; ?>" /></td><td><input type="text" name="videosuggestion<?php echo $vidcount; ?>" /></td></tr>
    I also need the php to run through again. Is this possible? Thanks for any ideas you have on this.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You could have the PHP and HTML code (or something like it - importing table fragments to a live page is not always the best approach) from your post on an external page with the .php extension. Each time your image is clicked, that page could be fetched via AJAX into an appropriate spot on your page with a query string that increments the var, which itself may have to be at a higher level than either page, like maybe at the session level.
    Last edited by jscheuer1; 04-28-2009 at 11:59 AM. Reason: sense
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Is there a tutorial or something that explains how to do this more detailed with coding examples?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Not that I'm aware of. That doesn't mean there isn't one. The AJAX importation is pretty straightforward though. There are a number of routines available, and at least some of the popular javascript libraries have AJAX 'units' and/or syntax. I'm a bit partial to my own routine:

    http://www.dynamicdrive.com/forums/s...3&postcount=23

    which would need some modification for this. The jQuery AJAX stuff I've seen looks pretty versatile.

    This question was originally in the javascript forum, one of the other mods or ddadmin moved it here to PHP.

    AJAX is essentially javascript using a server request object, so what I'm proposing would be javascript to import data. The trick would be to import a PHP page that the server could interpret properly, and then also to make (on the javascript side) an appropriate use of the imported data.

    How familiar are you with AJAX importation?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Not familiar at all well with writing it. I know what it is, ?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, how about PHP? I think you will need a session variable for this, regardless, and I'm not very familiar with that. As for the AJAX side, using my code that I linked to, you could:

    Code:
    new loadXmlHttp('somepage.php', 'target_element_id')
    on somepage.php, you could increment the session var $vidcount, and have your code (slightly changed because $vidcount should be session and already updated at the beginning of somepage.php, and because getting the tr will be a problem, we will need to make one, we should be able to get the td's though - but even that may mess up, as it will be an invalid HTML code fragment, let's keep our fingers crossed):

    Code:
    <td><?php  echo $vidcount; ?></td><td><input type="text" name="timecode<?php echo $vidcount; ?>" /></td><td><input type="text" name="videocomment<?php echo $vidcount; ?>" /></td><td><input type="text" name="videosuggestion<?php echo $vidcount; ?>" /></td>
    If there's a problem with that we can just import the now updated value of $vidcount and build the entire row from scratch, but let's not worry about that right yet.

    Now, appending to an existing table is tricky. Make sure your table has a tbody element, and give it a unique id, pass that id as the target_element_id in my above loadXmlHttp function.

    Then in the loadXmlHttp.prototype.stateChanged function from my code, you could:

    Code:
    loadXmlHttp.prototype.stateChanged = function(){
     if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !loadXmlHttp.re)){
      var r = document.createElement('tr'); //creates a tr
      r.innerHTML = this.xmlHttp.responseText; //fills it with the td's from the import
      this.el.appendChild(r); //appends the new tr to the tbody whose id was passed to the main function
     }
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That's a very weird approach to a problem that can probably be dealt with another way.

    PHP should not be injected-- that's a security risk.

    You could PERFORM a task using AJAX to run an EXISTING serverside PHP page, but updating PHP dynamically is incredibly risky if you allow any sort of user interaction.

    What John is saying can still be applied, but you should use it in the context of an existing PHP script, not "creating" PHP as you go.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •