Jump to content

CyberGod

Admin
  • Content Count

    1,498
  • Donations

    $0.00 
  • Joined

  • Last visited

  • Days Won

    75

Everything posted by CyberGod

  1. where are you now ?
  2. Clever and Creative Billboard Ads - Part 1
  3. CyberGod

    Tip of the day

    Tip of the day
  4. CyberGod

    Now its your turn

    Now its your turn
  5. CyberGod

    Hey Give Reply !

    Hey Give Reply !!!
  6. Spider men in India...
  7. CyberGod

    Future keyboard

    Future keyboard
  8. World best singer
  9. CyberGod

    Problem with paying for vip via paypal

    Details PMed. Thanks
  10. CyberGod

    Happy Birthday DevilSnare

    Many Many Happy returns of the day mate Have a great one. Regards, CW Team
  11. CyberGod

    Best Upload Filehost?

    Rapidshare
  12. CyberGod

    Go to Hell

    Go to Hell
  13. CyberGod

    Docs advice

    Docs advice
  14. CyberGod

    Oh, Servers

    Oh, made my remember my time in the datacenter
  15. CyberGod

    How To Mount a Virtual Drive With Daemon Tools

    very detailed and neatly done mate
  16. Hello all, First let’s explain the basics of what we are trying to do. We’ll build a script that will replace any type of url to a tiny url so it’s easier to post or be untraceable. For example this *long* google maps url http://maps.google.fr/maps?f=q&source=s_q&hl=fr&geocode=&q=white+house&sll=46.75984,1.738281&sspn=10.178118,28.54248&ie=UTF8&z=15&iwloc=A could become http://your.site/v/12345 you can check it out here : http://www.djpate.com/portfolio/shortURL/create.php and download the source code here This is not very hard to do but it’s nice tutorial for beginners. Ok so let’s start with the DB schema. CREATE TABLE `urls` ( `id` INT NOT NULL , `url` VARCHAR( 250 ) NOT NULL , `expire` DATETIME NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM ; id will be our identification hash, we won’t use auto increment for privacy purpose. We dont want a bot to check all link starting from 1. url is the actual url that will be redirecting to and expire is the time when to delete the record from our db. I’ll take more about this feature later. Now that you have your db setup let’s create the db connection page. It’s always good to have only one file doing all the db stuff. mysql.php <?php mysql_connect("yourHost","yourLogin","yourPass") or die(mysql_error()); //connects to the db mysql_select_db("yourDb") or die(mysql_error()); // selects the right db ?> now the creation page. create.php <?php require("mysql.php"); // to establish a connection to the db /* configurations options */ $lengthOfTheHash = 5; // the length determine the numbers of chars in the hash created 5 => 12345 for example $timeToExpire = 1; // in days $urlOfYourSite = "http://www.djpate.com/portfolio/shortURL"; function createHash($length=5){ // very simple hash function to generate a random string $valid = 0; while(!$valid){ for($i=0;$i<$length;$i++){ $possibleValues = "123456789"; // if you want to add letters you will have to change the id to varchar instead of int // pick a random character from the possible ones $hash .= substr($possibleValues, mt_rand(0, strlen($possibleValues)-1), 1); } $check = mysql_query("select id from urls where id = $hash") or die(mysql_error()); // checks if the hash allready exists in the db , not very likely to happen if(mysql_num_rows($check)==0){ $valid = 1; } } return $hash; } if(isset($_POST['url'])){ // post was posted //here we want to validate that the url is valid with a regexp if(preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i',$_POST['url'])){ $hash = createHash($lengthOfTheHash); mysql_query("insert into urls (id,url,expire) values ($hash,'".addslashes($_POST['url'])."',date_add(now(),interval $timeToExpire day))") or die(mysql_error()); echo "Congrats ! here is your link : <a href=\"$urlOfYourSite/v/$hash\">$urlOfYourSite/v/$hash</a>"; } else { echo "Invalid url !"; } } else { // no post data so we display the form ?> <form method="post"> URL : <input type=text name=url /> <input type=submit value=go /> </form> <?php } ?> now let’s create the redirection page show.php <?php if($_GET['id']){ require("mysql.php"); // to establish a connection to the db $id = addslashes($_GET['id']); $getUrl = mysql_query("select url from urls where id = $id"); // check if the id exists in the db if(mysql_num_rows($getUrl)==1){ // if so we redirect using the header function $url = mysql_fetch_array($getUrl); header("location:".$url['url']); } else { echo "Error : invalid hash"; } } else { echo "Error : no hash"; } ?> And to finish up let’s make a simple url rewrite so we dont have to see the show.php .htaccess Options +FollowSymlinks RewriteEngine on RewriteRule ^v/([0-9]*)$ show.php?id=$1 [L] note : dont’ forget to check that you have enable the mod_rewrite on your apache conf ! Bonus At this point everything should be working but you’ll end up having a problem with the url that stays in your db for years so you have to setup a cron to remove the url that reaches there expire date. We could do a real cron but you would need to have ssh access and php-cli installed and probably if you know what i’m talking about you dont need my help to do that. For those who can’t setup a real cron we are simply going to check to delete all the old record everytime someone create a new one. so you can just add this line before $hash = createHash($lengthOfTheHash); in create.php mysql_query("delete from urls where expire < now()"); this will remove all url where expire date is inferior to the current date.
  17. CyberGod

    What is your hobby

    CW takes up all my free time :cwrocks:
  18. CyberGod

    Youtube Section

    We have a video share section in community longue, maybe you can share some music video s there as well
  19. CyberGod

    Thought Of The Day

    Begin your day with a wonderful thought to ponder upon: April 30, 2012 Sometimes, the people who are thousands of miles away from you, can make you feel better than people right beside you. May 1, 2012 " Life's ups and downs provide windows of opportunity to determine your values and goals. Think of using all obstacles as stepping-stones to build the life you want." May 2, 2012 " The Titanic sank in the North Atlantic Ocean on 15 April 1912 (100 years on) after colliding with an iceberg. Relationships sometimes are like the Titanic - plain and smooth at first but if taken for granted, they could collide." May 3, 2012 " When your actions are in sync with your heart, something beautiful is bound to happen." May 4, 2012 " A new day is the biggest opportunity of your life." May 5, 2012 " SHOULD have, WOULD have and COULD have will ALWAYS keep YOU from I CAN, I WILL and I AM." May 6, 2012 When life gives you lemons, then make lemonade! At no time stop believing the impossible. Accept the unexpected. Keep a constant watch for the positive in everything and everyone and never settle for average. Stay dedicated in helping others realize their unlimited potential! Do it every day and DO IT BIG!!!" May 7, 2012 If you can not get through the mountain, go around it. If you can not go around it, climb over it. If you can not climb it, then sit down and ask yourself how important it is to get over to the other side. If it's important enough, start digging a tunnel. May 8, 2012 " Don't spend today worrying why yesterday was bad. Spend it planning on how to make tomorrow better." May 9, 2012 " I know I've done a lot of things I'm not proud of or stupid things, as people around called them. Yet, I won't regret what I've done because at one time, that's exactly what I wanted. Now that I know I was doing wrong, I will treat these experiences as wake-up calls for the rest of my life." May 10, 2012 " Your big opportunity may be right where you are now." May 11, 2012 When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car. May 12, 2012 " You aren't wealthy until you have something money can't buy." May 13, 2012 Ten years ago, we had a Steve Jobs, a Bob Hope, and a Johnny Cash. Now we have no jobs, no hope, and no cash.
  20. CyberGod

    [Poll] Extra Sections

    We would really like to hear from our members on this.
  21. CyberGod

    Men are Honest..

    Men are Honest.. “One day, while a woodcutter was cutting a branch of a tree above a river, his axe fell into the river. When he cried out, the Lord appeared and asked, “Why are you crying?” The woodcutter replied that his axe has fallen into water, and he needed the axe to make his living. The Lord went down into the water and reappeared with a golden axe. “Is this your axe?” the Lord asked. The woodcutter replied, “No.” The Lord again went down and came up with a silver Axe. “Is this your axe?” the Lord asked. Again, the woodcutter replied, “No.” The Lord went down again and came up with an iron Axe. “Is this your axe?” the Lord asked. The woodcutter replied, “Yes.” The Lord was pleased with the man’s honesty and gave him all three axes to keep, and the woodcutter went home happy. Some time later the woodcutter was walking with his wife along the riverbank, and his wife fell into the river. When he cried out, the Lord again appeared and asked him, “Why are you crying?” “Oh Lord, my wife has fallen into the water!” The Lord went down into the water and came up with ANGELINA JOLIE “Is this your wife?” the Lord asked.. “Yes,” cried the woodcutter. The Lord was furious. “You lied! That is an untruth!” The woodcutter replied, “Oh, forgive me, my Lord. It is a misunderstanding. You see, if I had said ‘no’ to ANGELINA JOLIE , You would have come up with AISHWARYA RAI. Then if I said ‘no’ to her, you would have come up with my wife . Had I then said ‘yes,’ you would have given me all three. Lord, I am a poor man and weak also.., and am not able to take care of all three wives, so THAT’S why I said yes to ANGELINA JOLIE .” MORAL OF THE STORY: Whenever a man lies, it is for a good and Honorable Reason, and for the Benefit of others. Men are honest.
×