Category Archives: Programming

Bulk Extract Hyperlink from Excel Cells

Alas there is no pre-defined function for extracting a hyperlink from an Excel cell. Therefore the easiest way to accomplish this is to create our own function using a macro.

Within Excel, open up the VBA Macro Interface:
Alt + F11

From the VBA interface, goto the menu and select:
Insert -> Module

On the module screen that opens up, paste in the following text:

Function HyperExtract(content As Range) As String
    On Error Resume Next
    HyperExtract = content.Hyperlinks(1).Address
End Function

Save your spreadsheet (you’ll now need to save it as a *.xlsxm format) and close the VBA screen.

Voila!

Enable or Disable PHP Functions For One cPanel Account

Enabling certain PHP functions for all users can be a security risk. However, by creating a user specific php.ini file, the risk can be mitigated for that one (hopefully trusted) user who needs a bit more functionality.

Step 1: Find the main copy of the php.ini file – probably located as /usr/lib/php.ini

Step 2: Copy it to the root directory of your user.
cp /usr/lib/php.ini /home//public_html/

Step 3: Edit the new php.ini file and edit the ‘disable_functions’ line to include or remove whichever function you want.

Step 4: Create or edit the .htaccess file in the sites root directory and insert the following:
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/<cPanel user>/public_html/php.ini
</IfModule>
<Files php.ini>
order allow,deny
deny from all
</Files>

Voila

Submit HTML form using GET or POST without the ‘Submit’ button

Whenever you submit a form using the submit button, the value of the submit button is also sent.

For example, this form:

<form id="myForm" method="get" action="http://www.your-site-name.com/page.php">
 <input type="text" name="value1" value="foo">
 <input type="text" name="value2" value="bar">
 <input type="submit" name="submit" value="Submit">
</submit>

Will open a page with the following URL:

http://www.your-site-name.com/page.php?value1=foo&value2=bar&submit=Submit

The best way to prevent the submit variable from showing is to not transmit the form using the submit button, but instead to use a bit of JavaScript on a normal button:

<form id="myForm" method="get" action="http://www.your-site-name.com/page.php">
 <input type="text" name="value1" value="foo">
 <input type="text" name="value2" value="bar">
 <input type="button" name="submit" value="Submit" onClick="document.getElementById('myForm').submit();">
</submit>

Which will yield a submitted form with the following URL:

http://www.your-site-name.com/page.php?value1=foo&value2=bar

Voila.

How to open a new browser window or tab using JavaScript

A client-side language like JavaScript can be used to open a new browser window or tab. Unfortunately, as it is client-side then there is no way to specify whether it is a new window or tab that is opened… that is down to how the particular browser is configured.

<script type="text/javascript">
 window.open('http://link-to-site/page.php?$value1=" . $value1 . "&value2=" . $value2 . "')
</script>

Open new window or tab and submit form using POST and PHP

How often have you pondered the best way of generating a dynamic page in PHP and then need to submit it to a website in a new window as if it has come from a form? Not often? Me neither… but having struggled to find an elegant solution I thought I would share my findings.

(See also the solution for using GET)

There are a few different ways of submitting a form using the POST headers from a dynamically generated PHP page. The first uses cURL, however I find this code to be cumbersome. The simplest way I have found is to generate a form and submit it using the POST method. It would be up to you whether you would prefer to open a new window (see how to open new window in javascript here) or place it in the code of the page you are loading and set ‘targert = “_blank” ‘ as used in the example below:

<?php
 $value1 = "foo";
 $value2 = "bar";
?>

<form id="myForm" method="get" action="http://link-to-site/page.php" target="_blank">
 <input type="hidden" name="value1" value="<?php echo $value1;?>" />
 <input type="hidden" name="value2" value="<?php echo $value2;?>" />

 <script type="text/javascript">
  document.getElementById('myForm').submit();
 </script>
</form>

Open new window or tab and submit form using GET and PHP

How often have you pondered the best way of generating a dynamic page in PHP and then need to submit it to a website in a new window as if it has come from a form? Not often? Me neither… but having struggled to find an elegant solution I thought I would share my findings.

(See also the solution for using POST)

Submitting a form using the GET method simply places all of the values in the URL. Because PHP is a server-side language, there is no way to force a new window to open in a browser without using a client-side language (e.g. JavaScript). This javascript can be dynamically generated via PHP though to solve our problem.

<?php
$value1 = "foo";
$value2 = "bar";

echo "<script type="text/javascript">
	window.open('http://link-to-site/page.php?$value1=" . $value1 . "&value2=" . $value2 . "')
</script>";"