Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: how do I use this php redirect on my pages?

  1. #1
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default how do I use this php redirect on my pages?

    PHP Code:
    <?php
    $referrer 
    $_SERVER['HTTP_REFERER'];
    if (
    preg_match("/site1.com/",$referrer)) {
          
    header('Location: http://www.customercare.com/page-site1.html');
    } elseif (
    preg_match("/site2.com/",$referrer)) {
          
    header('Location: http://www.customercare.com/page-site2.html');
    } else {
          
    header('Location: http://www.customercare.com/home-page.html');
    };
    ?>
    The guestbook/comments script is here:
    http://www.web-user.info/enlighten/guestbook.php

    I put it on this page here:
    http://www.web-user.info/enlighten/index.php

    But when a person clicks on the post button you are taken to the guestbook page.When you use the back button,you see it posted your comment but took you away to the other page.

    CAn the above be made to redirect a person if they go to that comments page from the index page?
    Thanks,

    Bud

  2. #2
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    Would I put this on the guestbook.php page?
    PHP Code:
    <?php
    $referrer 
    $_SERVER['HTTP_REFERER'];
    if (
    preg_match("/index.php/",$referrer)) {
          
    header('Location: http://web-user.info/enlighten/index.php');
    } else {
          
    header('Location: http://web-user.info/enlighten/index.php');
    };
    ?>
    so if it comes from my index.php to that guestbook page it will automaticly go back to the page you were on(index.php)
    Thanks,

    Bud

  3. #3
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    Anyone?

    Do I have it right or wrong for what I want to do?
    Thanks,

    Bud

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't understand exactly what you want to do. The referrer isn't necessarily going to be accurate, but unless the user is intentionally tricking it (or the browser just doesn't send it!) it should be accurate.

    But this code will do exactly the same thing regardless of what the referrer was. Is that intentional?
    PHP Code:
     <?php
    $referrer 
    $_SERVER['HTTP_REFERER'];
    if (
    preg_match("/index.php/",$referrer)) {
          
    header('Location: http://web-user.info/enlighten/index.php');
    } else {
          
    header('Location: http://web-user.info/enlighten/index.php');
    };
    ?>
    Do you want users to be able to visit the page if they choose to? Or should it always redirect them? If so, just use a redirect:
    PHP Code:
    <?php
    header
    ('Location: http://web-user.info/enlighten/index.php');
    ?>

    Additionally: you do not need a semicolon to end an if statement's {}. So it's just if () {}, not if () {};.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    Hi Daniel,this page http://www.web-user.info/enlighten/index.php ,has the guestbook added by way of an php include like this
    <php>
    <?php include("guestbook.php"); ?>
    </php>

    My problem is that when you add a post and click on the 'post' button it takes you to the guestbook.php page and you have to
    use your back button to go back to the enlighten page you were at.

    I am trying to find a way for that to not happen and you stay on the enlighten.php page without leaving it and having to go back to it.

    I thought that using the previous script it would automaticly take people back to the enlighten.php but I don't know if that
    is the best way to do this or not.

    AS you might have noticed,sometimes things just don't work out right for me and adding something makes a bigger more difficult issue for
    me to figure out.

    Thankfully I can usually get help here where many of you are more versed with php,css,javascript and more sometimes-lol

    Anyway,adding the comment script(guestbook.php will eventually be renamed to comments.php and I will update that site with my humble
    muses and /or thoughts
    Thanks,

    Bud

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The redirect will work, but it will mean that no one can intentionally access that page either.

    Another way to do this that would be more reliable (rather than hoping that the referrer information is correct) would be to check if a certain value is $_POST is set.

    Try this:
    1) Add the following code to the very top of your comments page:
    <?php print_r($_POST); exit; ?>
    2) Submit a comment (the contents are irrelevant and won't be stored). Note: the page won't work any more, but that's temporary-- don't worry. ("exit;" ends execution of the script.)
    3) Look at the output of the $_POST array. Now, see which items were submitted and probably wouldn't exist if that page hadn't been submitted. If the only reason to use a form to submit to that page would be to submit this form, then it doesn't matter which one you pick. But it might be a little more reliable to pick something like $_POST['comment'] or another field that is probably only going to be found in your comments form.
    4) Remove that PHP code from the page and it will work again.
    5) Now, instead of using the referrer, use an if statement that checks if that value was submitted. Assuming 'comments', it would be the following code:

    PHP Code:
    <?php
    if (isset($_POST['comment'])) {
         
    header('Location: http://web-user.info/enlighten/index.php');
    }
    ?>
    Note: doing it this way will not allow users to stay on the comments.php page regardless of where they submitted from. So if you did want to allow them to post from the comments.php page, then you might want to rethink it.


    The solution would be to modify the comments script directly, but I don't know if you're comfortable doing that. An easy way is to include a form value in the script that then lets you know where to redirect them. But that can be a little tricky and would require editing the comment form.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    I would be willing to try anything but I would have to have help due to my limited Knowledge.

    It just figures that it is not an easy fix-my luck-lol

    If you have time,I would greatly appreciate the help.Or if not maybe someone else could help me.

    I intend on using this enlighten page to be a place I can present my opinion of things going on around home and anywhere else.

    Here is a text file of the guestbook
    http://www.web-user.info/enlighten/guestbook.txt
    Thanks,

    Bud

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Simple question: do you intend to allow users to ever use (=see) the comments page?
    If not, we can fix this and effectively remove the comments.php page from your system. (Using a redirect is easiest.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    No, I want the comments to be viewable for anyone.I can delete it if I don't want it there for some reason.

    But I think it would be cool fro anyone to see what others are posting.I want to use this like what you see all over the place online.I was working on using captcha to prevent security issues but it did not work so I figured to get it working otherwise and then I would tackle that part.
    Look at this page
    http://espn.go.com/nfl/story/_/id/83...a-vikings-pick
    down a little you can see 'ESPN Conversations'

    There you can add your comments or see all of them.This is what I want to do.

    I presume it is easier to ave them in view all the time verse having to click a button to add or view comments
    Last edited by ajfmrf; 09-02-2012 at 04:43 AM. Reason: add to post
    Thanks,

    Bud

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    What I'm asking is specifically about the comments.php page, not your index.php page. Do you want visitors to be able to access both, or just to view the comments (=discussion) on the index page (=not the comments.php page)?

    I really don't see the problem if you want the comments.php page to be visible. Why is it a problem that they are taken there when they post? If you want to permanently hide that page, you can do that with a redirect. But if you ever want them to be able to go there, why stop it from posting to that location?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Similar Threads

  1. PHP Redirect to www.
    By bluewalrus in forum Submit a DHTML or CSS code
    Replies: 6
    Last Post: 01-16-2012, 05:40 PM
  2. AnyLink works fine in pages, but not when those pages are in frames
    By jddela in forum Dynamic Drive scripts help
    Replies: 9
    Last Post: 03-11-2010, 04:27 AM
  3. PHP redirect help
    By taydu in forum PHP
    Replies: 4
    Last Post: 01-20-2008, 03:00 AM
  4. How to redirect to a HTTPS pages using DD script
    By ajaxdude in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 12-14-2006, 06:12 AM
  5. Redirect
    By Freeman in forum HTML
    Replies: 1
    Last Post: 12-13-2005, 05:46 PM

Bookmarks

Posting Permissions

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