0

I have a php file test.php which generate an .ics file when I access it directly through the browser (www.mydomain.com/test.php). What I want is to create a feed URL for example www.mydomain.com/?something_id=true&userID_key=12345678 and when somebody will copy-paste the URL in browser to download the file.

Here is the content of the test.php file if matters:

function generate_ical(){
        /**
         * Get the event ID
         */
        $event_id = 2;
        /**
         * If no event ID or event_id is not an integer, do nothing
         */
        if ( !$event_id || !is_numeric( $event_id ) ) {
            die();
        }
        /**
         * Event information
         */
      //$event = get_event($event_id);
        $event = array(
            'event_name' => 'Test Event',
            'event_description' => 'This is a test event. This is the description.',
            'event_start' => time(),
            'event_end' => time() + 60*60*2,
            'event_venue' => array(
                'venue_name' => 'Test Venue',
                'venue_address' => '123 Test Drive',
                'venue_address_two' => 'Suite 555',
                'venue_city' => 'Some City',
                'venue_state' => 'Iowa',
                'venue_postal_code' => '12345'
            )
        );
        $name = $event['event_name'];
        $venue = $event['event_venue'];
        $location = $venue['venue_name'] . ', ' . $venue['venue_address'] . ', ' . $venue['venue_address_two'] . ', ' . $venue['venue_city'] . ', ' . $venue['venue_state'] . ' ' . $venue['venue_postal_code'];
        $start = date('Ymd', $event['event_start']+18000) . 'T' . date('His', $event['event_start']+18000) . 'Z';
        $end = date('Ymd', $event['event_end']+18000) . 'T' . date('His', $event['event_end']+18000) . 'Z';
        $description = $event['event_description'];
        $slug = strtolower(str_replace(array(' ', "'", '.'), array('_', '', ''), $name));
        header("Content-Type: text/Calendar; charset=utf-8");
        header("Content-Disposition: inline; filename={$slug}.ics");
        echo "BEGIN:VCALENDAR\n";
        echo "VERSION:2.0\n";
        echo "PRODID:-//LearnPHP.co//NONSGML {$name}//EN\n";
        echo "METHOD:REQUEST\n"; // requied by Outlook
        echo "BEGIN:VEVENT\n";
        echo "UID:".date('Ymd').'T'.date('His')."-".rand()."-learnphp.co\n"; // required by Outlok
        echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
        echo "DTSTART:{$start}\n";
        echo "DTEND:{$end}\n";
        echo "LOCATION:{$location}\n";
        echo "SUMMARY:{$name}\n";
        echo "DESCRIPTION: {$description}\n";
        echo "END:VEVENT\n";
        echo "END:VCALENDAR\n";
    }
Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
  • Welcome. What is your question? Does something not work? – brombeer Nov 28 '19 at 12:42
  • I don't know how to create the feed. As I said, the .ics file will be downloaded if I access the test.php file but I want to access the feed url and not the file. – dragos.nicolae Nov 28 '19 at 12:44
  • Show us the code you are working on and explain what the problem is. – MilanG Nov 28 '19 at 12:48
  • If you want to access `www.mydomain.com/?…`, then you need to handle this in your index document on the root level - because that is what the _empty path_ of this URL is pointing to. Apart from that - still unclear what your actual problem is. Why are you calling this a “feed URL” to begin with? Usually one would use that to refer to an RSS feed or something - but since you want this URL to trigger a download, that makes rather little sense to begin with. – 04FS Nov 29 '19 at 10:30
  • (Is your actual question _maybe_ how to get these parameter values from the URL, `?something_id=true&userID_key=12345678` - so that you don’t have to use hard-coded values in your code, but can pass these in dynamically? Well if you don’t know how to access query string / GET parameters yet - then now would be the time for you to go read up on that in a beginner’s tutorial.) – 04FS Nov 29 '19 at 10:31
  • Yes, that was my original question! Thank you! However, I managed to get this working using $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; and checking if '$string' is inside $url. If it is, call function() :). Thank you all anyway – dragos.nicolae Dec 05 '19 at 13:55

0 Answers0