close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

page redirection based on user

Thread began 8/18/2014 5:17 am by Jamie | Last modified 8/19/2014 12:25 pm by Jason Byrnes | 2371 views | 24 replies |

Jamie

page redirection based on user

Hey Jason

Am trying to get this to redirect to a specific page if its specifically a user and another page if it isnt that user. The code isnt working as it takes all users to the news_results page regardless if they have UserID 6 or not.

<?php require_once('../Connections/DBConnection.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php
$Users = new WA_MySQLi_RS("Users",$DBConnection,1);
$Users->setQuery("SELECT UserID FROM pcms2_users");
$Users->execute();
?>
<html>
<title></title>
<body>
<?php
if ("".($Users->getColumnVal("UserID")) ."" == "6") { // Show If
?><script type="text/javascript">
window.location.replace("product_contents_results.php");
</script>
<?php
} // ("".($Users->getColumnVal("UserID")) ."" == "6")
?>
<?php
if ("".($Users->getColumnVal("UserID")) ."" != "6") { // Show If
?><script type="text/javascript">
window.location.replace("news_results.php");
</script>
<?php
} // ("".($Users->getColumnVal("UserID")) ."" != "6")
?>

</body>
</html>



There is probably a more elegant solution that you may be able to point me in the right direction for?

Cheers

Jamie

Sign in to reply to this post

CraigRBeta Tester

Hi Jamie,

just wondered if you were using javascript for a reason

would it not be easier using php ?

header("Location: ".redirectURL);

Sign in to reply to this post

Jamie

No reason at all Craig and have tried your suggestion but it doesnt change the 'result' I'm afraid

EDIT; sorry, it only did the same thing as I had the syntax incorrectly ...

using the php method, I am getting

Warning: Cannot modify header information - headers already sent by (output started at /home/iteacvh1/public_html/admin_cms/index.php:11) in /home/iteacvh1/public_html/admin_cms/index.php on line 28



I have modified the code within the show if statements as follows:

<?php
header("Location: http://www.domain.co.uk/admin_cms/news_results.php"); /* Redirect browser */
?>
Sign in to reply to this post

CraigRBeta Tester

it looks like what your sql statement is doing is returning the first row in the table

Assuming the user is logged in, could you not ditch the recordset and use $_SESSION['UserID']

<!doctype html>
<html>
<?php
@session_start;
if ($_SESSION['UserID'] = 6) {
header("Location: http://www.domain.co.uk/product_contents_results.php"); /* Redirect browser */
} else {
header("Location: http://www.domain.co.uk/news_results.php"); /* Redirect browser */
} ?>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
Sign in to reply to this post

Jamie

Thanks Craig...

Am getting this error
Warning: Cannot modify header information - headers already sent by (output started at /home/iteacvh1/public_html/admin_cms/index.php:3) in /home/iteacvh1/public_html/admin_cms/index.php on line 6

Sign in to reply to this post

CraigRBeta Tester

hmm, shouldn't be anything going to the screen, you could try adding exit();

eg

php:
<?php if ($_SESSION['UserID'] = 6) {

    
header("Location: http://www.domain.co.uk/product_contents_results.php"); /* Redirect browser */
    
exit();
} else {
    
header("Location: http://www.domain.co.uk/news_results.php"); /* Redirect browser */
    
exit();
?>
Sign in to reply to this post

Jamie

thanks but still getting the error

Warning: Cannot modify header information - headers already sent by (output started at /home/iteacvh1/public_html/admin_cms/index.php:3) in /home/iteacvh1/public_html/admin_cms/index.php on line 6

Sign in to reply to this post

CraigRBeta Tester

can you attache the actual page please ?

Sign in to reply to this post

Jason ByrnesWebAssist

code order, you have the redirect after the doctype:

<!doctype html>
<html>
<?php
@session_start;
if ($_SESSION['UserID'] = 6) {
header("Location: http://www.domain.co.uk/product_contents_results.php"); /* Redirect browser */
} else {
header("Location: http://www.domain.co.uk/news_results.php"); /* Redirect browser */
} ?>




the redirect should be the first code block:

<?php
@session_start;
if ($_SESSION['UserID'] = 6) {
header("Location: http://www.domain.co.uk/product_contents_results.php"); /* Redirect browser */
} else {
header("Location: http://www.domain.co.uk/news_results.php"); /* Redirect browser */
} ?><!doctype html>
<html>
Sign in to reply to this post

CraigRBeta Tester

oops, my bad

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...