dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Newbie having trouble directing to a URL based on user input.

Hybrid View

  1. #1
    Join Date
    Feb 2014
    Posts
    1

    Newbie having trouble directing to a URL based on user input.

    I am trying to re-direct users to specific URLs depending on their input from another page. Code listed below:

    <?php
    $user1=999;
    $user2=100;
    $user3=200;
    $url='http://www.espn.com';

    $account=$_POST["account"];

    if ($account==$user1)
    {
    header ('Location: /support.html');
    exit;
    }
    elseif ($account==$user2)
    {

    header('Location: /services.html');
    exit;
    }
    elseif ($account==$user3)
    {
    header('Location: /about.html');
    exit;
    }
    else
    {
    echo "this don't work";
    }
    ?>

    I have also tried ('Location: http://mydomain.com/about.html'); and to no avail.

  2. #2
    Join Date
    Feb 2014
    Location
    south africa
    Posts
    16
    two questions
    1) are you sure the code is executing
    Code:
    if ($account==$user1)
    {
      echo 'user1';
      exit;
    }
    elseif ($account==$user2)
    {
      echo 'user2';
      exit;
    }
    elseif ($account==$user3)
    {
      echo 'user3';
      exit;
    }
    else
    {
      echo "this don't work";
    }
    2) is error reporting on, if so are you getting any errors ?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,307
    Are you getting the "this doesn't work" message, or some other result? If you are getting that message, then it's time to do a var_dump of $_POST and see if 'account' is actually set in it, and what it's exact value is. (Maybe you should be using $_GET?)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    Join Date
    Feb 2014
    Location
    Viet Nam
    Posts
    33
    hi, you can remove the "exit" in command. No need it.
    If your value is the same 999, 100 , 200, it will redirect well. If not it shows "this don't work".

    Please post message error if you get......

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,307
    Looking back at this, did you mean to use that $url variable as part of the redirect?
    Code:
    header ('Location: $url/support.html');
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  6. #6
    Join Date
    Feb 2014
    Location
    south africa
    Posts
    16
    surreylee you haven't answered anyone yet, have you got this sorted, if so, please post the solution and mark the thread as resolved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles