Redirect a domain to another file domain keeping web browser URL (htaccess)

Situation:
You have a site (eg. www.mysite.com) and a page of this site dedicated to photography (eg. www.mysite.com/photography.html) . For some reason you buy another domain (eg. www.photosite.com) and want to render your photography.html page below this new domain.

Solution:
Use a htaccess file running Apache server to solve that. How?

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^$ photography.html [L]
RewriteRule ^(.*)$ http://www.photosite.com/$1 [P]

And upload it to you new domain renaming the name to .htaccess .

Explanation:

  1. First rule will redirect www.photosite.com to www.photosite.com/photography.html
  2. Second one will “render” every www.mysite.com/any-site-page.html under domain www.photosite.com, and keeping this url domain even navigating between different pages (that’s why there’s a [P], standing for Proxy).

Hope you you find it useful.

Read More

Warning: Cannot modify header information – headers already sent

Sometimes programming with PHP and trying to redirect pages with header(“location:”.$site); , it’s possible to get the following warning:
Warning: Cannot modify header information – headers already sent
This may occur for one of those reasons:

  • Start the file with (or including a file which starts with):
    1
    2
    3
    
    <?php
     
    // the code starts here, above there's a whitespace
  • Having previously in the script (or including a file which have it) whitespaces :
    1
    2
    3
    4
    5
    6
    7
    
    <?php
    // some example code...
    ?>
     
    <?php
    // more example code lines...
    ?>
  • Print or echo of a variable or text before sending headers.
  • HTML code before sending headers.
  • A mix of the above reasons…

Sometimes, depending on PHP version, everything seems to be okay but when you run the script, it doesn’t work. Let’s see an example:

Warning: Cannot modify header information – headers already sent by (output started at /full/route/to/file/which/previously/has/sent/headers/included.php:xx) in /full/route/which/has/sending/header/script.php on line xx

In script.php there is eg. header(“location:script2.php); and apparently headers has sent before in included.php.

In included.php:

1
2
3
4
5
6
7
8
9
10
11
12
<?php
// code
if ($lang== "es")
{
	include("spanish.inc.php");
}
elseif ($lang== "en")
{
	include("english.inc.php");
}
// more code
?>

Imagine your error is on include(“spanish.inc.php”) and obviously the included file is ok (eg. empty). Then why there’s an error? Some php versions or apache/iis configurations, make an include (or require, require_once, …) works as an output buffer. To avoid that, just wrap the “conflictive” code with:

ob_start();
// code which have include or require, etc.
ob_clean();

So, finally In included.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// code
ob_start();
if ($lang== "es")
{
	include("spanish.inc.php");
}
elseif ($lang== "en")
{
	include("english.inc.php");
}
ob_clean();
// more code
?>

 

More information about those php functions here and here.

Read More

Date, time and other web selectors with mobile appearance.

Sometimes, it may be interessant (and perhaps easier and faster) to develop web-apps instead of native mobile apps. But the main issue is about the appearance problem. Nowadays, all those problems are minimized with html5, css3 and (eg. jQuery) JS libraries.

Today I’m not presenting any own source code, I just share a jQuery plugin that I found on web, to avoid appeareance problems on web-apps (at least in selectors). Their site is Mobiscroll, and you can find some sampleson their demo page . With that plugin, you can present simple date (or other selector) input forms, looks like:


Android system.


iOS system.


Or even HTC Sense.

And of course, as always with jQuery usage ease and MIT license.

Source: Mobiscroll developer by Acid Media.

Read More

Differences on DOM javascript setAttribute method between IE & other browsers.

Because a project of my job, I’m working in a dinamic creation of a webpage using Javascript to handle DOM.

Today I realised, that my original code (according to W3C) does not work properly with any version of IE, so for example, originally to create a input element I did:

1
2
3
4
5
6
7
8
9
// code
INPUTELM = document.createElement('input');
INPUTELM.setAttribute('name', 'codes[]');
INPUTELM.setAttribute('type', 'text');
INPUTELM.onkeyup = function(){ChangeSelectArticleByValue(this.value,'article' + (num_linies-1))}
INPUTELM.setAttribute('class', 'boxes');
INPUTELM.setAttribute('id', 'code' + (num_linies-1));
INPUTELM.setAttribute('tabindex',tabIndex);
// more code

The class attribute was not set, neither tabindex. After searching for a while I found that I might use (new methods below each one, lines 7 and 10)

1
2
3
4
5
6
7
8
9
10
// code
INPUTELM = document.createElement('input');
INPUTELM.setAttribute('name', 'codes[]');
INPUTELM.setAttribute('type', 'text');
INPUTELM.onkeyup = function(){ChangeSelectArticleByValue(this.value,'article' + (num_linies-1))}
INPUTELM.setAttribute('class', 'boxes');
INPUTELM.className= 'boxes'; // ADDED LINE
INPUTELM.setAttribute('id', 'code' + (num_linies-1));
INPUTELM.setAttribute('tabindex',tabIndex);
INPUTELM.tabIndex = tabIndex; // ADDED LINE

So mainly it seems that we might:

  • Use setAttribute for all most browsers, and the property for IE. Each browser will execute their code and avoid the other one.
  • To set class, use className because “class” is a JS reserved word.
  • Note uppercase in two or more words attributes.

I will edit this post if I deep on this.

 

Read More

iOS: How to open links externally with Safari from an app with an embedded webview?

Imagine you have an application which consists of an embedded webview that opens few local HTML pages. Perhaps, you will have one or more links which redirect the user to an external webpage, but if you do that, the webview will load the external page, and the user swill “miss” the application and this may confuse them.

What users expect is the external web page to open in a new window. HTML or Javascript is not enough to do that, but don’t panic, just add these few lines to your xcode project:
In the webview controller, inside the viewDidLoad() function:

webView.delegate = self;

Now just add these function in the controller as well:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:
(NSURLRequest *)request navigationType:(UIWebViewNavigationType)
navigationType;
{
	NSURL *requestURL =[[ request URL ] retain ];
	if (([ [ requestURL scheme ] isEqualToString: @"http" ])
	&& (navigationType == UIWebViewNavigationTypeLinkClicked) )
	{
		return ![[ UIApplication sharedApplication ]
		openURL: [ requestURL autorelease ]];
	}
	[requestURL release];
	return YES;
}

That will handle the links contained from your html documents in your webview, and will force Safari to open the ones which start with “http”.

Tip: If you want to do the same with links beginning with another scheme URI like mailto, skype… just add it in the “if” condition list.

Read More

iOS: How to configure an app for Ad Hoc distribution

How you have to configure an app for Ad Hoc distribution, and what do you need? Well, with that problem, I start my blog.

It’s not a taboo, that ‘s probably more confusing the way to send app’s to the appstore than even the objective-c language. Those days on my job, I had to deal with the common problem of testing an app with some devices that cannot be connected directly to the developer’s computer, so also as a self-guide for the next time, I begin with that.

First of all, I base my explanation with the Xcode version 4.2 and having a valid Apple developer license.

Creating the app ID and the provisioning profile

Log in with your development username and password to developer.apple.com member center, and go to the Provisioning portal.

I guess you have your development & distribution certificate, if not, in their related menu options, there’s explained how to get one. Then you must choose the App ID’s option, and add a new one*:

*In my case I’m not creating a new one, I’m using the Xcode: Wildcard AppID that’s managed by Xcode.

After that, go to the Provisioning option, and the Distribution tab. Add a new one.
Then be sure to check Ad Hoc and write a custom Profile name. Choose the right App ID (the one you created in the previous step) and check the devices where you want to test the app.

After that, download the Provisioning Profile and keep it in a known place.

Importing the Provisioning Profile to Xcode and configuring app.

Now, left the developer.apple.com, and open the project with Xcode. Go to the organizer (Window > Organizer). Then drag the Provisioning profile you created and downloaded to the Provisioning profiles tab.

Now close the organizer, and highlight the project. Choose the info tab (at the top) and duplicate one of two current configurations, and rename it, for example as Ad Hoc Distribution.

Choose the target (below the project), Summary tab and check Enable Entitlements (just do that, if your project need it, using iCloud for example), a new file project.entitlements will be created (look at the project tree). This file must look like “$(TeamIdentifierPrefix)<project bundle identifier>”. If it’s not the case, fix them. I cannot explain more on this, because I never used it.

In the Build settings tab, ensure that the value VALID_ARCHS is set to armv6 armv7. Then sign the code. In apple documentation, it seems that where on image below appears iPhone developer, it should be a dropdown list with the provisionings, but just let as shown in image.

In the case you use entitlements, it the different value should be the same as the entitlements file name.

Finally, you just need to fill the Bundle identifier with the same App ID (without the alphanumeric prefix), for example com.albercasadessus.helloworld.

That’s all. Now you just need to build and archive. First of all, change the target to iOS Device instead of Simulator (in the dropdown nex to the Run and Stop button). If not appears iOS Device, just disconnect any apple device connected. After that:
Product > Clean.
Product > Build.
Product > Archive.



Organizer
will appear after do Archive. Choose iOS App Store PAckage (.ipa), and in the dropdown, select the provisioning profile you downloaded and created before!

A file will be generated. Save together with the provisioning profile on finder. Then send it to the beta-testers (the devices you selected when you created the provisioning profile)

Install the app for testing in a device.

That’s the easiest part. Just follow this steps:
1- Connect the device in a computer with iTunes.
2- Drag the provisioning profile (file with . mobileprovision extension) on iTunes.
3- Double click the file app.ipa (or <whatever>.ipa). That will make the app appears on iTunes
4- Now just syncronize the device, and the app will be installed.

 

Read More