I'm in search of a foolproof method via code to tell if an ecommerce platform id running on woocommerce or shopify.
ATM, I came up with the code below that checks if there's a URL with "wp-admin" or "admin", but its not foolproof.
$url1 = "https://www." . $_POST['domain'] . "/wp-admin";
$url2 = "https://www." . $_POST['domain'] . "/admin";
// Use get_header() function
$headers1 = #get_headers($url1);
$headers2 = #get_headers($url2);
// Use conditio to check existence of URL
if($headers1 && strpos($headers1[0], '200'))
{
$eCommercePlatform = "WordPress/Woocommerce";
}
elseif($headers2 && strpos($headers2[0], '200'))
{
$eCommercePlatform = "Shopify";
}
else
{
$eCommercePlatform = "Not Shopify or Woocommerce";
}
Any other good hacks/suggestions?
I would use something like that:
// Mimic the browser
ini_set('user_agent', 'Mozilla/5.0');
$headers = #get_headers($url, 1);
if (isset($headers['X-Shopify-Stage'])) {
$eCommercePlatform = "Shopify";
} elseif (!empty($headers['X-Powered-By']) && $headers['X-Powered-By'] == 'WP Engine') {
$eCommercePlatform = "WordPress/Woocommerce";
} else {
$eCommercePlatform = "Not Shopify or Woocommerce";
}
Explanation:
Checking the /wp-admin path seems is not the best way to detect WordPress as on the first WP website I tested - it returned 403 Forbidden. I assume others may do the same for security purposes.
I found that all Shopify sites return X-Shopify-Stage header (at least for the time being) which can be used.
I'm developing a user site in php. What I want to do, is allow people to use a ?return_to url variable to get back to the page they were on before they were asked to log in (for example, if they were on /me.php, then they will be redirected to login, and the url will be login.php?return_to=me.php.. I want to redirect to me.php after login.).
Currently, the way my system checks for login submission on the homepage is with the following:
if(isset($_POST['submitted']))
{
if($advena->Login())
{
$advena->RedirectToURL("/");
}
}
When I try to use
if (strpos($_SERVER['REQUEST_URI'], "?return_to") !== false){
$location .= "?return_to=" . urlencode($_GET["return_to"]);
if(isset($_POST['submitted']))
{
if($fgmembersite->Login())
{
$fgmembersite->RedirectToURL($location);
}
}
} else {
if(isset($_POST['submitted']))
{
if($fgmembersite->Login())
{
$fgmembersite->RedirectToURL("/");
}
}
}
It always redirects to "/" regardless of the presence of ?return_to. Here is the redirect php:
function RedirectToURL($url)
{
header("Location: $url");
exit;
}
Thank you in advance for any help anyone can provide :)
members.php - sample page
<?php
// set the return url value
$_SESSION['return_url'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
// redirect if not logged in
if (!not_logged_in()) {
header('Location: /login.php?return_to=' . rawurlencode($_SESSION['return_url']));
exit;
}
// checks if the user is logged in
function not_logged_in() {
return !isset($_SESSION['logged_in']);
}
?>
login.php - login page
<?php
if (isset($_POST['username'], $_POST['password'])) {
// do more...
// redirect
if (success()) {
// set a session for logged in user
$_SESSION['logged_in'] = sha1(time() . rand(0, 99999));
if (isset($_GET['return_to'], $_SESSION['return_url'])) {
$fgmembersite->RedirectToURL('/process.php?ret=' . urldecode($_GET['return_to']));
exit;
}
else {
$fgmembersite->RedirectToURL('/process.php');
exit;
}
}
}
?>
process.php - login processor
<?php
if (isset($_GET['return_to'], $_SESSION['return_url'])) {
# set: return url
$continue_url = rawurldecode($_GET['return_to']);
# do: redirect to the specified page
header("Location: {$continue_url}");
unset($_SESSION['return_url']);
# do: redirect with message
exit('Redirecting...');
}
else {
header('Location: /members.php');
}
?>
I am using Dreamweaver with JQuery Mobile to create a web site.
I know that in JQuery Mobile I have to include `rel="external" to link to an external file.
In my case, as I am using Dreamweaver's generated code, I need to change it at this point:
$MM_redirectLoginSuccess = "menu.php";
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
I have tried putting
$MM_redirectLoginSuccess = "menu.php rel='external'";
but it doesn´t work.
Any help is welcome.
UPDATED
This the URL showed in the browser before the user logs in
http://.../obrasbiesa/login.php
And this is the URL showed in the browser after login, it should be
http://.../obrasbiesa/menu.php
but it is
http://.../obrasbiesa/login.php#/obrasbiesa/login.php
The code snippet you've posted has quite a bit of syntax errors.
Try this :
// Set Previous Url
$_SESSION['PrevUrl'] = 'http://'. $_SERVER['HTTP_HOST'] .'/obrasbiesa/menu.php';
// Redirect
if (isset($_SESSION['PrevUrl']) && !empty($_SESSION['PrevUrl'])) {
header("Location: " . $_SESSION['PrevUrl'] );
} else {
header("Location: ". $MM_redirectLoginFailed ); // p.s. is this variable being set?
}
I'm working on a site that has a My Account section that the user has to login to. I'm storing the users basic information in the session after they have logged in.
I'm having no problem in Chrome or Firefox with this. However, in IE 8 I login, and it redirects to the main back office page. It loads, but right after the session is cleared. I tested this by printing the session after session_start() then again at the end of the page. All the information is there when the page loads. If I open a separate page and print out the session right after, it's already cleared. Again, only in IE does this happen.
Is there something I'm missing here?
CODE
This is the code on all of the Account pages.
<?php
require_once('inc_session.php');
require_once('bo_session_check.php');
?>
On the page logged into (backoffice.php), the only other time the session is used, is when it is read to determine what kind of account the person has logged into, for example:
<?php if($_SESSION['user_type']=='member'){?>
Code for inc_session.php
<?php
if(!isset($_SESSION['is_mobile'])){
$mobile_browser = '0';
if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
$mobile_browser++;
}
if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
$mobile_browser++;
}
$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
//echo $_SERVER['HTTP_USER_AGENT'];
$mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda ','xda-');
if (in_array($mobile_ua,$mobile_agents)) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'ipad') > 0) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows') > 0) {
$mobile_browser = 0;
}
if ($mobile_browser > 0) {
$_SESSION['is_mobile']='yes';
}
else {
$_SESSION['is_mobile']='no';
}
}
/* TURN MOBILE SITE OFF */
//$_SESSION['is_mobile']='no';
$page=strtok($_SERVER["REQUEST_URI"],'?');
if(substr($page, 0, 3)!="/m/" && $_SESSION['is_mobile']=='yes' && substr($page,-3) =='php'){
if( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ){
$heading='https://';
}else{
$heading='http://';
}
header("Location: " . $heading . $_SERVER["SERVER_NAME"] . "/m" . $_SERVER["REQUEST_URI"]);
exit();
}
$page=substr($page, strrpos($page, '/', -1));
$ssl_pages=array('/backoffice.php', '/login.php', '/login-partner.php', '/checkout.php', '/checkout_member.php', '/membership.php', '/partner.php');
if(in_array($page, $ssl_pages) || substr($page, 0, 3)=='/bo'){
if($_SERVER[HTTP_HOST]!='domain.com'){
header("Location: https://domain.com" . $_SERVER["REQUEST_URI"]);
}elseif($_SERVER["HTTPS"] != "on") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
}else{
if($_SERVER["HTTPS"] == "on"){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
}
ini_set("session.cookie_domain", "domain.com");
session_start();
?>
This is bo_session_check.php
if(isset($_SESSION['agreed']) && $_SESSION['agreed']!="yes" && $_SESSION['admin']!="yes"){
/*
DEPRECIATED
header("location: bo_terms.php");
exit();
*/
$_SESSION['agreed']="yes";
}elseif(isset($_SESSION['user_id']) && $_SESSION['user_id']!=""){
/*ALL GOOD*/
}else{
/*YOU GOTTA GO*/
header("location: login.php");
exit();
}
?>
Here is the PHP Session Info
Since $_SESSION is handled server-side -- this is going to mean that cookies are disabled in IE8 -
You have session.use_only_cookies = On, which is fine, but just be aware that anyone with cookies turned off will fail to load your site properly.
However, this is not what is causing the issue.
From other StackOverflow answer:
Try putting [PHP code below] prior to starting the session - this would ensure that the session cookie will not expire until the browser is closed.
session_set_cookie_params(0);
Hope this helps solve your problem. Worst case scenario, pass the SESSION ID (SID) through the URLs in between page loads and redirects. Refer to this page in the PHP Manual on passing Session IDs. You would have to do this through the Location: http://URL that you have.
I have a full site that has been in OS-commerce and mobile site is in core PHP (codeignitor), and full version and a mobile version on sub-domain.
e.g full site: www.example.com and mobile site domain is m.example.com. when user open full site domain in mobile, then website redirect proper mobile domain, But if mobile user want to view full site then user can view fullsite in mobile.
I have used this to complete the redirect http://code.google.com/p/php-mobile-detect/, But it is not redirecting to the full site or to the mobile site using session. I know that I have to use PHP SESSIONS and REQUEST in order to get this to work but I am not sure how to use them in this instance, so could you please suggest how to solve this redirecting issue using session?
Here my code is:
session_start();
include('includes/Mobile_Detect.php');
$detect = new Mobile_Detect;
if(isset($_REQUEST['fullsite']) && $_REQUEST['fullsite'] == 'yes')
{//check if fullsite view request from mobile or website?
$_SESSION['fullsite']="yes";
if($detect->isMobile()) {
$_SESSION['website']="mobile";
}
else{
$_SESSION['website']="computer";
}
$deviceType = header('Location: https://www.example.com/');
}
else
{
if($_SESSION['website'] =="mobile" && $_SESSION['fullsite'] !="yes")
{
if($detect->isTablet())
{
$deviceType = 'tablet';
}
else
{
$deviceType = 'phone';
}
$deviceType = header('Location: https://m.example.com/');
}
elseif($_SESSION['website'] =="computer" && $_SESSION['fullsite'] =="yes")
{
$deviceType = 'computer';
$deviceType = header('Location: https://www.example.com/');
}
else{
$deviceType = 'computer';
}
$scriptVersion = $detect->getScriptVersion();
session_destroy();
}
From what I could get from github page you should be able to make it work like this:
index.php
session_start();
if ($_GET['fullscreen'] == 'yes') {
$_SESSION['fullscreen'] = 1;
} else if ($_GET['fullscreen'] == 'no') {
$_SESSION['fullscreen'] = 0;
}
if (false == isset($_SESSION['fullscreen']) && ($_SESSION['fullscreen'] == 0)) {
// If session['fullscreen'] has not been set (maybe first visit
// or the user does not what in fullscree
// check the device and do redirect
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect();
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
}
...
}
// Other code here
When visiting from mobile, if the user wants the full version, provide an anchor to url with GET parameter fullscreen=yes (http://example.com?fullscreen=yes)
If on full site and detect mobile (not included in code above), you could provide a link to mobile version with fullscreen=no