Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    TrainReq
    Guest

    header/ document.referrer

    I'd like to have a PHP page accessible only if the referrer comes from http://www.site.com/blah.html , if the referrer isn't /blah.html , it will header.location to another page that has an "Access Denied" error, and if the referrer is blah.html let all the PHP/HTML go through.. I was wondering if there is any way you can do that with javascript (with document.referrer) and set an if in the PHP , or do it with header Referrer.
    Last edited by TrainReq; 02-25-2007 at 08:55 PM.

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, you wouldn't be able to do that. PHP cannot use a javascript variable (such as document.referrer). Remember PHP (being a server side language) will run first, before any client side code.

    Try using HTTP_REFERER. See link below for more info.

    http://us2.php.net/reserved.variables

  • #3
    TrainReq
    Guest
    er.. ok.. i found out... now... how do I run it on " if(empty($_SESSION['id'])) " (more/less if the session is not there run this following code):
    Code:
    <?php
    if($_SERVER['HTTP_REFERER'] =="http://www.site.com"){
    CODE
    }else{
    header("location: http://google.com");
    }
    ?>

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i'm not sure if i follow? are you trying to see if a session variable is defined or not? or if its blank?

    if(isset($_SESSION['id']) || $_SESSION['id'] != ''){

    }

  • #5
    TrainReq
    Guest
    if there is no session in ID or if the session is expired, run the above query.

  • #6
    Regular Coder
    Join Date
    Jan 2006
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah if it is expired it will no longer be set.. just run the if statement i wrote above.

  • #7
    TrainReq
    Guest
    so I used

    PHP Code:
    <?php



    if(isset($_SESSION['id']) || $_SESSION['id'] != ''){

    if(
    $_SERVER['HTTP_REFERER'] =="http://www.site.com"){
    CODE
    }else{
    header("location: http://google.com");
    }

     
    ?>
    And the query doesnt work period now (while no session, of course)

  • #8
    Regular Coder
    Join Date
    Jan 2006
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i'm confused, are you saying its working how you want it now or its not?

  • #9
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    <?php

    session_start
    () //isnt this required at top of all pages within a session?

    if(isset($_SESSION['id']) || $_SESSION['id'] != ''){ //opens and doesn't close

    if($_SERVER['HTTP_REFERER'] =="http://www.site.com"){
    CODE
    }else{
    header("location: http://google.com");
    }

     
    ?>

  • #10
    Regular Coder
    Join Date
    Jan 2006
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i thought you only needed session_start() on the page thats setting the session variable. i could be wrong though.

  • #11
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts
    No, session_start() is required on any page using the session.
    session_start() can be used to start a new session, or continue from the current one


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •