Passing a url parameter into readfile()

My PHP background is VERY small. I have only used a few very simple functions - ever. That said, I am using the following php as a file I link to. When run, it forces download of a certain page (the page never actually opens in the browser, just downloads) into a word doc. It is working perfectly - except that I need to use a parameter in the readfile() url to filter the resulting file, but the readfile() seems to be ignoring the parameter.

Any suggestions on how I can get the parameter to work? The link to the php file is:

<?php header("Content-type: application/vnd.ms-word"); header("Content-disposition: attachment; Filename=letter_1.doc"); readfile("http://scriptcasemanagement.com/firm-login/letters-forms/ltr-ssa-1696[b]?casenum=$passid[/b]"); ?>

And sorry - my site is password protected containing secure info, so you really can’t go check it out or anything.

I would change the link to:
[php][/php]

[] denotes adding to an array, say if you have 20 checkboxes you could do color[] in order to get them all in the same value array.

On the server side you have to get the variable, it is not magically available
[php]<?php
header(“Content-type: application/vnd.ms-word”);
header(“Content-disposition: attachment; Filename=letter_1.doc”);

if (!empty($_GET[‘id’]) && is_numeric($_GET[‘id’]) {
readfile(“http://scriptcasemanagement.com/firm-login/letters-forms/ltr-ssa-1696?casenum=” . $_GET[‘id’]);
}[/php]

$_GET, $_POST, $_SERVER, $_COOKIE etc are global variables generated by php automagically. You should check them out :slight_smile:

Thanks so much JimL - glad I didn’t keep trying to piddle pointlessly with that.

Couple of things, though. So throughout my site, which links a lot of forms and displays together using a common case number, I usually add the parameter “?casenum=[id]” to pull the id of the form entry I am already on and which I want to pass along. Then I use a shortcode [get param=casenum] on the next page to grab it and filter my display. I guess the underlying problem here is that since I have a php function in the middle of this exchange, my link to the page to print is now in a php file, which does not read my “[id]” the same way. So somehow, I need to draw [id] as an actual number into my php function and then put that number on the end of my readfile() url.

$passid should probably be thrown away - I made it up badly for this - it is undefined entirely and only existed in the two places I posted.

I think that might change some nuances in the code you gave me. I saw that I hadn’t explained that clearly, and indeed, when I gave your code a go, I just got a new page with ?id=<?= $passid ?> printed as the end of the url.

Any chance you can clear up my muddling?

Add the code you are working with and we’ll take it from there :slight_smile:

Link to php file:

Letter to SSA 1696

PHP file:

<?php header("Content-type: application/vnd.ms-word"); header("Content-disposition: attachment; Filename=letter_1.doc"); readfile("http://scriptcasemanagement.com/firm-login/letters-forms/hbrteyiu92i3jnnhbdo12894euychj9wiounek/[b]?casenum=[id][/b]"); ?>

JimL suggested code:

Link to php:

php:

<?php header("Content-type: application/vnd.ms-word"); header("Content-disposition: attachment; Filename=letter_1.doc"); if (!empty($_GET['id']) && is_numeric($_GET['id']) { readfile("http://scriptcasemanagement.com/firm-login/letters-forms/ltr-ssa-1696?casenum=" . $_GET['id']); } $_GET, $_POST, $_SERVER, $_COOKIE etc are global variables generated by php automagically. You should check them out :)
Sponsor our Newsletter | Privacy Policy | Terms of Service