1
0
mirror of https://github.com/ovh/php-ovh.git synced 2023-11-05 03:20:26 +01:00
Signed-off-by: Vincent Casse <vincent.casse@corp.ovh.com>
This commit is contained in:
Vincent Casse 2016-01-13 17:41:33 +01:00
parent aded4f28f7
commit 42c0a43c4b
2 changed files with 27 additions and 23 deletions

View File

@ -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.

View File

@ -32,16 +32,19 @@ try {
// check if dns record are available
$recordIds = $conn->get('/domain/zone/' . $domain . '/record?subDomain='. $subDomain );
// 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['zone'] . PHP_EOL;
echo "We will delete field " . $record['fieldType'] . " for " . $record['subDomain'] . $record['zone'] . PHP_EOL;
$conn->delete('/domain/zone/' . $domain . '/record/' . $recordId);
}
}
}
// Now, we are ready to create our new redirection
$redirection = $conn->post('/domain/zone/' . $domain . '/redirection', array(