Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:35:26+00:00 2026-06-12T02:35:26+00:00

My first post – firstly have to say that this site is great –

  • 0

My first post – firstly have to say that this site is great – it’s helped me many times without me ever having to ask a question. until now!

I run a webapp built using PHP / MySql / JQuery – absolutely everything is loaded / posted using JQuery AJAX – .load() and .post()
I have a number of different clients using this webapp, all with sumdomains of the form: client1.example.com, client2.example.com, while example.com is the advertising page.

When I had few clients I duplicated files – eg all necessary files for client1 would be in the folder example/client1/, while client 2 would get an exact copy at example/client2/
As my number of clients grew, I changed the structure so that clients shared common files – now AJAX calls would go from the folder /example/client1 to /example

This was working fine, as each clients subdomain was being redirected to the actual folder – eg client1.example.com is redirected to example.com/client1
This redirection was necessary so that AJAX calls would not fail due to browsers’ Same Origin Policy.

The problem that this causes is that common users between different clients would be able to see information from the other systems by changing their URL after login eg from example/client1 to example/client2, due to PHP sessions not being exclusive – each client was perceived as being on the same domain – example.com.
To get around this would be to use subdomains WITHOUT redirection – as this way PHP sessions would be exclusive.
Doing this causes all the AJAX calls to the parent folder to fail due to Same Origin Policy. 🙁

I have researched this cross domain AJAX request problem and tried a number of different solutions:

1) Tunneling using an iFrame – AJAX object in parent folder – AJAX calls succeed – but same problem occurs with PHP sessions – domain is perceived as example.com instead of client1.example.com

2) Trick of setting document.domain=example.com – doesn’t seem to work – this is an old outdated workaround I think

3) Setting PHP headers – header(‘Access-Control-Allow-Origin: ‘.$_SERVER[‘HTTP_ORIGIN’]);
Doesn’t work at all

I don’t want to use any different libraries for ajax calls.

Currently I’ve come up with two options:

1) Use the old method of duplicating files for each client, which I’d rather not do as it’s a waste of space and makes updating files a pain – I have to replace many files rather than just 1.

2) Use a PHP base file in each client directory which will receive all AJAX calls and then include the requested file from the parent folder. I’ve tested this and it seems to be working well – so this is the option I’d go with unless someone out there has a better solution?
To elaborate on this option:
Say I’m posting from a page in subdomain: http://client1.example.com
Rather than call $.post'(http://example.com/file.php’); (which will fail)
I call $.post(‘http://client1.example.com/base.php’,{target:’file.php’})
Then from base.php just include(‘../’.$_REQUEST[‘target’])

I’m quite happy going with option 2, but it just leads me to wonder is there a better way?
*Anyone else experience a similar problem?*

Cheers!
J

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:35:27+00:00Added an answer on June 12, 2026 at 2:35 am

    UPDATE

    So I went with option 2 – creating a base file in the subdomain which all AJAX requests call, and this base file then uses PHP includes to get the actual target file.

    Works very well and is excellent for restructuring the filesystem easily. Will use this method from now on for all future projects!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post and I my first experience with jquery. I have
first post here at this great website! I would like to reduce the amount
My first post on this site with huge hope:: I am trying to understand
first post ever here I'm trying to replicate this sort of JSON object so
My first post here - it's a great site and I will certainly do
first post so be nice :) My problem is that I have a class
this if my first post so please be gentle. I have an iOS 5
this is my first post so please show some understanding. I have some java
First post, have found many answers here, so hopes are high. The problem: Google
*First Post I have a JQuery error handler for my Ajax posts that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.