473,795 Members | 2,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URL of Referring html Document

Hi there, I am using this code to retrieve the current URL:

function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? ''
: ($_SERVER["HTTPS"] == "on") ? "s"
: "";
$protocol = strleft(strtolo wer($_SERVER["SERVER_PROTOCO L"]), "/").$s;
$port = ($_SERVER["SERVER_POR T"] == "80") ? ""
: (":".$_SERVE R["SERVER_POR T"]);
return
$protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}

which returns the URL of the current PHP script.

But, I would like it to return the URL of the html page that preceeded
this script.

I mean, I have a some html pages with some photos. I have a form that
allows users to enter an email address that will then send the link of
that html page to the email address used.

When I use the above it only shows the address of the page that
executed the command, not the original html document.

Can this even be done?

Thanks,

Peter.

May 12 '06 #1
7 2589
Peter wrote:
But, I would like it to return the URL of the html page that preceeded
this script.


Look at $_SERVER['HTTP_REFERER'] (sic). But you can't trust it because it
comes from the browser, and not all browsers will set it.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 12 '06 #2
Nice one, thanks a lot. I'll check this out.

Pete.

May 12 '06 #3
Yep, works well, thanks. I tested on IE6, FF1.0.4 and Opera8.01 and
they all handle the HTTP_REFERER function.

May 12 '06 #4
NC
Peter wrote:

I am using this code to retrieve the current URL:

function selfURL() { .... }

which returns the URL of the current PHP script.
Why? What's wrong with $_SERVER['SCRIPT_URI']?
But, I would like it to return the URL of the html page
that preceeded this script.


That would be $_SERVER['HTTP_REFERER'].

Cheers,
NC

May 12 '06 #5
>Yep, works well, thanks. I tested on IE6, FF1.0.4 and Opera8.01 and
they all handle the HTTP_REFERER function.


Test it with firewalls in operation and you'll notice that HTTP_REFERER
can be deleted or faked. Further, there's a good chance a Windows
user won't be able to turn off that operation in the firewall even
if they wanted to.

Gordon L. Burditt
May 12 '06 #6
Hi NC, I tried the $_SERVER['SCRIPT_URI'] but it returns NULL. E.g I
have an html page with a form like this:

<form action="refer.p hp" method="post">
<p>First Name</br><input type="text" name="name" size="20"
maxlength="40"/></p>
<p><input type="submit" name="submit" value="Send Message"/></p>
</form>

And then this is my php code:

<?php
$refer = $_SERVER['SCRIPT_URI'];
echo $refer;
?>

But it comes back blank.

I would like it to return the full html URL like the HTTP_REFERER does
but seems that it is not to be relied on.

I think it will be best to use a hidden form on each page that contains
the URL and the just get this.... for reliability.

It's just that I have to then edit each page individually to add the
hidden value.

Thanks a lot though!

Pete.

May 13 '06 #7
Peter wrote:
Yep, works well, thanks. I tested on IE6, FF1.0.4 and Opera8.01 and
they all handle the HTTP_REFERER function.


Opera > Quick Prefs (F12) > Enable referer logging > Disable

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 13 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2325
by: Mike Brearley | last post by:
I was wondering if there was an easy way to have a form set up so that when the submit button is pressed, it goes to a confirmation page that contains a back button that goes back to the page that called the form. Basically, I'm looking at a scenario where 10 pages can call the form, but I want to user to be able to click the back button and be returned to the page they were on when they click on the link to the form. I thought that...
1
4768
by: Paul Lee | last post by:
Hi all, I'm trying to redirect users from a specific domain to one of my webpages. So, in my example, anyone accessing my index.html from the *btinternet.com domain (allowing for wildcards!) will be redirected to "update.htm". I'm not bothered what the referring webpage was, I'm just interested in anyone accessing my page from a certain domain
6
2887
by: jhallbox | last post by:
I am unclear how to test this object I'm sending to my function. It is a cell in a table and I simply want to know which row it is in. I am not a javascript programmer but a javascript cobbler, so illuminating me about the proper terminology would be greatly appreciated as well... The answer would allow me to simplify this (working) snippet. Thanks! _________________________________________________________________________ <script...
1
7877
by: VB Programmer | last post by:
With HTML, how do I get the value of a textbox in an ItemTemplate column within a datagrid? Simple shopping cart. For each row: 1 column is a textbox where they can enter the quantity. 1 column is an update button that calls UpdateCart.aspx passing it the CartId and Qty. Here's the HTML.... <asp:TemplateColumn>
3
1960
by: Filip Hendrickx | last post by:
Hi all. I am processing two documents with an XSLT, one is the input document, the other is loaded with the document() function in a variable $doc2. Inside a template that matches an element from $doc2, I need to check a value from the original input document. However, inside this template, the context is $doc2. What XPath expression should I use to refer to the input document? I've tried using /inputNamespace:inputElement, where...
5
3251
by: Christina | last post by:
I can't seem to find any reference for grabbing the title of the referring page, which I want to use for creating a link. i.e. document.write ("Our thanks to <a href='"+document.referrer+"'>" +referring page title +"<a>"). I have looked into using location.history also. This is probably a standard thing, but through all the forums and searches I only find a mishmosh of things referring to using frames, a different scripting language, etc....
3
3055
by: AviraM | last post by:
hello, this there any var to set the referring url manualy? is there anything at all so i can put in this var my own value, like when i paste an address on the firefox url and the page will set some value i want and it won't be blank thanks in advance.
2
2927
by: Celeste | last post by:
Hello, I'm trying to parse the referring url for google search terms so that when this page loads it will scroll to and highlight the search term(s). Should i be using document.referrer? Please take a look at my code and tell me what i'm doing wrong: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>highlight</title>
1
1219
by: beenben | last post by:
function calculate(){ number= parseInt(numberof); var price=4; total=price*number; alert("Your total is $" + total); return true; };
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.