SEO cookie redirection - php

I have a website where I am splitting my traffic into two user groups "learners" and "instructors". I hold their user group in a session variable and direct them to the relevant section of their site.
I am having problems with search engines not indexing the site due to them not having the user_type cookie set. Is there a way I can allow the search engine crawler access to both sections of the site (at the moment it gets stuck in an loop from the user_type selection page to the homepage).
I would also ideally like to be able to allow the crawler access to the member-only resources as there will be content that learner drivers will be able to access that I would prefer was only accessible once logged in.
The code checking the session variable user_type is below and is called on every page (hence why nothing is getting crawled)
if($check_exists==TRUE) {
$this->session->set_userdata('referrer', current_url());
if (strlen($this->session->userdata('user_type'))==0) {
redirect('/user_type/');
}
} else if($check_exists==FALSE) {
if (strlen($this->session->userdata('user_type'))>0) {
redirect('/home/');
}
}

The concept you are using to handle both user types (learner and teacher) is wrong from a SEO perspective. In most cases, you should never have to different content sharing a single URL.
In your case, http://www.road2driving.co.uk/home redirects to http://www.road2driving.co.uk/user_type if no cookie is found. A web crawler will ignore your cookie, and will be caught in a loop. If you want to index both pages, you need to drop the cookie based navigation and create 2 separate sections of your site.
http://www.road2driving.co.uk/home should be your current http://www.road2driving.co.uk/user_type page. Meaning that /home will display 2 links for the learner and teacher sections.
Then create a learn section and a teach section, using a sub-folder for example. You will have:
http://www.road2driving.co.uk/home
http://www.road2driving.co.uk/learn/
http://www.road2driving.co.uk/teach/
That way all sections of your site be accessible by a crawler.

Related

How to create web separate pages for user profiles using PHP and mySql? URL rewriting?

I am trying to figure out the best way/how to go about this -
I am relatively new to mysql and PHP and need to create user profile pages that display different values from a mysql database that have been uploaded for each user -
for example if I clicked on John's profile, the page would display John's name, age, any other values that I have stored on John in my mysql table. This is from the perspective of someone else logged in who wants to view John's page.
Since all my index.php files for my different web pages are all in their own folders (i.e. the about page, settings page, etc) I originally thought to simply have a user profile folder and index.php that just outputs the right information in accordance with the $user_id of the user that was clicked. That is the only way I can think to accomplish this.
My problem is that this would not allow for a person to access a user profile via URL (i.e. website.com/user1) and I am not sure my approach is the best/correct way to create user profile pages. I have explored this question and read up on URL rewriting but am still unclear -
What is the correct way to create separate user profile web pages and how does URL rewriting tie into the actual contents of the page's index file?
Is there a way to (this is poorly worded) store a separate index.php file for each user within their existing mysql column and just direct to this file when clicked?
Hard to answer without knowing how the structure of your application is looking.
But the most common way, and the most simple implementation would be to:
create a profile.php (profile-action in user-controller or whatever..)
add the user-id to the url, yourapplication/profile.php?userid=12
In your profile.php you simply fetch the data which belongs to the given userid (first validate the id etc...)
fill your html with the fetched data
So in short: create a view, fill in dynamic data depending on the userinput
I don't think what you want to do is related to URL rewriting. URL rewriting is simply writing facebook.com/user1 instead of facebook.com/user1/index.php (or whatsoever).
"My problem is that this would not allow for a person to access a user profile via URL" I believe this part is incorrect. Someone who logged in as, say, user1 can view the page www.website.com/user2 and see another person's profile.
Check out this website to get a better understanding for URL rewriting. Facebook uses it as you can access a person's profile from facebook.com/user5. On the other hand, one comment suggested you to use dynamic php such as /profile.php?id=5. It is your choice what to pick. But the first option does not prevent users to check out others' profile pages on the contrary to what -I believe- you assumed.

WordPress Referrer Tracking

I have a WordPress blog that's hosted within my site (http://www.mysite.com/blog) and my website itself is based on ASP.NET.
I'm tracking referrers within ASP.NET upon session start and storing them within a session variable to save into my database either after a session expires or after a visitor converts to a member.
How can I track the referrers for visitors that come to the blog first and click on a link to a page within the website? Is there a way in WordPress that I could pass the referrer using a query string?
When they land on the blog drop a cookie with the original referrer.
Then read this from the app.
Whip up a plugin to do something like this:
if( !isset($_COOKIE['ref']) ) {
setcookie(...);
}
If you feel like a hack you could just add this to WP's index.php, but a plugin would be the more portable, clean option.

Social Network & Dynamic vs Static pages. Where to draw the line?

As I come to the end of my project I am starting to wonder if I made it too dynamic. I have designed this social networking site and 90% of it is based on JQuery. It looks nice, it loads fast but I started to wonder if it is too dynamic...
My concern is that basically once you log in, 95% of what you do is JQuery based therefore the user never leaves the same URL. If this is true, how is a search engine like Google supposed to index my website?
Is this the part where I ask myself what parts of the site I want to be indexed and make them static pages instead?
Basically it has occurred to me that if when you browse my site for user profiles, these profiles are displayed to you through JQuery requests, then it is safe to assume that these profiles can never be found in a Google search, because the Google spider would never see it. Is this true?
Thank you for any thoughts on this,
Vini
Make your site work in both "modes". For example, I'm on my dashboard and I want to check out my friend Joe's profile, there should just be an A tag with the href set to something like "/profiles/joe".
Now, onDomReady, when the page loads, run your javascript to go through the links and attach click handers to those links, and load the profile dynamically using your existing jQuery style.
This development style is called "progressive enhancement" and allows both search engines and human accessibility devices to work better with your website. Check it out.

same php file to serve 3 domains

I'm rather new to php and wonder if the following technically feasible?
I would like to have 3 urls to hit the same page on the server, but display different slightly content (content text is in stored in database tables with a indicator flag whether the content belongs to urlA or urlB), i.e.
URL_A will show content specific to A's products only, URL_B will show content specific to B's products only, URL_C will show products for both A and B. All these URLs will point to the same page (index.php) and I would prefer if the domains all remain as they are entered to differentiate the branding and content, rather than using 301 to redirect 2 of the domains (e.g. a visitor entering www.urlA.com will be able to continue browsing/navigating the website pages like www.urlA.com/about-us or www.urlA.com/news)
Can this be implemented using a mod-rewrite and some php logic or passing some session or hidden form input to various pages? Any advice on where/how to start would be appreciated :)
You can use $_SERVER['HOST_NAME'] to determine which virtual host is being accessed. Use this value to perform whatever logic you require.

Displaying different content on a Profile page when the logged-in user is the Profile owner

I always try to make code nicer and more maintainable but I'm not sure if I do it right... For example, I'm doing a social network site, so the page domain.com/profile?id=17 would open profile for user id 17. If the user is the currently logged in one, then the profile will be seen as the owner (with edit options, etc) otherwise the page would show a profile for outsiders (no edit options).
How do I do this nicely? I was thinking that after checking if the user id == the user id in $_SESSION, I include one php file (the one with the edit options), otherwise I include the other one. Is this a solution? Is there a better one?
I do the same thing for headers, I have a file 'header.php' that includes the header of all pages (some php but also a logo, etc), however I'm not sure if this is good since a user can go to his browser and type mydomain.com/header.php and then be displayed a header only.
Your solution is one way to do it .another way to do it would e just check the user_id in session and if it is not set then just display another html . Also you would want to access users as their usernames rather than user id.For example instead of user_id.php=17 to username/luqita.If you are using apache as the web server then you could use it's mod_rewite module to generate pretty urls.

Categories