Results 1 to 6 of 6

Thread: alter long url

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default alter long url

    when using php the url at times can get very long with all the variables visible. is there a way to clean it up using javascript or some other method? if so can someone point the direction where and how to search for this?

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

    Default

    You cannot use a different URL if you want to load the same page. That information is required, or the server will not know it.
    Additionally, you cannot use a fake URL in the address bar via Javascript, etc.

    So that means you will need to approach this a new way.

    There are a few options:

    1. Use shorter variables and better names.

    2. Find another way to store some of this: cookies, sessions, post variables... it depends on what your needs are, though having the information in the URL is usually the best since this allows for links and bookmarks, and it's the easiest to use.

    3. Use .htacess and mod_rewrite to switch the ugly URLs from pretty ones. This is a popular technique, but it can be VERY difficult. It requires the use of "regex" (regular expressions) which can be, at first, very daunting. You can find some examples by searching, but you may need to adapt them to your specific setup. Basically what mod_rewrite does is takes one request URL then tells the server to give the user a different page, and the user never knows the difference. As a simple example, you could do 2.php instead of 1.php, but as a more useful one you could do ?var=value to /value.
    I have created a tutorial/introduction to doing this while keeping most of the control in PHP. You may find this easier or harder than regular mod_rewrite, but I think it's easier (since I know PHP well, but not regex or .htaccess). It may help you.
    http://www.dynamicdrive.com/forums/s...ad.php?t=51923


    Obviously (3) will give you the most control, but (1) and (2) may help also and they are much easier.
    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

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    that was very helpful, how can you pass a variable using sessions? i am aware that in order to have a seeion you need to include
    session_start();
    at the top before anything else but then how can a variable from 1 page x-fer over to the next without the url?

  4. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    If I'm correct on this also, once you start the session and declare the variable like below it will stay in the session and you can call upon it on subsequent pages
    [PHP]
    $_SESSION['myusername'] = $myusername;[PHP]
    Then you can use something like this on other pages to show a Welcome and myusername
    PHP Code:
    <?php 
    if (isset($_SESSION['myusername'])){ 
     
    ?>
     Welcome, <?php echo $_SESSION['myusername']; ?>&nbsp;<a href='http://remotelystartedmn.com/logout.php'>Logout</a><br>
     <?php
     
    }
    else
    {
    }
    ?>

  5. #5
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    so then you would have to declare the variable on top, after session_start();
    using the tag?
    $_SESSION['someVar'] = $someVar;

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

    Default

    Correct. After session start just use $_SESSION like a normal array but it will remain the same between page loads. Note that this can be confusing with clicking "back" etc.
    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

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
  •