access # part of url via php

Discussion in 'PHP' started by stephan2307, Mar 2, 2011.

  1. #1
    I have a question,

    If I have a url like

    http://www.mysite.com/#123
    Code (markup):
    how can I access the 123 via php?

    is there a mod rewrite way so that i can change the url to

    http://www.mysite.com/?p=123
    Code (markup):
    Any help appreciated.

    Thanks
     
    stephan2307, Mar 2, 2011 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    no, it is best used in javascripts
     
    gapz101, Mar 2, 2011 IP
  3. NLZ13

    NLZ13 Well-Known Member

    Messages:
    166
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    113
    #3
    I tried this too once, but as far as i could get information you cannot access this with PHP.
    What are you trying to do? Maybe there is another solution
     
    NLZ13, Mar 2, 2011 IP
  4. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i also have the same question as i cannot call a variable from get that has a # starting such as domain.com?data=#function
     
    srisen2, Mar 2, 2011 IP
  5. Mike Griffiths

    Mike Griffiths Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's not accessible directly through PHP. The anchor isn't passed by the browser to the server in any headers.

    You could do it by using JavaScript to pass the variable through to a PHP page via AJAX, and then update some sort of session and reload the page. This isn't ideal though, and I wouldn't recommend it unless absolutely neccessary.
     
    Mike Griffiths, Mar 4, 2011 IP
  6. Aff_Fan

    Aff_Fan Member

    Messages:
    147
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    #6
    $domain = $_SERVER['HTTP_HOST'];
    $path = $_SERVER['SCRIPT_NAME'];
    $url = "http://" . $domain . $path;
    $mystring1="#";
    $s1=strpos($url,$mystring1);
    $p=substr($url,$s1+1); // may you need to correct here

    $p - your required 123
     
    Aff_Fan, Mar 4, 2011 IP
  7. FCM

    FCM Well-Known Member

    Messages:
    669
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    155
    #7
    Unless your page is going to be a single page application, or you are anchoring data - I wouldn't advise you to do that.

    This is an anchor, use javascript and pass the variable via ajax to the php component you are using. I suggest using jQuery

    Bennadel.com has some good videos on jquery and this style navigation.
     
    FCM, Mar 4, 2011 IP
  8. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Get $_SERVER['SCRIPT_NAME']
    and use reg_ex

    Make sure, your htaccess has allowed rewrite rule to specific file.
     
    eleetgeek, Mar 4, 2011 IP