Solved

Pass PHP variables to SSRS

Posted on 2010-11-12
9
1,387 Views
Last Modified: 2012-05-10
Is there a way to pass a PHP variable to SSRS? I'm trying to capture the value of $var1 in a PHP page and pass it into a report built in SSRS 2008 as @var1. Anyone know of a way to do this?
0
Comment
Question by:dsurrett2
9 Comments
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 34123829
I am unfamiliar with SSRS but would writing the PHP variable to a hidden input box work?
0
 
LVL 5

Expert Comment

by:wmadrid1
ID: 34124103
0
 
LVL 13

Expert Comment

by:Megan Brooks
ID: 34133438
It depends upon where you are hosting the report viewer. If it is contained within a web application then the app itself determines how you pass a parameter to it. If you simply wish to redirect from a PHP page to Report Manager (RM) or the report viewer that is built in to Report Server (RS) then you can include the report parameter in the RM or RS URL as an URL query parameter (case sensitive). The URL might look something like this for a parameter called "rptParam" with a value of "xxx":

http://<reportserverhost>/Reports/Pages/Report.aspx?ItemPath=/reportpath/reportname&rptParam=xxx

or

http://<reportserverhost>/ReportServer/Pages/ReportViewer.aspx?/reportpath/reportname&rptParam=xxx

You can determine the exact URL by interactively displaying the report using RM or RS.

This is approach is OK within an intranet. You might want to take a different approach out on the Internet.
0
 

Author Comment

by:dsurrett2
ID: 34139047
I probably should have included a bit more info. I'm already using the PHP SDK from the codeplex site. I really would rather NOT have the parameter passed in as part of the URL since the parameter is used for the following purposes in my web application:

1. Restrict access to data on the screen (essentially a group ID)
2. Restrict access to data on a report (again, much like a group ID)

The problem I have is as follows:

I can easily declare and pass the group ID as a variable within PHP and all PHP code will recognize this group ID. However, if I want to use this same group ID in my SSRS report, I need to somehow pass the value of this PHP variable to a similar variable in my report as soon as I launch the report from the PHP page.

So in PHP I declare and populate a variable called $group, which is used to limit the data on the page. The user clicks a button to launch a report (using the PHP SDK) and the report query needs to be filtered by whatever value is stored in PHP as $group. By placing this value in the url, a user could potentially change the group to a different value and accidentally gain access to data intended for a different group. I appreciate all the feedback and hopefully this additional info will help guide those who know more about this than I do.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 13

Accepted Solution

by:
Megan Brooks earned 500 total points
ID: 34141210
I am not familiar with the SSRS SDK for PHP, but from glancing at some of the information about it I have the impression that it can send a request to the SSRS execution web service and return HTML (or other format) via the Render method, for direct output without using the ReportViewer control.

You will need to pass an additional parameter ($group) to the execution web service prior to rendering, one that is not supplied by the web page user interface. It looks like you would use the $rs->SetExecutionParameters2() method.

In my ASP.NET web apps I like to designate certain standard parameter names that are automatically populated when present. For example, if a report contains a hidden parameter called UserID then the web app might populate it automatically with the user's ID as assigned by the web app when rendering that report. The app uses GetExecutionParameters() to check for special parameter names.

As long as the user doesn't have direct access to the reports on the report server (and the web app does), you can prevent a user from substituting a different parameter value. Make sure that the only path the user has to the report is through your web app.
0
 

Author Comment

by:dsurrett2
ID: 34141244
rscowden, that sounds like it might work. I'll give that a try and report back. Thanks much!
0
 

Author Comment

by:dsurrett2
ID: 34801857
Ok, so here is what I did to get this to work...

First, load the report and get the list of parameters from the execution info as follows:

$stdObject = $report->loadReport($Name);
$reportParams = get_object_vars ($stdObject);
$reportParams = $reportParams["executionInfo"]->Parameters->ReportParameter;

Next, a PHP script builds a screen using a function that iterates through the list of report parameters, building an HTML input field element for each report parameter based on its attributes. In the below examples, $$x is a parameter. "Hidden" report parameters, as this one was to be, have the property "$$x->PromptUser" set to true, but have an empty string, "", in the "$$x->Prompt" field (at least as of Report Builder 2.0). Using the "variable variable" syntax in combination with a double-quoted string, the sript is set up to check for potential valid values in the current php scope to put into the report parameter (Other checks preclude any parameters that have "$$x->PromptUser" set to false or have something in "$$x->Prompt").

else if ($$x->Prompt == "") {
  $html .= "value='${${$x}->Name}' ";
}

Once the form has been filled out by the user, the list of report parameters is applied to the current report by creating an array called "$parameters" and calling the "$group->SetExecutionParameters2" function, passing it the array of parameters and the language for the report, like the following lines:

$executionInfo2 = $group->SetExecutionParameters2($reportParameters,"en-us");
$objectVars = get_object_vars ($executionInfo2);

The report is then rendered as HTML.
0
 

Author Closing Comment

by:dsurrett2
ID: 34801868
Solution was very general but did point me in the right direction.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now