PHP – N77 Design | NickClaeboe.com https://www.nickclaeboe.com Atlanta Web, Graphic & Flyer Design • Design Portfolio & Rates for Nick Claeboe Custom Design Work Wed, 03 Mar 2021 14:42:59 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://www.nickclaeboe.com/wp-content/uploads/2016/05/favicon-60x60.png PHP – N77 Design | NickClaeboe.com https://www.nickclaeboe.com 32 32 Rotate URLs with PHP Location Header Exit Code at Fifty Percent Random While Preserving URL string https://www.nickclaeboe.com/2018/06/13/rotate-urls-with-php-location-header-exit-code-at-fifty-percent-random-while-preserving-url-string/ Wed, 13 Jun 2018 11:30:17 +0000 http://www.nickclaeboe.com/?p=557

This is a great piece of code to rotate 2 separate landing page urls using PHP location headers and a 50% random string. This code also preserves the URL string so that any url string variables are sent to the rotated links of the outbound pages.

We achieve this by using a simple redirect script php header.

This snippet of code is excellent for the testing of different landing page offers with different designs and elements, so you may determine which page layout and design performs better.

First, I set up an index.php page in a directory on my site. In this case is was just a simple /r directory. So the file structure would look something like this

https://www.nickclaeboe.com/r/

and the php code would be added to the index.php file in this /r directory.

<?php
if (mt_rand(0,1) == 0) {
header("Location:https://www.nickclaeboe.com/blog/post1/?". $_SERVER['QUERY_STRING']);
exit;
} else {
header("Location:https://www.nickclaeboe.com/blog/post2/?". $_SERVER['QUERY_STRING']);
exit;
}
?>

Using this code, and with it preserving your url string, your traffic link would look something like:

https://www.nickclaeboe.com/r/?yourVariable=this

and with the script above installed on the index.php of the /r directory, the random string in the php snippet will send your traffic to each link approximately 50% of the time, evening out the traffic sent to the 2 pages you are testing. Ultimately, you will see your traffic sent to each page and those links will now look something like this:

https://www.nickclaeboe.com/blog/post1/?yourVariable=this

and

https://www.nickclaeboe.com/blog/post2/?yourVariable=this

I hope this helps you out as much as it’s helped me out.

It’s a very quick and easy way to test 2 separate landing pages with different landing page elements to test what page converts better based on your page variables.

]]>
Get User Agent For Custom Browser Styles – PHP Get User Agent Variables https://www.nickclaeboe.com/2016/09/28/get-user-agent-custom-browser-styles-php-get-user-agent-variables/ Wed, 28 Sep 2016 11:36:29 +0000 http://www.nickclaeboe.com/?p=435

Often, I come across the need to pull the user agent from the browser to echo custom CSS styles for that specific browser. This comes in very handy when developing for mobile. Below is a list of the major user agent/browsers and the php call to get the user agent from the session.

Use the following code below to grad the user agent for you development needs.

/// get user agent for custom browser styles
function get_browser_name($user_agent)
{
if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
elseif (strpos($user_agent, 'Edge')) return 'Edge';
elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
elseif (strpos($user_agent, 'Safari')) return 'Safari';
elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'IE';

return 'Other';
}
?>

<style>
.IE #form form select {
width: 185px;
height: 26px;
margin-right: 5px;
margin-left: 9px;
padding: 0 0 0 15px;
font-size: 12px;
color: #666;
}
.IE input[type="text"]{
height:27px;
width: 185px;
margin-left: 8px;
/* margin-right: 8px; */
text-indent: 10px;
border: 1px solid #ccc;
}
.Firefox #form form select {
width: 159px !important;
height: 30px;
margin-right: 5px;
margin-left: 9px;
padding: 0 0 0 15px;
font-size: 12px;
color: #666;
}
.Chrome #form form select {
width: 190px;
height: 26px;
margin-right: 5px;
margin-left: 9px;
padding: 0 0 0 15px;
font-size: 12px;
color: #666;
}
.IE input::-ms-clear {
display:none;
}
</style>

<body class="<?php echo get_browser_name($_SERVER['HTTP_USER_AGENT']); ?>">

 

]]>
Carry and Pass Variables From Page to Page in WordPress – Google UTM Tags Vars https://www.nickclaeboe.com/2016/09/17/carry-pass-variables-page-page-wordpress-google-utm-tags-vars/ Sat, 17 Sep 2016 12:50:39 +0000 http://www.nickclaeboe.com/?p=406

Last week I posted about grabbing Google UTM tags from a url string and using that to hide or show specific content based on a variable. After that task, I kept running into another issue with Google UTM tags… Grabbing them from an incoming link, grabbing those variables, and passing each of them along in the url to each page that the visitor navigates.

At first I was searching for a plugin or a WordPress function to rewrite the url’s with my url string but kept getting nowhere.

After several hours of research and a day later, I found a javascript/php hack that produced the results that I was ultimately looking for. Yes, it could be prettier but it WORKS!

Locate your template footer.php file in your theme folder and place the following code just before the closing tag to grab Google UTM tags and pass them to each page of your WordPress site.

Here’s 5 of the most common Google UTM tags that we grab from the session:

utm_source
utm_medium
utm_camgpaign
utm_terms
utm_content


<?php $utm_source = isset($_GET['utm_source']) ? $_GET['utm_source'] : ""; ?>
<?php $utm_medium = isset($_GET['utm_medium']) ? $_GET['utm_medium'] : ""; ?>
<?php $utm_campaign = isset($_GET['utm_campaign']) ? $_GET['utm_campaign'] : ""; ?>
<?php $utm_term = isset($_GET['utm_term']) ? $_GET['utm_term'] : ""; ?>
<?php $utm_content = isset($_GET['utm_content']) ? $_GET['utm_content'] : ""; ?>


<script type="text/javascript">
jQuery(document).ready(function ($) {
$(function() {
$("a").attr('href', function(i, h) {
return h + (h.indexOf('?') != -1 ? "&utm_source=<?php echo $utm_source; ?>&utm_medium=<?php echo $utm_medium; ?>&utm_campaign=<?php echo $utm_campaign; ?>&utm_term=<?php echo $utm_term; ?>&utm_content=<?php echo $utm_content; ?>" : "?utm_source=<?php echo $utm_source; ?>&utm_medium=<?php echo $utm_medium; ?>&utm_campaign=<?php echo $utm_campaign; ?>&utm_term=<?php echo $utm_term; ?>&utm_content=<?php echo $utm_content; ?>");
});
});
});
</script>

The first 5 snippets of php code are how you grab the Google UTM tag variables from the incoming link.

As you can see, we are grabbing the variables from the session that being passing in from the link. We’re grabbing the dynamic variable and echoing that variable in the javascript below it.

The javascript is where the magic happens on page redirect.

When a visitor clicks on any internal site link, the variables are picked up from the session and echoed behind the hardcoded variable tokens.

Sidenote: the code can be optimized, but this down and dirty method works

 

]]>
Carry Variables From One Url To The Next PHP WordPress Tip Hack https://www.nickclaeboe.com/2016/09/10/carry-variables-one-url-next-php-wordpress-tip-hack/ Sat, 10 Sep 2016 13:28:57 +0000 http://www.nickclaeboe.com/?p=393

While using WordPress and running traffic to many WordPress sites, I discovered the need for variables to be passed from one page to the next as a visitor is navigating a WordPress site.

After doing some extensive research, I found a simple script that can be added to the theme functions.php file to carry dynamic variable from one page to the next as a visitor is on your site.

I’m my case, I wanted the “utm_source” variable “GA” be appended and carried at the end of my url. It would look something like this:

http://www.mywebsite.com/category/site/?utm_source=GA

What natively happens in WordPress , is that once a visitor clicks a link, the variable is dropped from the url and not carried/passed on to the next page. The following script, when placed in your theme functions.php file, will allow your WordPress theme template to keep that variable and pass it to the next page.

////////////////////////////////////////
///// pass vars page to page

function wprdcv_param_redirect(){
if( !is_admin() && !isset($_GET['CUSTOM ']) ){
$location = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$location .= "?CUSTOM =PARAM1 ";
wp_redirect( $location );
}
}
add_action('template_redirect', 'wprdcv_param_redirect');

/////////////////////////////////////////////////////////

Just replace CUSTOM and PARAM1 with the variables you’re using, in my case, CUSTOM = utm_source and PARAM1 = GA, in the above code and add it to your functions.php

Also, if you are needing to do this for more that one variable, simply duplicate the code and update the variables, but, be sure to create new function identifier as follows:

function wprdcv_param_redirectTWO(){
if( !is_admin() && !isset($_GET['CUSTOM2 ']) ){
$location = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$location .= "?CUSTOM2 =PARAM2 ";
wp_redirect( $location );
}
}
add_action('template_redirect', 'wprdcv_param_redirectTWO');

Be sure to test everything out and if you run into any errors, roll back your edits until you get it the way you want it.

Good luck!

 

]]>
How to Fix Fatal Error: Maximum Execution Time Exceeded in WordPress https://www.nickclaeboe.com/2016/05/22/how-to-fix-fatal-error-maximum-execution-time-exceeded-in-wordpress/ Sun, 22 May 2016 22:13:51 +0000 http://ec2-54-186-150-17.us-west-2.compute.amazonaws.com/?p=286

I’ve been doing quite a few WordPress sites for clients lately and I use a lot of premium templates from templateforest.net. These templates are great but you can run into php errors with them from time to time dependent on your server’s settings for php. Sooner or later you’re going to run into some kinds of php error and that brings your site to a screeching halt. The most recent error that I encountered was this:

1.Maximum Execution Time (max_execution_time) : 30

I ran into several solutions, or so I thought, to correct this error. Again, dependent on your server’s php settings and where you host your site, this can turn into a giant headache in a hurry. I’m going to give you two methods that work and the one method that worked for me. It saved me so much time and got my project back on track with the client.

Method 1: Editing the .htaccess file

Using your favorite FTP clinet (mine’s Filezilla), edit your .htaccess file that’s located in your site’s root folder, where all of your main WordPress files reside as well.

Right click on the file (in Filezilla) and choose View/Edit and edit the .htaccess file in your text editor of choice. I prefer Notepad++.

At the end of the .htaccess file, paste this snippet of code.

1.php_value max_execution_time 300

This code sets the value for maximum execution time to 30 seconds. Some WordPress templates may require 60 seconds or more, if so, simply change the value to 600 or more dependent on your template’s needs.

Method 2: Editing the wp-config.php file (method that worked for me)

Again, using Filezilla (FTP) to connect to your server, in the root folder of your site, edit the wp-config.php file.

Scroll to the bottom of the file and above the commented out code that reads:

1.“/* That’s all, stop editing! Happy blogging. */”

Paste this snippet of code:

1.set_time_limit(60);

I hope that one of the above methods works for you, the wp-config.php file edit method is what worked for me. Happy coding.

]]>