From 42c0a43c4b110982a80adfd55ac16904d438f180 Mon Sep 17 00:00:00 2001 From: Vincent Casse Date: Wed, 13 Jan 2016 17:41:33 +0100 Subject: [PATCH] Fix typo Signed-off-by: Vincent Casse --- .../api_create_redirection.md | 9 ++-- examples/create-Redirection/apiv6.php | 41 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/examples/create-Redirection/api_create_redirection.md b/examples/create-Redirection/api_create_redirection.md index ac15d17..1605d1d 100644 --- a/examples/create-Redirection/api_create_redirection.md +++ b/examples/create-Redirection/api_create_redirection.md @@ -1,12 +1,12 @@ -How to get web hosting capabilities using php wrapper? ----------------------------------------------------- +How to create HTTP redirection using php wrapper? +------------------------------------------------- This documentation will help you to create an HTTP redirection from a subdomain to another domain. Following script include DNS record check and delete record if their will conflict with your redirection! ## Requirements - Having PHP 5.2+ -- Having a dns record at OVH +- Having a DNS zone at OVH ## Download PHP wrapper @@ -25,7 +25,8 @@ tar xzvf php-ovh-2.0.0-with-dependencies.tar.gz ## Create a new token -You can create a new token using this url: [https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*](https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*). Keep application key, application secret and consumer key to complete the script. +You can create a new token using this url: [https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*](https://api.ovh.com/createToken/?GET=/domain/zone/*&POST=/domain/zone/*&DELETE=/domain/zone/*). +Keep application key, application secret and consumer key to complete the script. Be warned, this token is only valid for this script on **/domain/zone/\*** APIs. If you need a more generic token, you may adjust the **Rights** fields at your needs. diff --git a/examples/create-Redirection/apiv6.php b/examples/create-Redirection/apiv6.php index c30ef07..1590aac 100644 --- a/examples/create-Redirection/apiv6.php +++ b/examples/create-Redirection/apiv6.php @@ -3,23 +3,23 @@ require __DIR__ . '/vendor/autoload.php'; use \Ovh\Api; // Informations about your application -$applicationKey = "your_app_key"; -$applicationSecret = "your_app_secret"; -$consumer_key = "your_consumer_key"; +$applicationKey = "your_app_key"; +$applicationSecret = "your_app_secret"; +$consumer_key = "your_consumer_key"; // Information about API endpoint used -$endpoint = 'ovh-eu'; +$endpoint = 'ovh-eu'; // Information about your domain and redirection -$domain = 'yourdomain.ovh'; -$subDomain = 'www'; // Here, the redirection will come from www.yourdomain.com -$targetDomain = 'my_target.ovh'; -$type = 'visible'; // can be "visible", "invisible", "visiblePermanent" +$domain = 'yourdomain.ovh'; +$subDomain = 'www'; // Here, the redirection will come from www.yourdomain.com +$targetDomain = 'my_target.ovh'; +$type = 'visible'; // can be "visible", "invisible", "visiblePermanent" // Field to set in case of invisible redirection -$title = ''; -$keywords = ''; -$description = ''; +$title = ''; +$keywords = ''; +$description = ''; // Get servers list $conn = new Api( $applicationKey, @@ -32,14 +32,17 @@ try { // check if dns record are available $recordIds = $conn->get('/domain/zone/' . $domain . '/record?subDomain='. $subDomain ); - foreach ($recordIds as $recordId) { - $record = $conn->get('/domain/zone/' . $domain . '/record/' . $recordId); - - // If record include A, AAAA or CNAME for subdomain asked, we delete it - if ( in_array( $record['fieldType'], array( 'A', 'AAAA', 'CNAME' ) ) ) { - - echo "We will delete field " . $record['fieldType'] . " for " . $record['zone'] . PHP_EOL; - $conn->delete('/domain/zone/' . $domain . '/record/' . $recordId); + // If subdomain is not defined, we don't want to delete all A, AAAA and CNAME records + if ( isset($subDomain) ) { + foreach ($recordIds as $recordId) { + $record = $conn->get('/domain/zone/' . $domain . '/record/' . $recordId); + + // If record include A, AAAA or CNAME for subdomain asked, we delete it + if ( in_array( $record['fieldType'], array( 'A', 'AAAA', 'CNAME' ) ) ) { + + echo "We will delete field " . $record['fieldType'] . " for " . $record['subDomain'] . $record['zone'] . PHP_EOL; + $conn->delete('/domain/zone/' . $domain . '/record/' . $recordId); + } } }