checking entire database during new post [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i have customized cms built in PHP. my website have more than 2,00,000 posts. when i publish a new posts, it take too many time to publish a single posts.
When i publish new post, it is checking entire data base to find if the url is exist in the database. if it exist then it shows an error.
I want to know, is this necessary to check entire database to check, if the url exist already.
Because it is checking entire database before publishing, it takes lot of time and server goes down.

Instead of checking the database to see if the URL is unique, simply force it to be unique by appending the ID of the new record to the URL string that you are saving and configure your website to work like that. For example, instead of you URL looking like:
mywebsite.com/post/test-post
Use something like
mywebsite.com/post/test-post/100
Where the 100 value is the ID of the post, which is a unique Primary Key

If you insist on using a URL that is generated from the subject line of a post (which I suppose is what you're doing here, your question is a bit vague), then create a table that contains hashes of every URL and search for the hash. That's a quick binary search. You'll need to watch out for hash collisions, so you should store the string in full as well.

Related

Create a link based on table date on another website [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 5 years ago.
Improve this question
I am trying to think about how I would go about creating a link to something based on a data in another table on another website.
I have the following table on the other website:
https://i.imgur.com/Hlemt1y.jpg
so basically columns: Order #, Status, customer P-O
What I am trying to do is create a url based on "customer PO" that links to the Order #. So it would find the customer PO, then check the value on the same row of Order #, and then once I have that value I can create the URL using that order #.
I've never done anything that takes a value from another website so I guess that is what I am after?
If the other web page doesn't have an API that you can use to retrieve that data in a more usable format, you will have to use a technique known as scraping. you would likely use curl or wget to fetch the web page and then parse the resulting html page to pull the data you need out of it. an xml library would be able to assist in parsing, but you may be able to get away with a shortcut by searching the string for a common beginning and ending string.
so for example, if there is only one html table on the page, you can search for
<table>
and the matching
</table>
Then parsing the tr and td tags is a little more manageable than dealing with the entire page. In the end it just depends on what this is being used for and how robust it needs to be.

Hide dynamic page "movie.php?id=10" from my PHP website's URLs and replace spaces with hyphens [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 5 years ago.
Improve this question
My website's URLs are as:
"/movie.php?id=10 Rangoon (2017)"
Spaces are converted to %20 by web browser.
But I want the simple URL like this:
"/Rangoon-(2017)"
How Can I do that?
My website is developed in PHP and all data of my website is placed on MySql Database and "movie.php" page retrieves the data from MySql Database.
Well, that's not a simple one, you'll have to make many updates :
generate an url for each of you movie pages (By the way, don't use parenthesis in an url, in your example the url should be something like rangoon-2017). You may use my method
seoUrl
store this url somewhere in your database
Decide on an url scheme, like movie/title-of-your-movie
When displaying a link, display the url scheme
create an .htaccess file which rewrites movie/whatever to movie.php?url=whatever
On movie.php, retrieve your movie information from the url and not the id
Additional thoughts :
you'll have to make sure each movie has an unique url. Adding the year is a good idea, since I doubt two movies will have the exact same title and year.
also, make sure your urls are unique in the database (And indexed, since you'll search from them)
why the prefix movie/ on the url ? Simply because if you don't create it, you'll find more difficult to redirect other type of pages to the correct file.

I want to create a website for polls/survey like this http://www.poll-maker.com/ [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
but did not understand
The concept of generating a link &
more importantly how they save the data in database,do they save it like id of poll & yes/no click or done with other logic.
what will happen to the polls which are expired? will they remain in database or somewhere else?
please help
To handle URL you can use cURL.
But I have an easy method. You can use the concept of Query Strings.
To Create New Question
Store the new question in database.Give Each Question a unique ID.
Then After user submits the questions show him a link like:
http://do-survey.com?question=xzxsa
To store polls
Get question like:
if(isset($_GET['question']))
{
$question = $_GET['question'];
// Now you have the question unique id manipulate the database using this
}
this is not the place to ask such questions, but to make my answer at least remotely useful:
they're not generating a link. That link doesn't exist under the form of a file on the server. Take for example a database containing 'id' 'poll' 'var1' 'var2'.
You can make a php page that gets a param from the link, have it like mysite.com/poll?id=1
The php script will get the '1' as a param, then you SELECT * FROM table WHERE id=1 and you generate the contents via php with the data from the DB.

How to avoid someone to fetch my database? [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 8 years ago.
Improve this question
I have video website and I worry about if somebody write a script that fetches all my database and use it because i use the video id in address as query string for saying every page which video have to be shown.
Example:
http://example.com/video/215/videotitle
215 is my video id and videotitle is the title of my video, i want to have something like youtube:
www.youtube.com/watch?v=__zj6ibrq04
How can I do this?
i should mention that I used mod_rewrite to get an address like this so I absolutely worry about somebody fetching my database because they can know the video id.
That's awful because id is an auto increment primary key in my database!!!
Is there any suggestion?
If all your pages are public, i.e. anyone can go to any site at any time, there's only one thing you can do against a bot automatically scraping your site: detect scraping behaviour and throttle it. That means you need to track every visitor by IP address and/or other characteristics and start denying them access once they start requesting too many pages within a certain time window. No, this is not trivial to get right.
In this case it doesn't really matter what your URLs look like; you may think that YouTube's URLs are "unguessable", but (most of) YouTube's videos are entirely public and can be discovered by browsing through YouTube's front page. There's no need to guess the URL, that's an irrelevant detail. And even if they were not, you could simply start trying every single URL from __aaaaaaaa trough __9999999. It'll take a while, but it's possible.

How to make a bot to navigate a site? [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 5 years ago.
Improve this question
Given a product id, associates have to navigate a vendors website, log in, perform a search, in order to get details on a product for a customer.
My employers want a program that can use the product id, and navigate the vendors website, and perform the search and everything to get the information thus saving the associate from having to manually repeat this task every time a customer wants more information about a product.
I know many sites use methods to prevent (CAPTCHA) exactly what I am trying to do. So I do not know if that automatically makes my given project an "evil" one. But I certainly do not have evil intentions, my employers simply want to save associates time on getting information that they are going to get regardless. However, if this is "evil" please explain why, so I can explain to my employers why we should not go down this road. That being said...
How can I make something like this in PHP?
It depends on what site you are trying to access. Many sites have an API that can be used to access data. If that's not the case, you may need to write a program that loads the html using a GET request, parses through the response, and retrieves the information you want. Without more details, that's the best answer I can give.
To start with I'd recommend reading up on cURL and DOM
cURL: http://php.net/curl (for fetching pages, even simulating search form)
DOM: http://www.php.net/manual/en/book.dom.php (to parse the fetched pages)

Categories