Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I created a mobile portion of the site and I can redirect it easily enough using this:
<script type="text/javascript">
if (screen.width <= 699) {
document.location = "http://mysite.com/mobile/";
}
</script>
That works fine. But then I thought - Hey! What if they want to see the normal site (from their mobile device or iPad)? So then I put a link on the mobile site going to the normal site and ran into a paradox of sorts. It kept sending them to the mobile site because of the screen check.
So then I tried to come up with code to by pass this. So this is what I came up with:
<?php
$myUrl = 'http://mysite.com/';
$mobileUrl= 'http://mysite.com/mobile/';
$checkLength = strlen($mobileUrl);
$referringQuacks = substr($_SERVER['HTTP_REFERER'], 0 , $checkLength);
if ($referringQuacks== $mobileUrl){
$chicken;
}
elseif ($referringQuacks == $myUrl)
{
$chicken;
}
else
{
echo '<script type="text/javascript">
if (screen.width <= 699) {
document.location = "http://mysite.com/mobile/";
}
</script>';
}
?>
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 it is the main url: mysite.com/ Then do nothing.
If it is any other instance - then run the javascript to check screensize and redirect to mysite.com/mobile/ if it is smaller than 699.
But then I thought - I don't need to check the mobile directory. I could just do away with that and use the mysite.com/ url. In other words - since the mobile directory is on the URL - then why not just have one URL that includes all subdirectories?
If only I had a wildcard to say not just that url - but any subdirectories on it as well.
Sorry for the confusion on subdomains and subdirectories. Anyways - does that make sense? I just confused myself. : (
Message was edited by: Drymetal
Copy link to clipboard
Copied
>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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
>So I want that myUrl variable to include not only the domain - but all subdomains as well.
Sorry, I didn't see your comments before posting my previous reply. Are you talking about subfolders, or subdomains?
>So as stupid as it sounds - I want to make sure that the person is being referred by the site they are on.
Can you clarify this a bit? What is the workflow that you are concerned with?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now