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 10 of 10
  1. #1
    EGS
    EGS is offline
    New Coder
    Join Date
    Feb 2008
    Location
    New Jersey
    Posts
    61
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Arrow [Request] Help to make a simple PHP script..

    Hi..

    I need help making a PHP script. Can anyone help me or provide code?

    It is very simple! I just cannot figure it out though, I know how to code an upload script for files or images, but cannot do this.

    Basically I need a script that adds inputted parts in a URL.

    Basically, users will use a form and enter two pieces of data in a form, and hit submit. This data will go into a URL that I designate in the script and the user will then, after hitting submit, go to that website.

    For example, I will be having two text boxes that people will need to fill in two pieces of data for. Someone decides to enter "cat" for the first box and selects "house" in the drop down menu next to it in the form.

    The designated URL I will be choosing is, for example, cathouse.com/{php-1}-{php-2}-information.html

    So the {php-1} will pull the information submitted from the first text box and the {php-2} will pull the information from the drop down menu and automatically input it the designated URL and thus direct/redirect the user after the user hits the submit button to that URL.

    Please help me and provide code for this? It will also help me learn a lot about PHP. I know this is going to be done through echoes, but the whole redirection part or whatever is the part I need to do..

    Thanks.

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts
    create a URL in a variable, then use:
    PHP Code:
    header("location: $url"); 
    that will redirect the user.

  • Users who have thanked idalatob for this post:

    EGS (03-26-2008)

  • #3
    EGS
    EGS is offline
    New Coder
    Join Date
    Feb 2008
    Location
    New Jersey
    Posts
    61
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by idalatob View Post
    create a URL in a variable, then use:
    PHP Code:
    header("location: $url"); 
    that will redirect the user.
    Thank you for that. But how will I create the form for the variables to create $url?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Here is the form ...

    <form action="goto.php" method="post">
    URL1: <input type="text" name="url1" value=""><br>
    URL2: <input type="text" name="url2" value=""><br>
    <input type="submit" name="submit" value="Goto URL">
    </form>

    Here is the PHP script called "goto.php"
    PHP Code:
    <?php
    // Get variables from the form
    $url1=$_POST['url1'];
    $url2=$_POST['url2'];

    // Build the URL
    $goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";

    // Check if it exists ... go there only if it exists.
    if (file_exists($goto)) {
    header ("location: $goto");
    }
    else{
    // It does not exist, so go back to form
    header ("location: index.php");
    }
    ?>

  • Users who have thanked mlseim for this post:

    EGS (04-08-2008)

  • #5
    EGS
    EGS is offline
    New Coder
    Join Date
    Feb 2008
    Location
    New Jersey
    Posts
    61
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    Here is the form ...

    <form action="goto.php" method="post">
    URL1: <input type="text" name="url1" value=""><br>
    URL2: <input type="text" name="url2" value=""><br>
    <input type="submit" name="submit" value="Goto URL">
    </form>

    Here is the PHP script called "goto.php"
    PHP Code:
    <?php
    // Get variables from the form
    $url1=$_POST['url1'];
    $url2=$_POST['url2'];

    // Build the URL
    $goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";

    // Check if it exists ... go there only if it exists.
    if (file_exists($goto)) {
    header ("location: $goto");
    }
    else{
    // It does not exist, so go back to form
    header ("location: index.php");
    }
    ?>
    Doesn't work I'm afraid..

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by EGS View Post
    Doesn't work I'm afraid..
    Then give some information... like what the errors are.

  • #7
    EGS
    EGS is offline
    New Coder
    Join Date
    Feb 2008
    Location
    New Jersey
    Posts
    61
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    Then give some information... like what the errors are.
    It just refreshes to the page that the form is on, it doesn't go to the URL.

    I am using the code and form on the same page, as there is no need for two files when the form can just post to itself..

    Not working though.

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    It's possible the server doesn't have fopen wrappers on. Use the filename instead of the url if the file is on the same server(you should be anyway). Verify this by using var_dump() or checking the phpinfo():
    PHP Code:
    $goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";
    var_dump(file_exists($goto));
    exit; 
    Place that before the if/else with the header() function calls(the $goto line I gave was just for reference, you don't need to change it).

  • #9
    EGS
    EGS is offline
    New Coder
    Join Date
    Feb 2008
    Location
    New Jersey
    Posts
    61
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    It's possible the server doesn't have fopen wrappers on. Use the filename instead of the url if the file is on the same server(you should be anyway). Verify this by using var_dump() or checking the phpinfo():
    PHP Code:
    $goto="http://www.cathouse.com/".$url1."/".$url2."/information.html";
    var_dump(file_exists($goto));
    exit; 
    Place that before the if/else with the header() function calls(the $goto line I gave was just for reference, you don't need to change it).
    File doesn't exist on same server, basically lets people go to URLs...

    My server does support it, I've had a proxy on it before though..

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    So did you try that code I posted?


  •  

    Posting Permissions

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