Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/9855-string-question/
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
Link to comment
https://forums.phpfreaks.com/topic/9855-string-question/#findComment-36698
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
Link to comment
https://forums.phpfreaks.com/topic/9855-string-question/#findComment-36711
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.