Skip to main content
Drymetal
Inspiring
August 31, 2012
Question

Wildcards in URLs?

  • August 31, 2012
  • 1 reply
  • 2011 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?

Drymetal
DrymetalAuthor
Inspiring
August 31, 2012

>So basically - it is saying if the referrer is the mobile site then don't

>do anything.  I have $chicken cause I don't know how to say "Do nothing".

If you don't want to do anything when a comparison tests positive, then typically you would reverse the logic and do something if it tests negative (basic boolean logic):

if ($referringQuacks != $mobileUrl){

do something

{

But I don't know if I'd be using referers here to accomplish what you want. Your mobile site has a link to the normal site. Why not add a querystring to the link that can be used to turn off the screen width test. You could even write a cookie or set a session variable (if you are using sessions) to make it persist.


I thought of using a query string - however, after they get to the home page and click on a link - that query string will be gone and they'll get redirected again.  I've got the script for the window size in the header file.  So it loads on every page.

A session might work.  I would just use an if isset statement for a session wouldn't I?