SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, found this on PHP.net for to go to last page:
    $HTTP_REFERER
    But it doesn't work. Look at this:
    <?php
    if($email=="") {
    $HTTP_REFERER;
    exit();
    }

    And I would like to send a variable with it.How should this look like?
    Thanx, alex

  2. #2
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think you have to use the header-localtion thing...
    Nearly 7 years old!

  3. #3
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well If I understand this you want a link to go back to the last page you vistited?

    Then you could use this:
    PHP Code:
    <?
    echo "<a href=\"$HTTP_REFERER\"><< Back</a>";
    ?>

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you may need to declare it as a variable..

    PHP Code:
    <?php
    $goback 
    getenv['$HTTP_REFERER'];

    echo(
    "<a href=\"$goback\">Go Back</a>");
    ?>
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just so you know, here's the header thing AlexC mentioned:

    PHP Code:
    <?php
    header
    ("Location: $HTTP_REFERER");
    ?>
    Note: you cannot output any text (even whitespace) before making use of the header() function...doing so will produce an error.

    Oh, and if you want to simulate the browser's back button, you can try this (I use it fairly often...I find PHP's HTTP/enviromental variables will fail on me when I use Opera):

    Code:
    <a href="javascript:history.go(-1);">Go Back</a>

  6. #6
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanx, but that's not exactly what I need. I will do this:
    I have a form, where I put something like this at the end of each field:
    <?php
    if ($unvalidemail) {
    echo ("you must enter an valid e-mail")
    }

    and than on the page where I send my form to, I will put something like this on the top:
    if $email=() {
    load the form again with the variable $unvalidemail, so that
    the user will see the error message behind the text field.
    So it should be a function to automatically load the last page ( the form ).
    Ore can I put this all on the form page itself with an PHP_SELF ? And if so ,how?
    Thanx, Alex

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, putting it all in the same page with $PHP_SELF is the most common practice. It definitely makes this kind of validation script easier to write. Here's one possible structure for the script:

    PHP Code:
    <?php
     
    if ($submit) { // Form submitted...
       
    $validinput true;
       if (...
    bad email...) {
         
    $validinput false;
         
    $emailerror "Bad email address...";
       }
       if (...
    bad user id...) {
         
    $validinput false;
         
    $useriderror "...";
       }
       ...
       if (
    $validinput) {
         
    // Process input
       
    } else displayForm();
     } else 
    displayForm();

     function 
    displayForm() {
       global 
    $email$emailerror$userid$useriderror, ...;

       
    // HTML for form and errors here.
     
    }
    ?>
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  8. #8
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One problem with PHP_SELF - on the windows box I use for writing and testing everything (i.e my laptop) any URL with PHP_SELF in it turns into something along these lines:

    http://localhost/php.exe/script.php (I forget the exact format but php.exe is in there)

    It still works, but it's a horribly ugly URL.

    Any ideas how I can stop it doing that? I'm using Apache + PHP 4.0, and PHP is NOT installed as a module.

  9. #9
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That would seem to be because you are running the CGI version of PHP. You should really set up PHP as an ISAPI or Apache module so that you can make full use of its features. It's never a good idea to have such a big discrepancy between your development and deployment servers if it can be avoided.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  10. #10
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Point taken

    /me hurries off to dig up a tutorial on installing PHP on windows as an Apache module

  11. #11
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The firepages package (at www.firepages.com) and other similar packages provide a single install for Apache/PHP/MySQL/phpMyAdmin/etc. There have been several discussions about these in the forums... They'd probably save you some trouble.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  12. #12
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great site that (I've recommended it to other people) but I'm gonna have a go at installing it myself - good experience for setting up real 'live' servers. Plus I can always fall back on FirePage if it all goes horrible wrong...

  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PLus firepages package installs PHP to run in CGI mode as well. Best to do like you said Skunk, install them all yourself, it will only prove to be more valuable in the future. If yo get stuck do a search on this form for a thread entitled php4apache.dll in this thread there is a url to a page that gives the skinny on getting PHP installed as apache module on Windows platforms. It was a life sver for me and may prove helpful for you as well.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #14
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Kevin, it's me again. I
    I'm sorry, but it doesn't work as it should. Would you mind to have a short look. It's would you postet 2 hours ago, but I'm not sure about the way I did it.

    <?php
    if ($submit) { // Form submitted...
    $validinput = true;
    if ($email=="") {
    $validinput = false;
    $emailerror = "Bad email address...";
    }
    if ($uid=="") {
    $validinput = false;
    $useriderror = "Bad User-ID..";
    }

    if ($validinput) {

    //What do I have to write here ??


    } else displayForm();
    } else displayForm();

    function displayForm() {
    global $email, $emailerror, $uid, $useriderror;



    }
    ?>

    <html>
    <head>
    <title>Untitled Document</title>

    </head>

    <body bgcolor="#FFFFFF">
    <form method="post" action="connect5.php">
    <p>
    <input type="text" name="email"><?=$emailerror?>
    </p>
    <p>
    <input type="text" name="uid"><?=$useriderror?>
    </p>
    <p>
    <input type="submit" name="submit" value="Submit">
    </p>
    </form>
    </body>
    </html>

    Thanx for your patience, Alex

  15. #15
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You put whatever you want to do with the data there, In that space where you write
    //What do I have to write here ??
    That is where you would put the code that would process the data entered if there were no errors,

    except there a few errors in your code and it should look like

    <?php
    if ($submit) { // Form submitted...
    $validinput = true;
    if ($email=="") {
    $validinput = false;
    $emailerror = "Bad email address...";
    }
    if ($uid=="") {
    $validinput = false;
    $useriderror = "Bad User-ID..";
    }

    if ($validinput) {

    //What do I have to write here ??


    }
    else {
    displayForm();
    }

    }
    else {
    displayForm();
    }
    function displayForm() {
    global $email, $emailerror, $uid, $useriderror;



    ?>

    <html>
    <head>
    <title>Untitled Document</title>

    </head>

    <body bgcolor="#FFFFFF">
    <form method="post" action="<? print $PHP_SELF; ?>">
    <p>
    <input type="text" name="email"><?=$emailerror?>
    </p>
    <p>
    <input type="text" name="uid"><?=$useriderror?>
    </p>
    <p>
    <input type="submit" name="submit" value="Submit">
    </p>
    </form>
    </body>
    </html>

    <?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  16. #16
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, it's working now. But two problems remain.
    1. What do I have to write in this line if I want the data to be send to another page for to be processed?
    ( Ore do you think it doesn't make sence to have one form page and another page for to process the inputs)
    2. When somebody enters something wrong, than the form is load again, but all the fields are blank. So is it possible to save all the inputs?
    Thanx, Alex

  17. #17
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change your html form to this
    <html>
    <head>
    <title>Untitled Document</title>

    </head>

    <body bgcolor="#FFFFFF">
    <form method="post" action="<? print $PHP_SELF; ?>">
    <p>
    <input type="text" name="email" value="<?=$email?>"><?=$emailerror?>
    </p>
    <p>
    <input type="text" name="uid" value="<?=$uid?>"><?=$useriderror?>
    </p>
    <p>
    <input type="submit" name="submit" value="Submit">
    </p>
    </form>
    </body>
    </html>



    Why do you want to send it to another page just process the form right on the smae page.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  18. #18
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    PLus firepages package installs PHP to run in CGI mode as well.
    Wow, I didn't know that! That's a pretty big failing... Do any of the other bundles install it as an Apache module?
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  19. #19
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just correcting Freddy's last code listing (he forgot to close the last set of braces):

    PHP Code:
    <?php 
      
    if ($submit) { // Form submitted... 
        
    $validinput true
        if (
    $email=="") { 
          
    $validinput false
          
    $emailerror "Bad email address..."
        } 
        if (
    $uid=="") { 
          
    $validinput false
          
    $useriderror "Bad User-ID.."
        } 

        if (
    $validinput) { 

          
    // Process the submission here.

          //...
        
    } else displayForm(); 
      } else 
    displayForm();

      function 
    displayForm() { 
        global 
    $email$emailerror$uid$useriderror
        
    ?> 

    <html> 
    <head> 
    <title>Untitled Document</title> 

    </head> 

    <body bgcolor="#FFFFFF"> 
    <form method="post" action="<?=$PHP_SELF?>"> 
    <p> 
    <input type="text" name="email" value="<?=$email?>"><?=$emailerror?> 
    </p> 
    <p> 
    <input type="text" name="uid" value="<?=$uid?>"><?=$useriderror?> 
    </p> 
    <p> 
    <input type="submit" name="submit" value="Submit"> 
    </p> 
    </form> 
    </body> 
    </html> 

        <?php
      
    }
    ?>
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  20. #20
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, thanx to freddydoesphp, it works.
    Alex

  21. #21
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I noticed that thanks Kevin, I figured since he didn't say he got a parse error on the last line of his script, in his last post, I figured he had figured that one out.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  22. #22
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Me again.
    I want to put the form-process-staff on another page, as I have problems when I write it all in the same page. If it is all together on one page, I have two html-parts. But in the WYSIWHG-Modus of Dreamweaver I can just see one of it, so I can not make a design for the second one ( ore not a good design). That's why I would like to link it to another page. Or is there any better way.
    ( Sorry for all this beginner-problems )
    Alex

  23. #23
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Design the second file individually, then include it in your first file where you need it with:

    Code:
    include("secondfile.php");
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •