hello i need a simple code to save url into file.txt

Discussion in 'PHP' started by tadmeer, Sep 1, 2012.

  1. #1
    helloi need to log referrer for visitors the links like: http://localhost/hello.php?session=aGVsbG8gZGlnaXRhbHBvaW50==


    i want to log the url and the (decodded) base64 code: aGVsbG8gZGlnaXRhbHBvaW50== to file.txt or something


    so the file.txt will have:


    url: http://localhost/hello.php?session=aGVsbG8gZGlnaXRhbHBvaW50==
    session: aGVsbG8gZGlnaXRhbHBvaW50==
    decodded_session: hello digitalpoint


    thanks for help me
     
    tadmeer, Sep 1, 2012 IP
  2. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Enjoy! Is secure and works, I tested.

    See live at: http://lamp-developer.com/logdecode.php?session=VGhpcyBpcyBhIHRlc3Qh

    See the log here: http://lamp-developer.com/log.html

    Please remember I am for hire! I can code anything and if it is a language I can't, I probably know somebody who can.

    This will log each entry to log.txt one after the other separated by *****************.

    You MIGHT need to chmod 666 the log. I don't have to but you might.

    
    <?php
    if (!empty($GET['session'])) {
    	die('Not all data that is required was entered. I Quit!');
    } else {
    	if (!function_exists('curPageURL')) {
    		function curPageURL() {
    			$isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
    			$port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
    			$port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : '';
    			$url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"];
    			return $url;
    		}
    	}
    	$path = htmlspecialchars(strip_tags(trim(curPageURL())));
    	$session = htmlspecialchars(strip_tags(trim($_GET['session'])));
    	$session_decoded = base64_decode($session);
    	if (!function_exists('doLog')) {
    		function doLog($mess) {
    			$logFUN = fopen('log.html', 'a+');
    			fwrite($logFUN, $mess);
    			fclose($logFUN);
    		}
    	}
    	$log .= '
    		<div style="clear:both;margin-top:10px;border-bottom:1px solid #000000;">
    			<div style="clear:both;line-height:21px;">URL: ' . $path . '</div>
    			<div style="clear:both;line-height:21px;">SESSION: ' . $session . '</div>
    			<div style="clear:both;line-height:21px;">SESSION DECODED: ' . $session_decoded . ' </div>
    		</div>
    	';
    	doLog($log);
    }
    echo $log;
    ?>
    
    
    Code (markup):
    Just edit the style value to alter the look.
     
    Last edited: Sep 1, 2012
    DomainerHelper, Sep 1, 2012 IP
    ThePHPMaster likes this.
  3. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    100
    #3
    And please give me a +1 reputation by clicking the thumbs up pic at the bottom left of my post. Thank mate.
     
    DomainerHelper, Sep 1, 2012 IP
  4. tadmeer

    tadmeer Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    DomainerHelper
    thank you very much bro it's working fine
     
    tadmeer, Sep 1, 2012 IP
  5. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    100
    #5
    I updated the code above to use an html page that you can style.
     
    DomainerHelper, Sep 1, 2012 IP
  6. tadmeer

    tadmeer Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks very much
     
    tadmeer, Sep 1, 2012 IP
  7. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    100
    #7
    You're welcome. Don't forget to add to my rep with the thumbs up button plz.
     
    DomainerHelper, Sep 1, 2012 IP
    hassanahmad2 likes this.