Sara Tarek
Sara Tarek

Reputation: 369

Create one URL to be used instead of many URLs

I need to create a general URL from many URLs, for example if i have 5 URLs for some pages, I want to create a new one to be used as a shortening URL for those 5, in other words I need these URL to save the other URLs somehow and returns them to me when i put it in the address bar and it will be perfect if it opens them in tabs

I don't know how can i accomplish this, How to create a URL generally ? and how to let it does something like this.

It may be a basic question !! But i am a noob in Web apps, so sorry if it isn't clear enough too

Upvotes: 1

Views: 209

Answers (3)

Shady Mohamed Sherif
Shady Mohamed Sherif

Reputation: 15759

You need a webserver which is running php, jsp or any other backend language. then you need to write a page with one of these language which takes an array of links as a get variable and returns a javascript body which opens this list of urls in a tabs.

for example in php

Use serialize and unserialize PHP function to send the array of links to the php page. This function giving you storable (string) version of array type. For more infomation about usage read http://php.net/manual/en/function.serialize.php and http://www.php.net/manual/en/function.unserialize.php

then loop the urls and add such an echo message for each one.

<?php
        foreach ($arrayOfUrls as $url) {
        echo '<script type="text/javascript">var win = window.open('.$url.', "_blank"); </script>';

?>

finally you need to call this page from your javascript code , you need to serialize your JS array which have the list of the urls.

you can use this code for that.

/*
* PHP Serialize
* Morten Amundsen
* [email protected]
*/
function php_serialize(obj)
{
    var string = '';

    if (typeof(obj) == 'object') {
        if (obj instanceof Array) {
            string = 'a:';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                tmpstring += php_serialize(obj[key]);
                count++;
            }
            string += count + ':{';
            string += tmpstring;
            string += '}';
        } else if (obj instanceof Object) {
            classname = obj.toString();

            if (classname == '[object Object]') {
                classname = 'StdClass';
            }

            string = 'O:' + classname.length + ':"' + classname + '":';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                if (obj[key]) {
                    tmpstring += php_serialize(obj[key]);
                } else {
                    tmpstring += php_serialize('');
                }
                count++;
            }
            string += count + ':{' + tmpstring + '}';
        }
    } else {
        switch (typeof(obj)) {
            case 'number':
                if (obj - Math.floor(obj) != 0) {
                    string += 'd:' + obj + ';';
                } else {
                    string += 'i:' + obj + ';';
                }
                break;
            case 'string':
                string += 's:' + obj.length + ':"' + obj + '";';
                break;
            case 'boolean':
                if (obj) {
                    string += 'b:1;';
                } else {
                    string += 'b:0;';
                }
                break;
        }
    }

    return string;
}

The output url will be like yourphppage.php?urls=""a:3{i:0;s:4:"URL1";i:1;s:8:"URL2";i:2;s:7:"URL2";}

Upvotes: 1

Binoj D
Binoj D

Reputation: 115

You can use PaseteBin and their APIs. They have a list of APIs which your webapp can use to store the URLs in plaintext format and have them returned to you. The pastebin URL generated will be your URL which contains other URLs.

Upvotes: 1

Quentin
Quentin

Reputation: 943696

I need these URL to save the other URLs somehow and returns them to me when i put it in the address bar

The only way to do this would be at the resource level. For instance, you could use the URL of an HTML document which promptly opens 5 popups (although this would be blocked by most browsers) or opens the 5 pages in frames (which would be a nasty UI).

How to create a URL generally?

Run a web server. Then combine the address of the machine it is running on (either its IP address or a hostname set up with DNS) with a local part which is handled by the web server software you selected.

Upvotes: 0

Related Questions