Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP Redirect doesn't work - UPDATE: Safety of @extract($_POST);

  1. #1
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry PHP Redirect doesn't work - UPDATE: Safety of @extract($_POST);

    EDIT: Scroll down for a follow up problem related to the safety of @extract($_POST);

    Hi all,

    I set up a php redirect resulting from two dropdown select menus. Here is the code:

    Code:
    <?php
    	@extract($_POST);
    	$quickarchive_date = stripslashes($quickarchive_date);
    	$quickarchive_categories = stripslashes($quickarchive_categories);
    	if ( $quickarchive_categories == "C" && $quickarchive_date == "#" ) {
    		$url = "http://www.mysite.com/weblog/archive_2/";
    	} elseif ( $quickarchive_categories != "C" && $quickarchive_date == "#" ) {
    			$url = "http://www.mysite.com/weblog/archive_2/".$quickarchive_categories."/" ;
    	} else {
    		$url = "http://www.mysite.com/weblog/archive_2/".$quickarchive_categories."/".$quickarchive_date ;
    	}
    	header("HTTP/1.1 301 Moved Permanently"); 
    	header("Location: $url");
    ?>
    This doesn't work. What do I have to change in order to make it work and keep the same functionality.
    Thanks, dl33
    Last edited by dl33; 09-22-2007 at 10:35 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    @extract($_POST);
    Ugh! You might as well just have register_globals on!

    What do you mean by "doesn't work?"
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I think you could do that in html and it would be a little easyier in html..
    Hey new design new look, goto xudas for personal webdsign help.. (:

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

    Default

    Huh? No...


    Well, the code must be sent (using http headers) before any content on the page. Do you have any html output before that?

    Can you link us to the page?
    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

  5. #5
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The code above is the only code in the document. I know that it works as far as outputting §url, since I tried echoing it before I put the redirect statement in.
    However, as soon as I try redirecting using header(), it doesn't work, as in doesn't redirect me: The browser gives me a blank page (which makes sense, since the php code doesn't echo anything). Safari gives me the following response:
    Safari can’t open the page “http://URL/_archive_php_rewrite”. The error was: “bad server response” (NSURLErrorDomain:-1011) Please choose Report Bugs to Apple from the Safari menu, note the error number, and describe what you did before you saw this message.
    Sorry, but I am a complete PHP noob, so please take it easy with me...

    Judging from the comment about register globals, I assume that this script is not that safe: Is there a better way of doing what I want to do? Thanks...

    Oh and about doing this in html, I am not aware of it, please help me out. I know that one can redirect users in javascript, but I would like to stay javascript independed.

    This code is being created for a weblog archive. Users can use two drop-down lists to browse it: Unfortunately, the /?etc=bla syntax that classical forms use doesn't work with my publishing platform, so I have to rewrite it.
    Last edited by dl33; 09-22-2007 at 09:32 PM. Reason: Forgot something

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Your best bet would be to do the following:

    Code:
    <?php
    $quickarchive_date = stripslashes($_POST['quickarchive_date']);
    $quickarchive_categories = stripslashes($_POST['quickarchive_categories']);
    if ($_POST['quickarchive_categories'] == "C" && $_POST['quickarchive_date'] == "#" ) {
    $url = "http://www.squawkdesign.com/weblog/archive_2/";
    } elseif ( $_POST['quickarchive_categories'] != "C" && $_POST['quickarchive_date'] == "#" ) {
    $url = "http://www.squawkdesign.com/weblog/archive_2/".$_POST['quickarchive_categories']."/" ;
    } else {
    $url = "http://www.squawkdesign.com/weblog/archive_2/".$_POST['quickarchive_categories']."/".$_POST['quickarchive_date '];
    }
    header("Location: $url");
    ?>
    Not tested, but should work.
    Hope this helps
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Actually, I just found the answer myself: Since I am working with ExpressionEngine I HAVE to add exit; at the end of my code. Don't know why, but my code works now.

    However, I still have one more question regarding the safety of @extract($_POST);
    Anyone?
    Last edited by dl33; 09-22-2007 at 10:34 PM.

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by dl33 View Post
    I still have one more question regarding the safety of @extract($_POST);
    And your question is?
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How safe is it? And if it isn't safe, how can I make it safer?

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

    Default

    register_globals is on for many servers.

    The issue is fairly simple. POST, GET and COOKIE variables will then be real variables. In this case, just POST.
    ie, $_POST['whatever'] will set $whatever to the same value.

    The safety concern is that anyone could inject any variable they want with a custom form to the page.

    Using that means any variable can be set to something when the script starts. So if you check if a variable is set, and it is then through that, it will keep that value.

    for example, it could be a problem if you had:
    <?php
    if (isset($delete)) {
    unlink($delete);
    }
    ?>

    And they could delete any file on your server.

    But that is an extreme case. Only an issue if you have a vulnerability like that in the script.

    I'd recommend just using $_POST['name'], rather than $name.
    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
  •