Out company operate numerous servers
We are using a internal script to filter out various pieces of information , The frontend users will be say entering a postcode , it will then process a list of 5 pages in 1 page of information .
Note: we know our code may not be the most simplistic but it seems to work at the moment , any 1 that knows a easier way to do it then please do say
<?php $postcode = $_POST['postcode']; ?>
// get DOM from URL or file
$html = file_get_html('http://xx.com/en/search/records/search.pub?Surname=willi*&Location=$postcode&x=39&y=9&Page=1');
$html1 = file_get_html('http://xx.com/en/search/records/search.pub?Surname=willi*&Location=$postcode&x=39&y=9&Page=2');
$html2 = file_get_html('http://xx.com/en/search/records/search.pub?Surname=willi*&Location=sa11&x=39&y=9&Page=3');
we have further code which filters out our servers results , but for some reason when one of our users posts the form to this script , only the bottom result is coming back purely because the location is hardcoded - the others are coming back unknown and we think that it isnt passing the postcode variable to the urls correctly
could it be because the $postcode variable is already inside the $html variable , is there a way to get around this issue ?
Thanks
the string beetwen single quotes (') don't get evaluated. try something like
$html = file_get_html('http://xx.com/en/search/records/search.pub?Surname=willi*&Location='.$postcode.'&x=39&y=9&Page=1');
$html1 = file_get_html('http://xx.com/en/search/records/search.pub?Surname=willi*&Location='.$postcode.'&x=39&y=9&Page=2');
and check the $postcode value for valid values before using it in your programs, please
Related
Hoping this is a simple and easy question. I've seen multiple examples of, and know how to append variables to the URL (i.e. mydomain.com/index.php?id=1&stat=0), but my question is this:
If I have a page on my site that already has variables in the URL (i.e. mydomain.com/tickets.php?stat=Open), how can I append a page number to the end of that URL (i.e. mydomain.com/tickets.php?stat=Open&page=2). This is for pagination purposes of a table with values from my database, that includes a search and select function (select open, closed, or all tickets, and search for a specific ticket number).
I've done several searches with google, and came up dry, as most topics regarding this have you hardcode the url with variables from the get go, and not append them. I may just be using the wrong search parameters as well, and am not sure what to search for exactly.
Any help or insight on this would be greatly appreciated, thank you.
Please note I wish to do this solely in PHP, HTML, and MySQLi. I want to refrain from using javascript or ajax if possible for my clients that may have those features disabled on their browsers.
Using this way:--
<?php
$domain = "mydomain.com";
$page = "tickets.php?";
$full_page_url = $domain.'/'.$page;
$arr = array('stat' => 'Open', 'page' =>2);
$add= http_build_query($arr);
$correct_url = $full_page_url. $add;
echo $correct_url;
?>
output:--mydomain.com/tickets.php?stat=Open&page=2
I would do it like this:
$page = 2;
$url = 'mydomain.com/tickets.php?stat=Open';
if( false !== strpos($url, '?')){
//if url has a ? split it.
$arr_url = explode('?', $url);
//convert query string to array, $array=['stat'=>'Open']
parse_str($arr_url[1], $array);
//add or replace page by array key
$array['page'] = $page;
//convert it back to a query string.
$query = http_build_query($array);
print_r($query);
}
Outputs
stat=Open&page=2
It's a simple matter of putting $query back with $arr_url[0] I'll leave this up to you. But I will give you a hint $arr_url[0].'?'.$query
The advantage here is that you don't have to worry about getting into a situation where you are adding page after page after page after...
Like this:
mydomain.com/tickets.php?stat=Open&page=1&page=2&page=3
You can't simply concatenate it onto the end of the url, and it's probably just as hard to remove it as it is to parse the query string.
As a side note, you could just use $_GET but where is the fun in that, as $_GET is the query string already parsed as an array ( so you could skip parse_str). But it may not be on a request, such as if you were just building the link from a string.
So I thought I would show it with parse_str to cover the "harder" case.
One last thing if you are just building a bunch of urls all the same except the page part. The obvious answer is to setup a base url and then just loop out the numbers.
$url = 'mydomain.com/tickets.php?stat=Open';
$pagedUrls = [];
$numberPages = 10;
for($i=1; $i<=$nubmerPages; $i++){
$pagedUrls[] = $url.='&page='.$i;
}
Or what have you for the number of pages.
It's really not that clear in your question exactly what you are trying to do..
Hope that helps.
I am trying to use VBS to gather names of files from a website. I can get the HTML code but I don't know how to extract the name. I haven't yet found anything that can do what I need. I need to extract the name of a file from a table. The HTML around what I need looks like this tsc_details.php?show_id=NEEDED INFO"> There are many different names formatted this same way and the number of names will vary from time to time.
NOTE: There will be multiple of these at various places in the HTML code.
Here is my code
On Error Resume Next
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "WWW.Webpage.com"
ie.Visible = True
While IE.ReadyState <> 4 : WScript.Sleep 100 : Wend
ie.document.getElementById("f_user").Value = "user"
ie.document.getElementById("f_pass").Value = "pass"
ie.document.All.Item("submitb").Click
While IE.ReadyState <> 4 : WScript.Sleep 100 : Wend
This is all of the code I have. It works perfectly for logging in to the page I just don't know how to get the Information I need.
Figured it out and wanted to share my findings in case it helped someone out.
For Each a In IE.Document.GetElementsByTagName("A")
If InStr(a.GetAttribute("href"),"tsc_details.php?show_id=") > 0 Then
var = a.GetAttribute("href")
var = Replace(var,"tsc_details.php?show_id=","")
exit for
end if
next
Used this code
I am making the dynamic website in PHP. While code is running good using pageid.
The url is now like www.google.com/pageid=1
Now, i want to change the url for 1 level pages as www.google.com/page1
for level 2 as www.google.com/page1/page2
for level 3 as www.google.com/page1/page2/page3
While unique address is stored in the my table as page1,page2,page3.
How can it be possible to change url at run time. Please give the examples and comments. So that it may helpful to understand.
Also i want to know if it is possible using the .htaccess file. If possible How .htaccess %{REQUESTED_FILE}% will reach out for my unique url's that are stored in the database.
$URL= "www.google.com/page1"
1) split the string with '/'
$data = explode("/",$URL);
$data[1] will have page1 value
2) replace the string page with ""
$pageId = str_replace("page","", $data[1]);
3) whatever is left is the page id
pageId has the value now.
Use that to query the database.
Another way is to use regex to extract the number from page1 and use it where-ever you want to use it.
I'm trying to use SimplePies "$feed->set_feed_url (array());" function but I am having major difficulty understanding why it wont accept my values.
When I add the URLS manually (i.e directly below), they work just fine. The feeds go through ok and displays the feeds as needed.
$feed ->set_feed_url (array(
'http://www.theverge.com/tag/rss',
'http://feeds.ign.com/ign/all'
));
I have URLS in a database table that I am pulling out like normal with a while loop. I then append a comma and remove the trailing comma so its nice for the SimplePie array. Like so:
while($row = mysqli_fetch_array($pullAllAccountsDoIt)){
$result4mdb .= $row[0] . ",";
}
$result4mdb = substr($result4mdb, 0, strlen($result4mdb) -1);
echo "the result is: " . $result4mdb;
When I do this, and echo out "$result4mdb", it prints out: the result is: http://www.gamespot.com/feeds/mashup/,http://www.theverge.com/tag/rss
Meaning that the variable is good and printing out what i need. So far so good.
I then go into the simplePie code, put in my varialble like so:
$feed ->set_feed_url (array($result4mdb));
and nothing happens. I don't get any errors or anything, just that the page stays blank and nothing comes up.
For testing, I do a gettype($result4mdb); and it tells me that the variable is a "string" and again, the output of this variable when echoed is the URLS it got from the database so I KNOW that the whole process so far is working.
For further testing, I go to the database and remove one of the URLS so that when queried, that it returns one value, and all of the sudden SimplePie works.
I've been searching for a good day and a half now, trying different things and googling as much as possible but to no avail. I just cant quite get it.
I'm at my wits end. Any assistance as to why this isn't working is GREATLY appreciated.
Thank you in advance everyone
You're just producing a string containing comma seperated values. What you need is an array, so just explode() your string:
Change:
$feed ->set_feed_url (array($result4mdb));
to
$feed ->set_feed_url (explode(',', $result4mdb));
More elegant version, change:
while($row = mysqli_fetch_array($pullAllAccountsDoIt)){
$result4mdb .= $row[0] . ",";
}
to
while($row = mysqli_fetch_array($pullAllAccountsDoIt)){
$result4mdb[] = $row[0];
}
This way you're not creating a string that needs to be exploeded, but create an array at first.
I have a POST form in PHP that I'm converting to GET.
The form works and gives me the first page of results without any problems.
But how do I link to the second page? I assume I have to replicate all the GET parameters into the "Next Page" link plus the page number (which the script already handles), but how would I do that?
CLARIFICATION: How do I get all the GET variables from a form onto a link in the page?
simpliest way is too to do something like:
$get = preg_replace("/page=\d+/i", "", $_SERVER['QUERY_STRING']);
$link = "somepage.php?".$get."&page=".($_GET['page']+1);
echo "<a href='".$link."'>Next Page</a>";
That will simply take the get string, remove the page then add the page back in as +1. Please note this would be insecure as people could pass anything in the query string. A better option would be to build the the URL explicitly by checking for each expected $_GET key=>value pair, validating it, then adding it to a link variable. That way any additional bits in the query string wont be echo'd to the page.
EDIT:
Ok so heres a very quick example.
$category = (int)$_GET['cat'];
$keyword = trim($_GET['keyword']);
$keyword = filter_var($keyword, FILTER_SANITIZE_STRING);
$nextlink = "somepage.php?";
$nextlink .= http_build_query(array(
"cat" => $category,
"keyword" => $keyword,
"page" => $page+1
));
So basically you get the GET var's you want, validate them, then just use http_build_query and an associative array to build your query string for the link. The security i put in their is very basic, but typecasting numbers and limiting the amount of crud you can stick into a string is a place to start
Simplistically speaking, you would read them out of the request like this:
$link = 'mypage/?someitem=' . $_GET['someitem'] . '&page=' . ($page + 1);
Although you may not wish to trust the parameters as they may contain an HTML injection or other nasty tricks designed to attack your website.
Isn't it just URL?param1=val1¶m2=val2&...?