6

I am new to php and handling server side.

I have a domain "www.example.co.in". And another addon domain "www.example.com". I have created a new folder "www.example.com" at the root folder(public_html) of "www.example.co.in" cpanel hoisting.

public_html-> www.example.com

Now I have written an api in php fetch_data.php which looks like the below format:

<?php 
    if(isset($_POST['test'])){
        // db connection
        // retrieve data from database
    } else {
        echo("error")
    }  
?>

Now if I put this file inside www.example.com i.e. public_html-> www.example.com -> fetch_data.php

isset($_POST['test']) is returning false.

And if I put the same file inside the root folder i.e. public_html-> fetch_data.php

I am able to fetch the data.

Note: I am using the same input.

URL: http://www.example.com/fetch_data.php <- isset not working

URL: http://www.example.co.in/fetch_data.php <- isset working

I am testing the above mentioned apis using the REST Easy extension of firefox. Rest Easy by nathan-osman

The actual path of my cpanel:

home/www.example.co.in/public_html/

And the addon domain:

home/www.example.co.in/public_html/www.example.com/

LF00
  • 27,015
  • 29
  • 156
  • 295
OnePunchMan
  • 720
  • 15
  • 33
  • In Cpanel, www.example.com should be an add-on domain with a root directory specified. That root directory should be the subdirectory that you created and put your php file.. – Alan Dec 09 '16 at 17:56
  • @Alan yes, you are right. but I am using the same code, same input and pointing to the same db. I just change the url in order to access those php files. So, what might be the issue here? – OnePunchMan Dec 10 '16 at 09:57
  • can you dump the value of $_REQUEST ? – Saeed.Gh Dec 25 '16 at 00:03
  • from where you are accessing this and what is the response you are getting . Is it 404 ? – Aabir Hussain Dec 27 '16 at 09:23
  • I am getting the response, meaning it's returning whatever I have written in the else part. – OnePunchMan Dec 27 '16 at 09:26
  • If you are reaching that file. Can you show the code from where you are making the request – Aabir Hussain Dec 27 '16 at 10:34
  • @AabirHussain Its not through code, through **REST Easy extension of firefox**. I can reach the same file kept at two different locations. As mentioned in the question, with same input, one is giving me the if part(original domain) and the other else part(addon domain). – OnePunchMan Dec 27 '16 at 10:38
  • @Saeed.Gh How should I write the code for dump $_REQUEST in php? – OnePunchMan Dec 27 '16 at 10:40
  • @OnePunchMan if you are getting IF for one request and else for second one then the problem is with your request. Thats why I am asking to show request code. Make sure, you are making a POST request with atleast one value set for test. – Aabir Hussain Dec 27 '16 at 10:45
  • I told you, there is no code. I am just using the UI tool with same input. I tested it by just changing the address, original domain and addon domain. I am able to reach both the location. – OnePunchMan Dec 27 '16 at 10:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/131574/discussion-between-aabir-hussain-and-one-punch-man). – Aabir Hussain Dec 27 '16 at 11:09
  • @OnePunchMan var_dump($_REQUEST); – Saeed.Gh Dec 27 '16 at 11:45

3 Answers3

2

add this to you virtual host:

ServerName example.com
ServerAlias www.example.com www.example.co.in example.co.in
LF00
  • 27,015
  • 29
  • 156
  • 295
1

Godaddy provides shared hosting where most of setup is already done. Apache setup is also done by hosting partner.

You need to set different document_root for different domains. Check Godaddy Documentation.

anwerj
  • 2,386
  • 2
  • 17
  • 36
1

I think, you have chosen a single domain hosting plan and just parked an add-on domain. You should have multi domain hosting in order to host two or more domains in the same server. Since godaddy is a shared hosting service you don't have access to apache configuration files.

Instead check amazon aws micro instance which is free and you can play around a lot with it.

Jagadesha NH
  • 2,529
  • 2
  • 23
  • 41