Jump to content

mejpark

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Posts posted by mejpark

  1. Hello.

     

    I am building a basic link checker at work using cURL. My application has a function called getHeaders() that returns an array of HTTP headers:

     

    function getHeaders($url) {
    
        if(function_exists('curl_init')) {
            // create a new cURL resource
            $ch = curl_init();
            // set URL and other appropriate options
            $options = array(
                CURLOPT_URL => $url,
                CURLOPT_HEADER => true,
                CURLOPT_NOBODY => true,
                CURLOPT_FOLLOWLOCATION => 1,
                CURLOPT_RETURNTRANSFER => true );
            curl_setopt_array($ch, $options);
            // grab URL and pass it to the browser
            curl_exec($ch);
            $headers = curl_getinfo($ch);
            // close cURL resource, and free up system resources
            curl_close($ch);
        } else {
            echo "<p>Error: <a href=\"http://uk.php.net/manual/en/book.curl.php\">cURL<a/> is not installed on the web server. Unable to continue.</p>";
            return false;
        }
        return $headers;
    }
    
    print_r(getHeaders('mail.google.com'));
    

     

    Which yields the following results:

     

    Array

    (

        [ur1] => http://mail.google.com

        [content_type] => text/html; charset=UTF-8

        [http_code] => 404

        [header_size] => 338

        [request_size] => 55

        [filetime] => -1

        [ssl_verify_result] => 0

        [redirect_count] => 0

        [total_time] => 0.128

        [namelookup_time] => 0.042

        [connect_time] => 0.095

        [pretransfer_time] => 0.097

        [size_upload] => 0

        [size_download] => 0

        [speed_download] => 0

        [speed_upload] => 0

        [download_content_length] => 0

        [upload_content_length] => 0

        [starttransfer_time] => 0.128

        [redirect_time] => 0

    )

     

    (In case you're wondering, I changed the 'url' key to stop the forum interpreting it as BB Code)

     

    I've tested it with several long links, and the function acknowledges redirects, all apart from mail.google.com it seems.

     

    For fun, I passed the same URL (mail.google.com) to the W3C link checker, which produced:

     

    Results

    Links

     

    Valid links!

     

    List of redirects

     

    The links below are not broken, but the document does not use the exact URL, and the links were redirected. It may be a good idea to link to the final location, for the sake of speed.

     

    warning Line: 1 http://mail.google.com/mail/ redirected to

     

    https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=zpwhtygjntrz&scc=1&ltmpl=default&ltmplcache=2

     

    Status: 302 -> 200 OK

     

    This is a temporary redirect. Update the link if you believe it makes sense, or leave it as is.

     

    Anchors

     

    Found 0 anchors.

     

    Checked 1 document in 4.50 seconds.

     

    Which is correct, as the address above is where I am redirected to when I enter mail.google.com into my browser.

     

    What cURL options would I need to use to make my function return 200 for mail.google.com?

     

    Why is it that the function above returns 404 status code as opposed to 302 status code?

     

    TIA

  2. Hello,

     

    I am trying to redirect non-authenticated users to following url after login:

     

    http://xxxxxxxxxx.xxxx.xx.xx/dvd_process_script.php?response=accept&owner=3&dvdid=55&requester=9

     

    But the URL above doesn't seem to be stored in $_SERVER['REQUEST_URI'] upon requesting it.

     

    The general logic of my script is:

     

    <?php
    
    if(user is logged in) {
        
        // redirect to home page
    
    } else {
    
        // this block executes because ALL users logged out
    
        echo $_SERVER['REQUEST_URI'];
    
        exit(); // for test purposes
    
    }
    
    ?>

     

     

    Confusingly, the above code outputs '/index.php' which was not what I was expecting. How would I go about redirecting to the desired url above (including get parameters)?

     

    Thanks,

     

    Mike

  3. Good evening folks,

     

    I have a webapp that allows users to catalogue their DVD titles, and I would like to reformat all titles that start with the word "the".

     

    Specifically, if the 'title' string starts with the word "the", I want to chop "the" from the beginning of the string, prepend it with a comma and a space, and then glue it onto the end of the string:

     

    "The Matrix" (current)

     

    "Matrix, The" (desired)

     

    What is the easiest way to do this in PHP?

     

    Regards,

     

    Mike

     

  4. With regards to "PHP and MySQL Web Development, 3rd Edition" by SAMS  My friend at uni had this book, as did my previous employer, and I can see that a lot of folks in this thread recommend it.  I ordered a copy over the weekend, and it should arrive today.  My only concern is that the content may be outdated?  Is this a valid concern, or is the material still relevant today?

  5. I'm about to start my first PHP/MySQL contract @ £20/hour for 3 months ;D

     

    I'm certainly no expert in these languages, but I believe I can implement what they are looking for using open source libraries, helper classes and so forth.  Either that, or I'm screwed, lol.

  6. I'm a 27 year old male, and I have been learning PHP/MySQL on and off since the beginning of 2004.  I completed my first PHP/MySQL project in the second semester at university.  I studied B.Sc Internet Technology, and spent the third year of my course working in Madrid for industrial experience.  I graduated in 2007 with full honours, and started working as a PHP developer for a local web design company.  I am now working as a PHP/MySQL contracter through an agency :)

  7. I learned the theory behind object-oriented programming at uni (Java), and scored fairly well.  But knowing is one thing - doing is another!  I definately want to learn OO-PHP though, but not until I reasonable comfortable with procedural PHP programming.

  8. Out of interest, in what situation would you specifically need to use Dreamweaver over a *NIX based IDE?

     

    Templates ;D

     

    Why would you choose a third-party bundle to the package manager in your distribution. Setting up a LAMP in Debian/Ubuntu is as simple as aptitude install apache2 php5-mysql libapache2-mod-php5 mysql-server-5.0 (as root). It'll sort out all dependencies for you and the packages will update along with the rest of your system.

     

    Yes, I realise that.  Coming to think of it, I do use the lamp stack from the ubuntu repos.  But I use XAMPP on CentOS because I don't like the way the Apache webroot is mapped to my home directory.  Of course, I could modify the configuration, but it's easier for me to use XAMPP.

  9. For development purposes I prefer using XAMPP for Linux with Ubuntu, but there are times when I need to do something on Windows (in Dreamweaver), in which case I use XAMPP for Windows :)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.