SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: PHP redirect

Hybrid View

  1. #1
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool PHP redirect

    Evening all...

    I am trying to set a session variable and redirect.

    If I link to language.php without the get variable in the URL the redirect works...otherwise I get a 404 and I don't know why

    PHP Code:
    $_SESSION['language_code'] = $_GET['language_code'];

    header'Location: http://www.spanishpropertymagazine.com/index.php' ) ; 
    spanishpropertymagazine.com/language.php?language_code=ES does't seem to work

    Halp me pleaz...

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you started your session?

    PHP Code:
    session_start();
    $_SESSION['language_code'] = $_GET['language_code'];

    header'Location: http://www.spanishpropertymagazine.com/index.php' );
    exit; 

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Ljubljana, Slovenia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ?language_code=ES

    should work!

    PHP Code:
    $language = isset($_GET['language_code']) ? $_GET['language_code'] : $my_default_language); 
    isset is checker!

    but you can use a mapper for the case if somebody trys:
    ?language_code=XXX
    Gregor Grajzar, web developer
    http://xweblabs.com
    http://grajzar.info

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure the file language.php exists in your root? If yes then off course it should work. Maybe you are supposing to redirect to index.php:
    PHP Code:
    header('http://www.spanishpropertymagazine.com/index.php?language_code=ES');
    exit(); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hadn't started the session in language.php but now I have and I still get the same problem

  6. #6
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It simply does nothing at all?
    Try using an HTTP sniffer to see what header your page is sending to the browser.
    Adscend Media,
    CPA Affiliate Network
    Ask me about our content gateway for monetizing content!

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Ljubljana, Slovenia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like it doesn't work at all --> means that error is some up the file (before your language trick);

    try first:
    PHP Code:
    <?
    echo "hello world";
    ?>
    $_GET is some basic function

    Look again your code looks like loooooop!
    Gregor Grajzar, web developer
    http://xweblabs.com
    http://grajzar.info

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Ljubljana, Slovenia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and another common thing with header
    spaces or html before <? will cause error header allready send!
    Gregor Grajzar, web developer
    http://xweblabs.com
    http://grajzar.info

  9. #9
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am still scratching my head with this. Infact I have gone off my food and i need a bath.

    linking to www.spanishpropertymagazine.com/language_set.php redirects to the default language (english) but linking to spanishpropertymagazine.com/language_set.php?language_code=es throws up the 404

    help please...

  10. #10
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Ljubljana, Slovenia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually went to see if the site exists. It does.
    Now do this quickly, since you have a live error:
    spanishpropertymagazine.com/language_set.php&language_code=ES

    I see here '&' and not '?'

    how the url should look
    index.php?myfirstvar=1&myseconvar=2

    so '?' after index.php mens -> here come my variables
    & after first variable means -> this is my next variable
    Gregor Grajzar, web developer
    http://xweblabs.com
    http://grajzar.info

  11. #11
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The links for your flag icons all have '&' instead of '?' in the address.

    For example:
    language_set.php&language_code=ES

    Once fixed it seems to work.

  12. #12
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gregor thanks dude,

    I thought it was going to be something complicated, but no just stupid.

    I am sure that if people one day look back over my threads on sitepoint they will say "bit of a thicky".

    Slovene isn't on of the languages I had planned for the site. If you want the language config file It could be there!!

    Thanks man

  13. #13
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Ljubljana, Slovenia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't bother about the past ;-) slovenia is no bigger than china town ;-) ok joke twice as big.

    best wishes for your site ;-)
    Gregor Grajzar, web developer
    http://xweblabs.com
    http://grajzar.info


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
  •