Hello I need URl shorting script with adsense revenue sharing can any one help me to got this script Thanks
This wouldn't be to difficult to do with PHP and MySQL, I'll give a very basic example, but some basic knowledge of both is required. First, you'll want to create a table, let's call it 'shorten_table', and add two columns: id - INT, primary key, auto-increment url - TEXT Second, you'll need two PHP scripts. The first one will be used for visitors to enter in their URL they would like to shorten, submit it, then get the shortened link. The second script will be used to redirect visitors using the shortened link to the actual website. Below is the first script, assuming your MySQL table is named 'shorten_table' and your domain is 'http://www.your_domain.com': submit_link.php <?php /* //////////////////////////////////////////////////// Instead of creating two seperate files just to handle the user input, it can all be done in one file. All you have to do is check to see if the user and pressed the submit button. The code below check whether the user is visiting this page for the first time, or if they have submitted a link. /////////////////////////////////////////////////// */ //Include your code to connect to your MySQL database //and select your table. If you don't do this, the //code will not work :) $url = mysql_real_escape_string( $_POST['url'] ); $submit = $_POST['submit']; //Success/error handlers $success = 0; $error = 0; //Check if user pressed submit if( isset( $submit )) { //Make sure $url is not blank if( $url != '' ) { //You would want to perform some type of URL validation here, before query below $sql = mysql_query( "INSERT INTO shorten_table (url) VALUES ('$url')" ); if( $sql ) { $shortened_id = mysql_insert_id(); $success = 1; } else { $error = 1; } } } ?> <html> <head> <title>Shorten A Link</title> </head> <body> <div style="margin: 0 auto; text-align: center; padding-top: 20px;"> <?php //If we have successfully shortened a URL, display the shortened URL instead of the form if( $success == 1 && isset( $shortened_id )) { ?> <p><b>Success! Your shortened link is below:</b></p> <p><a href="http://www.your_domain.com/redirect.php?id=<?php echo $shortened_id; ?>">http://www.your_domain.com/redirect.php?id=<?php echo $shortened_id; ?></a></p> <?php } //If there was an error, inform the user elseif( $error == 1 ) { ?> <p style="color: #ff0000">There has been an error</p> <?php } //If it was unsuccessful (or not used yet) and there are no errors, display the form else { ?> <p><b>Enter Link Below:</b></p> <form name="submit_link" action="submit_link.php" method="post"> <input type="text" name="url" value="http://" /> <input type="submit" name="submit" value="Shorten!" /> </form> <?php } ?> </div> </body> </html> PHP: Now users need to be redirected when they use the shortened link from your site. It will be used like 'http://www.your_domain.com/redirect.php?id='. Since the id variable is included within the URL, we must use the GET method instead of POST when retrieving it in PHP: redirect.php <?php //Get the id of the row for this URL $shortened_id = mysql_real_escape_string( $_GET['id'] ); //Get the actual URL from our table (sloppy i know) $result_url = mysql_query( "SELECT url FROM shorten_table WHERE id='$shortened_id'" ); $url_array = mysql_fetch_array( $result_url ); $url = $url_array['url']; header( 'Location: ' . $url ) ?> PHP: This is a quick example, much more can be added to it (and probably should).
That was good one DollaradeConner, but I would suggest to keep key or short_url as alphanumeric rather than auto incremented values. More over, for precision and avoid duplicates, i would keep it based on current time in microseconds precision