How to avoid the use of (php?id=idNumber) using php [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I need to know a better way of retrieving data from the db. In the page I am developing when I click on check product button for example, the id of that specific product is passed to the product page such as http://domainname.com/products.php?id=1.
Apparently this is a bad way to retrieve data. How can I pass this id value to the products page without using ?id=1.
Thanks

Apparently this is a bad way to retrieve data
It is totally untrue. Using $_POST instead of $_GET in this case make the page for specific product inaccessible by pure URL. What if I want to share a link of product with id 2321 to my friend in facebook?
Take a look as this website for example londonperfumeshop.co.uk/diesel-zero-plus-men. The product I guess is retrieved from the database but there is no id passed through the domain. How is that done in php? – user2257461
This is called URL Rewrite. Basically, it is not PHP feature. It is a web server feature. The concept behind URL rewrite is to map a pattern of URL into another pattern of URL. For example. I want to map
products/(.*) -> products.php?alias=$1
If someone try to access the following link:
products/url-rewrite-for-dummy
products/head-first-web-mobile
It will map to the following link:
products.php?alias=url-rewrite-for-dummy
products.php?alias=head-first-web-mobile
So basically, it's still a $_GET. While using alias make your URL looks prettier and friendlier, there is a small problem. Alias can be changed. Lets say you want to rename your product, so the alias should be also changed. It causes the old link to be invalid. To overcome this problem, you can combine alias with id.
products/([0-9]+)-(.*) -> products.php?id=$1
If someone try to access the following link:
products/1-url-rewrite-for-dummy
products/2-head-first-web-mobile
It will map to the following link:
products.php?id=1
products.php?id=2
Using ID with alias improve the speed of query; and ID of a product will always still the same (it would be unusual for product ID to be changed)

Related

how to get the wordpress posts into another wordpress site on different server [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have two sites with different server. I need to get post of one site to another wordpress site. I have database and cpanel of both server. I guess i can do using rss feed or fetching the database directly. I need to get all the post content including images and all. so i think rss feed will not be the better solution.
Please suggest me the better solution. Thank you
use WP API
e.g.
$posts = json_decode(file_get_contents('http://example.com/wp-json/wp/v2/posts?filter[posts_per_page]=20&filter[orderby]=date'));
foreach ( $posts as $post ) {
echo ''.$post->title->rendered.'';
}
It depends on the approach you want to use as this question is primarily opinion-based.
Although,
One and good approach is to have a single database for both the server. As mentioned in your question, images and other media will get shared too.
So On the second server you can connect to the main database of the first server and then whenever you show the media like images, show it from the first server (By using URL of first server). For this you might need to update the codes of the second server.
The better approach is master and slave concept.
Make a plugin for your WordPress site and listen to new posts by filters. whenever a new post comes in , write it to another WordPress site's database.
Reference:
wp_insert_post() https://developer.wordpress.org/reference/functions/wp_insert_post/
You should perform this using wordpress inbuilt functionality that is import and export through wordpress admin.
Just go to your wordpress admin from where you want to shift all post.Then go to tools section and click on export and select posts in your case. You can also export all content, pages etc. using this. You will get a .xml file, just download it.
Check here : https://codex.wordpress.org/Tools_Export_Screen
Now, go to wordpress admin of your another website where you want to import content. Just go to tools and click on import and go with the flow.
Wordpress have a builtin export function. Export that from the other site and import on the other site.

Pass URL parameter (utm code) across my site's webpages [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a webpage I'm trying to promote via ad banners. I want to associate a utm code to those those links, so when a visitor lands on my website, I'll be able to track where they came from (mysite.com?utm_campaign=adXYZ)
Normally these ad banners lead to a single webpage with single point of conversion where I'm able to capture the utm_campaign ID and gauge how effective my marketing is. However, I'm now leading users to a full website with many pages and many points of conversion. I'm hoping to keep that utm_campaign ID across multiple pages using some crafty JS or PHP.
For example:
user clicks ad banner to mysite.com?utm_campaign=adXYZ
user lands on mysite.com but wants to go to mysite.com/features
user goes from mysite.com/features to mysite.com/pricing
By the time the user reaches mysite.com/pricing, I want ?utm_campaign=adXYZ to still be there in the URL.
I know there are ways via analytics and what not to track a session/conversion, but I specifically need to capture the referral utm code in an HTML form down the road. Can anyone point me in the right direction? Thanks a bunch!
Edit: An important point to note. The site should still be accessible organically via search, bookmark, linking, etc and not have the trailing campaign ID in the URL. Only when user visits the site from ad banner should the campaign be there and all subsequent pages.
I would set a cookie containing the relevenat information the first time the user enters your website.
Otherwise you have to pass the information every time again with every request (GET / POST). This solution will work even if the user don't allow cookies. Murat Cem YALIN wrote how this works in detail. But if you want to use the JS-method: Be aware that the user must have JS activated!
The third option might be using PHP Sessions.
you can do it with both php and js.
in php use simplehtmldom (http://simplehtmldom.sourceforge.net/) to access all links in html output and add ?utm_campaign=adXYZ to all of them just before outputting rendered html.
in js you use jquery to do the same when the document loaded. ex:
$("a").each(function(){
$(this).attr("href", $(this).attr("href") + '?utm_source=adxYZ');
});

Working options without API's in PHP [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
There is a site that does not have a standalone search or API product available at this time, and I need a PHP page which can get information another way. This site has a manual search function to pull data, is there a way for my page to go to the site, click on the search parameters that I need and pull the results into my page? Maybe there's a better way?
Example.
realestate.com.au, I want a user to enter the same search fields in my php file, go to realestate.com.au, plug in those search parameters in that site, then as the results of my search come through, eg, 3 bedrooms, 2 bathrooms in the Suburb of Marylands, I get the price of all the results and in my page calculate the median price, and that field gets outputted to the user on my screen.
Now I have no code for this as I don't even know how to start. I cant do most of it if I can find out a way to start by having php go to realestate.com.au (not redirecting the user there, just hooking into the website) and doing the search.
I hope I make sense.
Regards
This is somewhat complex... more than I can cover here. but here is the general steps involved:
1) Build your URL
From your target site, find out what the URL looks like on the search results page. That should tell you how to build your URL for later on.
2) Use CURL to retrieve your custom results page
Using the format that you saw above, sned a request for that page using CURL. Only you will be substituting your visitors search terms into the URL.
3) Scrape the resulting page
CURL will fetch the HTML from the search results page. You will then have to iterate through that result and pull out the needed data using DIV IDs and classes.
4) Serve the final results to your visitor
Drop the scraped data into your own page and send to the browser.
See aslo:
http://voices.yahoo.com/how-scrape-web-page-using-php-curl-5442987.html
NOTE: I would make sure you have permission to scrape the site.

Pause music when switching to another page in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I like to pause music when switching to another page from home page & on returning back we should resume the music as it was before. It shouldn't need to restart the music again when I get back to home page.
We are using flashplayer found from this site:
http://flashnifties.com/products/nifty-audio-player/documentation/
However we have not found any script which fulfill our need.
Please help me if anyone has the solution of this problem.
The critical part of this problem is that you are reloading the page, which completely resets the Flash player within it. You are left with two options:
Implement your site as a single page application and use ajax to refresh the content. This means that the Flash player will not be reloaded when the user needs more content (this is what we do on our site).
-or-
Use a frameset, with player loaded in one frame, and rest of website in the other. This is a bad choice of architecture... frames are evil.
It looks like you can pause with this:
audioPlayer.pauseAudio()
I would add this javascript to the button or object that changes to a new url (page). This listens for an action and does
document.getElementById('newPageButton').onclick = function() {
//interact with the flash "audioPlayer.pauseAudio();", cache song time location.
//go to next page code
}
you'll probably need to write your own actionscript to save the location of were the song was paused at. Looking at the documentation there isn't a way to see exactly were the song was paused.
After you figure that out, store the location on some sort of caching. Load that caching when you go back to the page. Though looking at the documentation again, it looks like you'll need to write some actionscript to get resuming at a specific time working.
This might not be the best flash player for what you wish to achieve.

Building analytics for a custom application - would an open analytics framework (like piwik or owa) be the solution? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
An application I am involved with is in dire need of a restructuring of the reports section... I am open to suggestions. All the development is currently in PHP (nginx/php/linux/mysql/redis environment), although other suggestions which fit in to the environment are welcome.
There is already ongoing logging for the current system which feeds into mysql tables. All tables are basically the same structure and different things logged with different logtypes.
There are a couple of different metrics/actions we'd like to report on, and be able to have the users drill down, by date or other filters.
Example metrics:
User searches a topic. I log his user id, search keyword, each result ID.
User accesses an item on the system (either from a search result above, or from my main page - i have separate logs for both). I log (currently) the "ID" of the page, the unique ID of the user (all users have an ID), the time, the Category of the page.
User submits a request for an item. I log the ID of the request (new id), the unique ID of the user, the Category of the report.
List all users who clicked on item X.
etc
Can someone give me some opinions on whether I would be able to leverage the existing functionality in Piwik (www.piwik.org) or Open Web Analytics (http://demo.openwebanalytics.com) to build an easy to use dashboard of sorts and report tool? The idea is that most if not all of the queries to insert and to select the data for the metrics above we already have. What we need is a uniform way of displaying the data, where the user can view different reports in a constant format, etc...
Filtering by category where we have a category ID would also be something necessary. Category is a hierarchichal tree and picking a parent node means we basically list all child nodes and make an IN (x,x,x) with all of the child IDs (we are investigating changing to linear tree traversal, but thats for another discussion...)
basically, once again, sorry if this has become confusing: from those who have experience with piwik/owa/other web analytic frameworks, have you used it to deliver custom metrics from custom applications, not related directly to webpage viewing?
If so, could you share examples?
Also, any reasons to favor piwik or owa? OWA seems to have some nice things which we could maybe add in the future like heatmaps and recordings, but the main focus right now is the custom metrics so the web metrics stuff would be disabled at first...
Thanks for the help...
Using Piwik with a mix of Custom Variables & Segmentation should allow for your requirements.

Categories