GET URL parameter in PHP

$_GET is not a function or language construct—it’s just a variable (an array). Try: <?php echo $_GET[‘link’]; In particular, it’s a superglobal: a built-in variable that’s populated by PHP and is available in all scopes (you can use it from inside a function without the global keyword). Since the variable might not exist, you could … Read more

apache redirect from non www to www

Using the rewrite engine is a pretty heavyweight way to solve this problem. Here is a simpler solution: <VirtualHost *:80> ServerName example.com Redirect permanent / http://www.example.com/ </VirtualHost> <VirtualHost *:80> ServerName www.example.com # real server configuration </VirtualHost> And then you’ll have another <VirtualHost> section with ServerName www.example.com for your real server configuration. Apache automatically preserves anything … Read more

How to set a cookie for another domain

You cannot set cookies for another domain. Allowing this would present an enormous security flaw. You need to get b.com to set the cookie. If a.com redirect the user to b.com/setcookie.php?c=value The setcookie script could contain the following to set the cookie and redirect to the correct page on b.com <?php setcookie(‘a’, $_GET[‘c’]); header(“Location: b.com/landingpage.php”); … Read more

Google Apps Script to open a URL

This function opens a URL without requiring additional user interaction. /** * Open a URL in a new tab. */ function openUrl( url ){ var html = HtmlService.createHtmlOutput(‘<html><script>’ +’window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};’ +’var a = document.createElement(“a”); a.href=”‘+url+'”; a.target=”_blank”;’ +’if(document.createEvent){‘ +’ var event=document.createEvent(“MouseEvents”);’ +’ if(navigator.userAgent.toLowerCase().indexOf(“firefox”)>-1){window.document.body.append(a)}’ +’ event.initEvent(“click”,true,true); a.dispatchEvent(event);’ +’}else{ a.click() }’ +’close();’ +'</script>’ // Offer URL as … Read more

How to redirect all HTTP requests to HTTPS

The Apache docs recommend against using a rewrite: To redirect http URLs to https, do the following: <VirtualHost *:80> ServerName www.example.com Redirect / https://www.example.com/ </VirtualHost> <VirtualHost *:443> ServerName www.example.com # … SSL configuration goes here </VirtualHost> This snippet should go into main server configuration file, not into .htaccess as asked in the question. This article … Read more