Jump to content


Photo

string question


  • Please log in to reply
3 replies to this topic

#1 simonp

simonp
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 17 May 2006 - 02:00 PM

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

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


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 May 2006 - 02:40 PM

Take a look at the [a href=\"http://www.php.net/parse_url\" target=\"_blank\"]parse_url()[/a] function.

Ken

#3 simonp

simonp
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 17 May 2006 - 06:56 PM

Hi folks,

I can get the whole URL using

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

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

Not too good with arrays.

Cheers


#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 May 2006 - 07:40 PM

Try:
<?php
    $refurl = $_SERVER['HTTP_REFERER'];
    $parsed = parse_url($refurl));
    foreach($parsed as $key => $value)
          echo '$parsed[' . $key . '] = ' . $value . "<br>\n";
?>

The scheme is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['scheme'][!--colorc--][/span][!--/colorc--]
The host is in [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$parsed['host'][!--colorc--][/span][!--/colorc--]
The path 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users