Hi. I am a PHP starter and need your help. I have a form that searches a database for a report based on subject's ID number or title. The report resides on a link that has the following form:
How to call that URL in php, so that I get the report for any ID number or title I search? Either the ID number or the title will be empty in the URL based on what the user searches. The user ID and password is the same for all users.
I am not sure if I explained myself well, but I hope I could get some help from here.
I find it very insecure though that passwords can be simply put in the url
01-09-2013, 03:01 PM
TecBrat
I agree with the warning about the password in th URL. If you contol that domain, consider changing that approach.
You can use file_get_contents for a very simple data grab, or you can read up on cURL for a more complex interaction with the requested page.
Is this an API of some kind, or are you scraping from an HTML page?
01-10-2013, 08:06 AM
Atrisa Milani
Thank you both for your answers. I hid the username and password data from the URL.
The report comes from an API and not from HTML page. In my case I guess the file_get_contents function will work fine, though I am still not there:)
01-10-2013, 08:36 AM
Atrisa Milani
When searching with a specific ID number, The URI for the report with that ID gets printed in the window and not the report. This line is responsible for getting the report:
echo getReport(getURI(($rID)));
and then getReport function:
function getReport ($uri) {
$rep = file_get_contents($uri);
return $rep;
}
&uri is the URI in the form I mentioned in the first post and where the report resides. With these I get the report URI in to the frame, but not the report for that specific URI.
01-10-2013, 08:51 AM
Atrisa Milani
I though the problem was because of the iFrames I was using, but that is not it.
01-10-2013, 10:44 AM
Atrisa Milani
Found the reason. Problem was not in the code, rather in our environment.
01-11-2013, 05:43 PM
speghettiCode
Maybe I'm mis-interpreting the original question, but in case anyone else is reading this thread and interprets it the way I did...
mysql_query("SELECT * FROM mytable WHERE id=$id OR myvar='$myvar'");
?>
BE SURE TO CLEAN/VALIDATE YOUR VARIABLES BEFORE USING THEM IN A SQL QUERY TO AVOID INJECTION.
01-18-2013, 07:14 AM
Atrisa Milani
Thanks speghettiCode. I now get the report out.
One question yet: the report is using Scandivian characters such as Å and Ä. The report looks fine on the URL in the browser, but when I get the same report with my PHP code, those special characters are not recognized and the report looks funny. Is there a way I could define the character set in my code so that the report shows correctly?
Also the styles and pictures in the report are missing.
Thanks
01-18-2013, 09:57 AM
speghettiCode
Those characters are part of a UTF-8 character set. To set the default character set via PHP, include the following line at the top of your page:
PHP Code:
ini_set('default_charset','UTF-8');
Also, it may be redundant, but I also include the following HTML at the top of my pages:
If your database query is not pulling the information you would expect, there are several factors:
1. table structure
2. how the variables are encoded in the table
3. how the variables are encoded in the query
If you are using the code I suggested, then Å will be changed to Å when stored in the variable (or, perhaps displayed in the report depending on how you have it set up). To reduce the risk of SQL injection it's important to use htmlentities() or something similar when using the variables in a query. However, if you need these characters displayed on the screen, you could use:
Thanks for the reply. I have that meta tag in the first page; also tried ini_set('default_charset','UTF-8'); but still the same problem. My code looks like this:
This did the trick: $data = utf8_encode($data); Looked like the data was in ISO-8859-1 and had to convert it to UTF-8. Thanks for your help so far.
01-24-2013, 04:58 AM
havet
PHP is server side scripting language. It is use for designing web page. PHP may be deployed on most internet servers and additionally as a standalone shell on nearly each operating system.