• I try to pass a parameter to a php script of my own. I created a page called “myscript.php” and used the plugin Insert PHP to do some basic things. Now I want to do things depending on a parameter par1 and try the usual syntax
    <a href="myscript.php?par1=something">
    with $_GET["par1"] within the script
    No success. I also tried to name the page just “myscript”, without suffix; didn’t help.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • So what is the issue? am guessing that WordPress is not recognising myscript.php? is that what you mean by no success?

    Thread Starter veselyf2

    (@veselyf2)

    That is not the main issue. I assume (based on trial) that the suffix .php is not recognized under wordpress, so I named the sandbox script just “myscript”. It looks like this:

    [insert_php]
    echo ‘Server date and time is: ‘;
    echo date(‘l, F j, Y \a\t G:i:s’);
    echo ‘<br> </br>’;
    echo ‘Hallo ‘ . $_GET[“name”] . ‘!’;
    [/insert_php]

    If I call it as …/myscript it does give the date and says Hallo; if I say …/myscript?name=anna
    it produces a 404 error.

    I’m not understanding the relationship between myscript.php and the insert_php shortcode. Where is your example code? Where is the shortcode being used?

    Moderator bcworkz

    (@bcworkz)

    There are more issues in this regard than you realize. First of all, you shouldn’t directly request custom PHP files in WP. There is no reliable way to invoke the WP environment when you do this. If you are utilizing shortcodes to cause your custom code to execute, there is no reason for a separate file. Put the shortcode in a post and make the request using the post’s permalink. You may add URL parameters like you would any other URL.

    Besides using shortcodes, there are 4 other valid ways in WP to cause custom code to execute. 1) hook a filter or action. 2) Use Ajax. 3) Make a custom page template. 4) send your request through wp-admin/admin-post.php.

    Don’t bother with Insert PHP plugin. If you can write PHP within the shortcode, you can just as easily create your own shortcode without the plugin. There is also some added security risk in using Insert PHP and similar plugins. The way the plugin works might also be why you are having trouble with getting URL parameters, but I cannot be sure about this.

    The main thing to remember in making your own shortcode is the handler function must never generate output by using echo, fprint, etc. Instead, accumulate output into a variable that your handler function returns. WP will then echo out the returned string at the appropriate location in the post.

    Thread Starter veselyf2

    (@veselyf2)

    Thank you for your extensive response. I will follow up your suggestions and warnings.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘pass data using insert php’ is closed to new replies.