> ## Documentation Index
> Fetch the complete documentation index at: https://help.trfyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Proxy Trfyx through PHP

> Proxy Trfyx analytics through a PHP application.

A PHP proxy can forward the tracker and event requests through your own domain.

<Steps>
  <Step title="Create a proxy endpoint">
    Create a route for `/script.js` that fetches and returns the Trfyx script:

    ```php script-proxy.php theme={"dark"}
    <?php
    header('Content-Type: application/javascript');
    header('Cache-Control: public, max-age=31536000');
    echo file_get_contents('https://app.trfyx.com/script.js');
    ```

    For events, forward the request body and relevant request headers to `https://app.trfyx.com/api/events`, then return Trfyx's response to the browser.

    <Warning>
      Your event endpoint must forward the original visitor IP. Do not replace it with only the IP of your PHP server.
    </Warning>
  </Step>

  <Step title="Update the tracker">
    ```html index.html theme={"dark"}
    <script
      defer
      data-website-id="YOUR_TRFYX_PROJECT_ID"
      data-domain="yourdomain.com"
      src="/script.js"
    ></script>
    ```
  </Step>

  <Step title="Verify installation">
    Open Developer Tools → Network and confirm the script and event requests use your domain. Then verify a new visit in Trfyx.
  </Step>
</Steps>

<Note>
  For most PHP sites, <a href="/managed-proxy">Managed Proxy</a> is simpler because it removes the proxy code and maintenance burden.
</Note>

## Next steps

<CardGroup cols={2}>
  <Card title="Goals" icon="bullseye" href="/goals" />

  <Card title="Funnels" icon="filter" href="/funnels" />

  <Card title="Managed Proxy" icon="shield-halved" href="/managed-proxy" />

  <Card title="Troubleshooting" icon="life-ring" href="/troubleshooting" />
</CardGroup>


## Related topics

- [Proxy Trfyx through your domain](/proxy-guide.md)
- [Proxy Trfyx through Nginx](/nginx-proxy.md)
- [Proxy Trfyx through Express](/express-proxy.md)
- [Proxy Trfyx through Flask](/flask-proxy.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.