Jump to content

Capture referring url then create link based on it


sqc

Recommended Posts

Hello, newbie here.

 

Let’s say this url refers to my page:  www.referringpage.com/folder/abc123

 

(1) I want to capture the "abc123" part that comes after the last forward slash and assign it to a variable named "id"

 

(2) Then I want to create a clickable link:  www.mynewlink.com/folder/abc123

 

Probably pretty simple to the vets.  Thanks in advance!

 

Link to comment
Share on other sites

First of all, var_dump() doesn't return anything. So your $id will be null.

 

Secondly, parse_url() returns an array not a string. Did you look at the manual?

 

EDIT: Oops sorry, you're using a component flag, so it does return a string.

Edited by scootstah
Link to comment
Share on other sites

 

“Didn't work” is a bit vague.

<?php

$_SERVER['HTTP_REFERER'] = 'https://www.mynewlink.com/folder/abc123';

$url_path = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH);
$url_id = basename($url_path);

var_dump($url_id);

Thanks.  this returned:   string(6) "abc123"

 

If the actual refering page url was  www.referringpage.com/folder/abc123 how would I take what youve done but actually capture the url and then print the clickable link http://www.mynewlink.com/folder/abc123

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.