Jump to content

Archived

This topic is now archived and is closed to further replies.

simonp

string question

Recommended Posts

Hi all,

I'm using the code below to check that a user is coming from the correct page before allowing them to go on.

It works for all but one page which passes a string in the URL, eg>

[a href=\"https://www.mywebsite.com/page4.php?name=william\" target=\"_blank\"]https://www.mywebsite.com/page4.php?name=william[/a] etc

How can I make the code check that the first part is correct but ignore everything after page4.php?

Cheers

Simon

[code]<?php
if ($_SERVER['HTTP_REFERER'] != "https://www.mywebsite.com/page5.php") {
        header("Location: https://www.mywebsite/page1.php");
    break; // END case 'OK'
}
?>[/code]

Share this post


Link to post
Share on other sites
Take a look at the [a href=\"http://www.php.net/parse_url\" target=\"_blank\"]parse_url()[/a] function.

Ken

Share this post


Link to post
Share on other sites
Hi folks,

I can get the whole URL using

[code]            $refurl = $_SERVER['HTTP_REFERER'];
            print_r(parse_url($refurl));[/code]

but how can I JUST get the scheme (https), the host and the path (ie withouth the query)?

Not too good with arrays.

Cheers

Share this post


Link to post
Share on other sites
Try:
[code]<?php
    $refurl = $_SERVER['HTTP_REFERER'];
    $parsed = parse_url($refurl));
    foreach($parsed as $key => $value)
          echo '$parsed[' . $key . '] = ' . $value . "<br>\n";
?>[/code]

The [b]scheme[/b] is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['scheme'][!--colorc--][/span][!--/colorc--]
The [b]host[/b] is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['host'][!--colorc--][/span][!--/colorc--]
The [b]path[/b] is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['path'][!--colorc--][/span][!--/colorc--]

You really should learn to use arrays as they are very powerful in PHP and other programming languages.

Ken

Share this post


Link to post
Share on other sites

×

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.