How would custom user links work? - javascript

By custom user links, i mean like for example when a user registers to the website, a page is created specifically for that user with a link.
For Example
https:/domain.com/users/customerName
Then after creating the link, the website will automatically customize the website by using a clone of a specific webpage.
*Btw i've already took Care of the Login/Register part. I just need to know how custom user links would work.

Option 1: example.com/user
Use a single PHP file and an .htaccess file. Check out How to create friendly URL in php?
Option 2: user.example.com
Create sub-domains for each user, also uses .htaccess. Check out How to let PHP to create subdomain automatically for each user?
Option 3: example.com?user=name
Create a single php file and use $_GET parameters. This is the most usual and easiest way to customize the website based on the user who registered and logged in. (usually using user ID number: example.com/profile.php?user=71)
Of course there's also Session handling.

I think you searching for URL rewriting concept.
If user login the page no need to clone the page.you could access the same page with this user data and specification(dynamic page).Many the page content with php functions
URL rewriting
you could the function in .htaccess
if user enters the page
http://example.com/someuser
its rewrite the url with
http://example.com?q=someuser
if you see the url bar its like special page for the user.

It's actually fairly simple. You just use GET within PHP and the URL would be something like http://example.com/user?id=4453623 - If you've ever been on facebook you'll notice they use PHP for the profile pages and much other things too. If you go to your profile page, you'll notice a "id=" variable up in the URL and that's how they determine which profile page to display to you.
This is basically what #Granny commented.

Related

Redirect with current domain at the end - Wordpress plugin

For my WordPress website, I use the plugin Wp domain checker. You can check if a domain is available and proceed with a redirect. The problem is that I want it to redirect to a special redirect depending on the page where the domain checker is embedded in. For example, if it is embeded in: test.com/page1 and the redirect would be test.com/succes I want it to redirect to test.com/succes-https://test.com/page1
With the plugin that I am using, you can add {domain} at the end to redirect to a special URL with the chosen domain at the end. I want this functionality, but then with the current URL instead of the chosen domain. I know that this works via an input text field, with the name="domain"
Do I need to do this with PHP, or should I use the following JavaScript function, but how?
document.write(window.location.href)
And do I need to insert the code into the plugin PHP code, or in the current WordPress page?
Just found out that there is a very simple way of doing this. Because it uses a href link you can simply turn the href link into this href='redirect' and then it would go to http://example.com/page1/redirect. This is approach 1, but you can also use another approach, with PHP.
The second approach is to use href='$current_url redirect' and then this should be the PHP function: $current_url = home_url(add_query_arg(array(),$wp->request));
It grabs the current WP page, which you can then use in the href. Then the text with a space behind the function is the redirect, so it will redirect to the same page as approach 1.

How do I get user specific pages using javascript only?

I am creating a website where each user will have their uniq page. users can visit other user's pages by
http://website/user?user=<username>&session=<session>
Now I want to simplify above URL to
http://website/user/<username> (something like pinterest or facebook)
I thought I can use mod_rewrite. However, mod_rewrite is for server side. I do not want to include any PHP code. What I do to get data for a user :
load the basic HTML template and then based on which user we are talking about, load user's data asynchronously.
Can I achieve above in JS? If yes, how?
-Ajay
Unfortunately, you can't do exactly this.
But possible solution would be to place your HTML hub page to http://website/user/ and form user URLs like this: http://website/user/#username. JS can get the user name simply by var username = location.href.split("#")[1].
By the way, you said that you are not using PHP. How do you parse URL arguments then?

How to get bookmarklet running that allows to grab text, load a specific form and past the text into the form

I am very very new to JavaScript and I would like to build a Bookmarklet for a webservice I use. I need to grab text from any page, load the form of the service and post the text into the textfield of the form. So far I got this:
// grab text
javascript:(function(){var t=window.getSelection?window.getSelection().toString():document.selection.createRange().text;t="You selected: "+t;alert(t);})()
//load form
document.onload=function(){window.location=%22http://www.streetmails.com/index.php%3Fc=mailing%26a=content%22})();
//paste text into form
window.onload=function%20D(a,b){c=b.split('|');d=false;for(q=0;q<c.length;q++){if(c[q]==a)d=true;}return%20d;}function%20E(){f0=document.forms[0];f0['subject'].value='news from London';f0['content'].value='<echo$_GET['t']?>';f0[''].value='Add%20a%20picture...';f0['topicId'].value='4';}E
Can you help me? I searched and keept trying and trying but cant get it running....
Thanks in advance!
You can not do exactly what you are trying to do using a bookmarklet. When you execute a bookmarklet, you are executing Javascript inside the current web page. Javascript running in the web page of one web domain can not interact with pages from a different web domain. document.onload will almost never work in a bookmarklet because usually a web page is already loaded before you click the bookmarklet.
Lets call the page with text the "text-page". Lets call the page with the form the "form-page". A web form always submits to another page or to itself. It depends on the form's action value. Lets call that the action-page. Forms can be either submitted via GET or via POST.
To accomplish your goal with a bookmarklet, generally what is done is the bookmarklet will create a form on the text-page and then submit that form directly to the action-page.
If the action-page will accept a GET (only query string values), that is easiest. Look here for many such examples: https://www.squarefree.com/bookmarklets/search.html
If the action-page requires a POST, that is a little more complex because you must use Javascript to create the form: http://www.google.com/search?q=javascript%20create%20form
Addons, extensions, and user scripts can be used to do what you want more directly because they are not limited to operating only in the current domain, but of course they are more complicated to program.

Handling Facebook Like Button Information (title and image) with Links with Hashtags

On my website, Like buttons are generated dynamically. The URLs associated with these Like buttons are links that automatically redirect (with htaccess) to its respective hashtag url (i.e. ".com/event/200" redirects to ".com/#event/200"). The issue is that I can't seem to set the title or image. When a page loads with a hashtag, a database is queried and then the page title, meta data, and other things are changed. Facebook seems to be using the metadata that's set before the database has had time to load and the content has been changed. Does anyone have any idea how I can solve this problem? I'd love to be able to set the title and image when the like button is loaded if there's anyway to do that. Here's my like button code:
<fb:like href='http://website.com/"+postname+"/"+data.id+"' send='true' layout='button_count' width='450' show_faces='true'></fb:like>
The URLs associated with these Like buttons are links that automatically redirect (with htaccess) to its respective hashtag url (i.e. ".com/event/200" redirects to ".com/#event/200").
That’s your error right there.
Since the Hash part of an URL does not get transmitted to the server, it’s only usable client-side. So redirecting to it server-side is a really bad idea, since you know nothing about the client’s capabilities (f.e. if it supports JavaScript).
Don’t do server-side redirects - make them client-side instead, via JS.
This tutorial shows how to basically go about making an “AJAX-Page” crawlable: http://support.google.com/webmasters/bin/answer.py?hl=en&answer=174992

Tracking incoming URL

I have a situation where I need to change some CSS on a page based off the URL where the visitor came from. I'm using a form to submit a value to a new page (a checkout page) which is hosted on a different server/site than where the form resides. I have different forms sending this info over to the checkout page on 2 totally different sites. On this checkout page, if the user comes from site A, I need to add a certain class to a div. If the user comes over from site B, I need to add a different class to a div. Something like this:
if incoming URL is equal to www.abc.com, then addClass ('classABC');
if incoming URL is equal to www.xyz.com, then addClass ('classABC');
Am I providing enough information to properly evaluate this? Ideally I'd like to pull this off in jQuery but not sure if there's an existing plugin that can check this. One thing to note, not all the forms being submitted to the checkout page reside on the same pages (i.e. www.xyz.com/index.html). Some may be on different pages through each site, so I need to be able to figure this out based off the primary URL.
Thanks!
It should be possible to read the HTTP Refferer on the serverside. If you can then just put this value into a hidden input field like that <input type="hidden" value="the referer" id="referer-value"/> and read that hidden value for example using jquery like this var referer = $('#referer-value').val();. but as long as you can read the referer on the server you could also directly change the css file serverside.
To do this in JavaScript/jQuery you'll need to either add a URL parameter to the page to indicate which site it's from or use server-side code to embed the css in the page (which would be better). On the server you could do it with http referrer, but it's not 100% reliable so is still better to use a url parameter.
switch(location.hostname) {
case 'www.xyz.com':
case 'xyz.com':
$('div#yourid').addClass('classXYZ'); break;
case 'www.abc.com':
case 'abc.com':
$('div#yourid').addClass('classABC'); break;
}
Hope it helps!

Categories