php - SELECT from database WHERE some parammeter is equal to a portion of a string var -


I'm trying to recover it from my database of "validity" of the domain (if something is authorized to do) The URL being checked came to my script on a GET variant and then I just asked the database:

  $ url = $ _GET ['url']; // The complete URL of the site like: sub1.domain.com/page/1/some $ url = parse_url ($ _GET ['url']); // URL parsing http://php.net/manual/en/function.parse-url.php $ host = $ url ['host']; // gives me sub1.domain.com   

after parsing:

  $ query = "SELECT * fROM domains_table WHERE domain = '". $ Host "';   

This works great, sometimes domain.com has several sub-domains and I can not save all the variations in the database. It seems to me a lost place if we say domain.com has 30 sub-domains and then I need to save sub1.domain.com sub2.domain.com and so on ...

Instead, I was thinking in a more robust way, saving in the data base such as *. Domain.com and then somehow (and this is where I need help) in the query or in the php script (if the query is better, the personal taste), make something that says' there is a string How can I do this?

Edit:

There is some confusion in the answer, so I try to explain myself better:

If saved in URL field in my table: *. Domain1.com How can I do something like this:

  SELECT * from domain WHERE url like "sub1.domain.com"   < P>   

You can use MySQL's operator to recover something Want to

Example:

  SELECT * from table WHERE value like '% string%';   

"string" matches % any string before or after the part.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -