Skip to main content
Drymetal
Inspiring
August 31, 2012
Question

Wildcards in URLs?

  • August 31, 2012
  • 1 reply
  • 2009 views

Can you use wildcards in URLs in PHP?  For instance:

<?php $MyUrl= 'http://mysite.com/'; ?>

Are there wildcards or something I can throw at the end of that so all subdirectories and files are included in that?

Thanks!

This topic has been closed for replies.

1 reply

Participating Frequently
August 31, 2012

You can put whatever you want in there. What matters is how you intend to process that variable in your php script. If you put a '*' at the end of the url, then your script would need to detect that and take appropriate action. It's not clear what your intent is here.

Drymetal
DrymetalAuthor
Inspiring
August 31, 2012

Let's say it was something like this:

$myUrl = 'http://mysite.com/';

    $checkLength = strlen($myUrl);

    $referringQuacks = substr($_SERVER['HTTP_REFERER'], 0 , $checkLength);

    if ($referringQuacks== $myUrl)

    {

blah blah blah

So as stupid as it sounds - I want to make sure that the person is being referred by the site they are on.  But if there is a subdirectory - this doesn't work.  So I want that myUrl variable to include not only the domain - but all subdomains as well.

Does that make sense?

Participating Frequently
August 31, 2012

I don't know exactly why you are checking referers but I don't think you really don't need to worry about subdirectories here. The way you are doing it now, checking the substring for a match, should work. Typically you wouldn't care if the referer came from a subfolder. Don't forget to account for cases where the visitor might enter 'www' in the url. I know there are functions in ASP that allow you to get the domain portion of a url; I'm sure php has similar.

Be aware that many things such as browser settings, add-ons, firewalls (personal and corporate) will block http_referer. So if you are relying on a match before executing some critical function (form posting, etc), it will fail frequently.