PHP - Redirect To Login With Dynamic Url Doesn't Work
Redirect to login with dynamic URL (?p=) doesn't work
I have two webpages that I want to be accessible only when the user is logged in. One for admin and one for other users. When a user who isn't logged in arrive to these pages I want to redirect the page to login.php. This doesn't work with the website I am working on. I use this script on the startpage: Code: [Select] <?php if(file_exists($_GET['p'].".php")){ include($_GET['p'].".php"); } else{ if(empty($_GET['p']) OR $_GET['p'] == ""){ include("main.php"); } else{ include("404.php"); } } ?> and therefore my links have this format: ?p=mapp/filnamn and it doesn't work with header('Location: /?p=admin/login'); If I skip this script and use ordinary links header('Location: /admin/login.php'); it works, but I don't want to be forced to copy the same code over and over again to get header, footer, leftbar and rightbar on every single page. I have almost teared my brain apart to find a solution but in vain. Today I have been sitting in front of the computer almost the whole day with this problem, but no luck. I don't even know what to search for. What is it I don't understand? Not long time ago I hade another problem just because I use dynamic links. This is the script I use on the page that I don't want to be accessible if you aren't logged in: Code: [Select] <?php session_start(); $username = $_SESSION['username']; include ('functions.php'); db_connect(); if(!empty($_SESSION['username'])){ $sql = mysql_query("SELECT username, usertype FROM users WHERE username='$username'"); $result = mysql_num_rows($sql); $row = mysql_fetch_array($sql); if($_SESSION['username'] = $username AND $row['usertype']==1){ $_SESSION['username'] = $username; $user_welcome = "Welcome ".$username; } else{ //header('Location: /?p=admin/login'); die("<a href='?p=admin/login'>You have to login as admin to access this page!</a>"); } } else{ //header('Location: /?p=admin/login'); die("<a href='?p=admin/login'>You have to login to access this page</a>"); } ?> I use "die" because it is the only way for me to make it work, but I want to use what is in the comments. Maybe it's not such a bad idea to use the method I use today, but the problem is that when I get the message that I have to login to view the page, the rightbar disappear and the page therefor looks stupid. Another question I am wondering about, is if the above script is secure? It doesn't feel like it, but maybe the security is all about the loginpage? Similar Tutorialsif ($count==1){ header("Location:store.php"); }very simple I have issolated it and it doesn't redirect maybe u can see where my mistake is I have created a registration page to access my website. After the user registrate himself should appear an alert saying that the registration was OK and a redirect to main.php page... however for some reason if I create an insert statement the alert and the redirect don't appear... If I remove the insert the alert and the redirect works... why? This is part of the code of my 3 files: registration.php (ajax call) $('#submit').click(function() {var username2 = $('#uname2').val(); var password2 = $('#psw2').val(); $.ajax({ url: 'ajax/response.php', type: 'GET', data: {username2 : username2, password2: password2}, success: function(data) { if(data === 'correct') { alert("Username and Password have been created!"); //don' work with the insert location.replace("main.php"); //don' work with the insert } else { alert("Username or password are not correct... please register yourself!"); } } }); }); response.php (answer to ajax call) if(isset($_GET['username2']) && isset($_GET['password2'])) {$username2 = $_GET['username2']; $password2 = $_GET['password2']; if (checkUser($pdo, $username2) === true) { echo 'duplicate'; } else { insertUserPwd($pdo, $username2, $password2); //including this line the redirect and the alert doesn't work... the insert is OK echo 'correct'; } } data_access.php (the function works but doesn't permit alert and redirect to appear) function insertUserPwd(PDO $pdo, $usr, $pwd){ $data = [ 'id' => '', 'user' => $usr, 'password' => $pwd ]; $sql = "INSERT INTO users (id, user, password) VALUES (:id, :user, :password)"; $stmt= $pdo->prepare($sql); $stmt->execute($data); } Can someone help me to fix the code? Problem: The page does not redirect the end user to main.php. Notice: Use of undefined constant name_id - assumed 'name_id' in C:\x\xampp\htdocs\pages\form_process.php on line 48 Warning: Cannot modify header information - headers already sent by (output started at C:\x\xampp\htdocs\pages\form_process.php:48) in C:\x\xampp\htdocs\pages\form_process.php on line 87 The error messages displayed above make it seem like they are connected to the problem, but I don't understand why 'name_id' is undefined as its auto increments in mysql. I also think my .htaccess might be preventing me from redirecting, is that possible? " header('Refresh: 5; URL=http://localhost/pages/main.php'); " Goal: redirect user to main.php without error messages being displayed. form_process.php <?php //let's start our session, so we have access to stored data session_start(); if (isset($_POST['terms_and_conditions']) == 0) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('You must agree to the terms and conditions to create a profile. Go back and try again.'); } include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('The code you entered was incorrect. Go back and try again.'); } else { include 'db.inc.php'; $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect. Check your connection parameters.'); mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); $error = array(); $query = 'SELECT name FROM user WHERE ' . 'name = "' . mysql_real_escape_string($_SESSION['values']['name'], $db) . '"' ; $result = mysql_query($query, $db) or die(mysql_error($db)); if(mysql_num_rows($result) > 0) { $error['uname'] = '<p class="errText">Username is taken.</p>'; header('Refresh: 5; URL=form1.php'); } //let's create the query else{ $query = sprintf("INSERT INTO user ( name_id, name, password) VALUES ('%s','%s','%s')", name_id, mysql_real_escape_string($_SESSION['values']['name']), mysql_real_escape_string(md5(SALTY . $_SESSION['values']['password']))); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); $name_id = mysql_insert_id(); $query = sprintf("INSERT INTO contact ( name_id, first_name, last_name, email, address, city, county, post, home, mobile) VALUES (LAST_INSERT_ID(),'%s','%s','%s','%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($_SESSION['values']['first_name']), mysql_real_escape_string($_SESSION['values']['last_name']), mysql_real_escape_string($_SESSION['values']['email']), mysql_real_escape_string($_SESSION['values']['address']), mysql_real_escape_string($_SESSION['values']['city']), mysql_real_escape_string($_SESSION['values']['county']), mysql_real_escape_string($_SESSION['values']['post']), mysql_real_escape_string($_SESSION['values']['home']), mysql_real_escape_string($_SESSION['values']['mobile'])); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); $name_id = mysql_insert_id(); $query = sprintf("INSERT INTO profile ( name_id, bi, ex) VALUES (LAST_INSERT_ID(),'%s','%s')", mysql_real_escape_string($_SESSION['pro']['bi']), mysql_real_escape_string($_SESSION['pro']['ex'])); $result = mysql_query($query, $db) or die(mysql_error($db)); $_SESSION['logged'] = 1; header('Refresh: 5; URL=http://localhost/pages/main.php'); } ?> <html> <head> <title>Register</title> </head> <body> <p><strong>Thank you <?php echo $_SESSION['values']['name']; ?> for registering!</strong></p> <p>Your registration is complete! You are being sent to the page you requested. If your browser doesn't redirect properly after 5 seconds, <a href="main.php">click here</a>.</p> </body> </html> <?php session_destroy(); die(); } ?> I'm trying to make a login page called login.html, currently my check.php posts from a submit button then checks the username and password fields. if (mysql_num_rows($res)==0) { echo "Username or password is incorrect <br>"; echo 'Click <a href="login.html">here</a> to try again'; } else { echo "Your Username and Password is correct, welcome<br>"; echo 'To enter the members area, click <a href="users.html">here</a> to enter'; } If the username or password is incorrect the site goes from login.html to check.php page and displays as expected: Username or password is incorrect Click here to try again Ideally, what I would like to happen would be the login.html page would let the user know that the username or password was incorrect. In a similar way to how https://www.stumbleupon.com/login does it. Or just an easier way to just replace the php code to redirect the user to a page like login_incorrect.html or something similar? I have tried simply copying the login.html code and putting it in a page called login.php and then adding the check.php code to this too, although this works I dont really want users to be able to see the code when going to the page source of login.php Thanks in advance
Hello all
My theme uses this file (socials-auth.php) to login with Google
I want the user to not redirect after logging into /my-account page and become the same as the current page wp_redirect( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) );
And after the user login, his Gmail name will appear with a random number, if ( ! empty( $userProfile ) ) { $email = $userProfile->email; if ( email_exists( $email ) ) { $user_data = get_user_by( "email", $email ); mf_login_user( $user_data ); wp_redirect( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); } else { list( $user_login, $no_matter_data ) = explode( '@', $email ); $u_login = $user_login . rand( 1000, 9999999 ); $password = bin2hex( random_bytes( 15 ) ); $user_register_data = [ 'user_login' => apply_filters( 'pre_user_login', $u_login ), 'user_email' => apply_filters( 'pre_user_email', $email ), 'user_pass' => apply_filters( 'pre_user_pass', $password ), ];
Hope you can help me Hi there, If anyone has a spare minute, id really appreciate someone casting their eye over this and seeing if there's anything obviously wrong. Writing to the txt file works fine, but the redirect to the thankyou.html page doesn't. Cheers Guys. <?PHP $filename = "output.txt"; #CHMOD to 666 $forward = 1; # redirect? 1 : yes || 0 : no $location = "thankyou.html"; #set page to redirect to, if 1 is above ## set time up ## $date = date ("l, F jS, Y"); $time = date ("h:i A"); ## mail message ## $msg = ""; foreach ($_POST as $key => $value) { $msg .= ucfirst ($key) .", ". $value . ", "; } $msg .= "\n"; $fp = fopen ($filename, "a"); # w = write to the file only, create file if it does not exist, discard existing contents if ($fp) { fwrite ($fp, $msg); fclose ($fp); } else { $forward = 2; } if ($forward == 1) { header ("Location:$location"); } else if ($forward == 0) { echo ("Thank you for submitting our form. We will get back to you as soon as possible."); } else { "Error processing form. Please contact the webmaster"; } ?> Many thanks, Mike I have written some php that forces login before accessing certain pages on my site. When a user sends an private message to another user, they are notified via email. In the email they can then click the view message link to take them right to the message, but if they aren't logged in they are sent to the login page. I'd like them to be redirected to the message after logging in, but I'm getting a php error. This is currently working for URL's like: domain.com/known-bugs Does NOT work: http://domain.com/messaging?action=read&cid=130&utm_source=new_message&utm_medium=email&utm_campaign=direct_mesage_link I think the query string is a problem in the script. To create this login feature. I am using... Code: [Select] $login = array( 'blogadd', 'messaging', 'company-settings', 'company-landing', 'company-create', 'company-join', 'account-settings', 'logout', 'home', 'newsadd', 'partnerRequest', 'known-bugs', 'reminders' ); $page = substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4); if (in_array($page, $login)) { $urlSource = urlencode(curPageUrl()); header("Location: /login?onlogin=${urlSource}"); die(); } curPageURL is just the full url of the current page. WORKS: When I'm not logged in and I go to the known-bugs page I get redirected to http://domain.com/login?onlogin=http%3A%2F%2Fdomain.com%2Fknown-bugs DOESN'T WORK: When I try and access messaging by clicking... http://domain.com/messaging?action=read&cid=130&utm_source=new_message&utm_medium=email&utm_campaign=direct_mesage_link I get redirected to: http://domain.com/login?onlogin=http%3A%2F%2Fdomain.com%2Fmessaging%3Faction%3Dread%26cid%3D130%26utm_source%3Dnew_message%26utm_medium%3Demail%26utm_campaign%3Ddirect_mesage_link Any thoughts as to what I am doing wrong? Hi, i need help with refferer redirect after login. Example: - i am on user profile page (not required to be logged in) - when i click send PM (it goes to that address and that page check if user is logged in, if not it redirect user to login page) now in input hidden value(login page), where i save referrer url, there is not address of send PM link, but link from users profile page, i dont know why ? And after i login it redirect me to profile page not to send PM page. This is that send PM page: Code: [Select] <?php include("includes/connection.php"); ?> <?php include("includes/functions.php"); ?> <?php check_login(); ?> <?php include("includes/header.php"); ?> . . . . . Login input hidden field: Code: [Select] <input type="hidden" name="ref" value="<?php echo (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : ''; ?>" />Why it doesnt redirect me to send PM page after login ? Hey freaks! I have run into a bit of a snag and need a little guidance from the wise ones. I have a login script that users are redirected to if they land on restricted pages of my site. Initially, I used javascript (go back (-1) to get the user back to the page they were previously on after logging in - which worked fine...but only if they got their login credentials right the first time (which will probably never happen that often). The login form processes itself, so if they get it wrong, it comes back to login.php. I noticed that when I test logging in and purposely enter the wrong information, when I do enter the right info the login page comes back up because it was the previous url. I am not a big fan of JS and I am still fairly new to PHP, so I am not sure how to do this. I tried setting a session for the previous url using http referer (if the url did not equal login.php), but it did not like that at all! Undefined index, headers already sent, you name it...I got the error... I can post my code if need be, but it is just a basic login script (with a lot of Dreamweaver mumbo jumbo) that checks the username and pass in mysql. Any suggestions? Should I use a session for this? Or is it probably one of those switch statements that I am not remotely close in knowledge to writing myself...lol. Or even scarier...a custom function? Any help would be appreciated. Thanks! Hi, I have a url redirect set up on my site, when I use this I am unable to login, if I use the original Domain name it works fine, thanks for your help. I want people to login and then be redirected back to the page from where they came from. I was thinking that maybe I would have to use $_GET for 3 pages but I don't know if there is any easier way. http://pixpresso.mycyberlove.com/ This is my test hosting for this site I'm making. Navigation and facebook login are almost done. So, the problem is that after facebook login URL is http://pixpresso.mycyberlove.com/#_=_ Why is this? Is this bad, should I and can I remove this? Is there a way to get current logged in username and based on that redirect to a different page? I’m using the following secure PHP login without MySql as a login system: https://sourceforge.net/projects/phploginbyvallastech/ Now I’m looking to redirect each logged in user to their personalized page. But I can’t figure out how to A) fetch the current logged in user and B) redirect multiple users. This code redirects to the latter address, but the username based redirect is not working: <?php session_start(); if ($_SESSION["username"]==User1){ header("location: user1content.php"); exit; } else { header("location: generalcontent.php"); exit; } { ?> <?php } ?>
So it’s clearly not fetching the logged in user. Though <?php echo $login->username; ?> fetches the username just fine. I've joined querys because I'm making my own forums. However, when it gets to the echoin out part, it shows the category and only ONE of the sub categorys. Code: [Select] <div id="forumContainer"> <?php $lastboard = ''; $forumQ = mysql_query("SELECT f1.cat_name as catName, f1.cat_id as catID, f2.cat_id as subCatID, f2.sub_id as subID, f2.sub_name as subName, f2.sub_desc as subDesc FROM `forum_cats` as f1 LEFT JOIN `forum_sub` as f2 ON f1.cat_id = f2.cat_id GROUP BY f2.cat_id "); while($forumF = mysql_fetch_assoc($forumQ)) { if($forumF['catName'] != $lastboard) { echo '<div class="forumCat">'.$forumF['catName'].'</div>'; $lastboard = $forumF['catName']; } echo '<div class="forumSub">'.$forumF['subName'].'</div>'; } ?> </div> $Row[2] doesn't work but if I use $Row["linkcat"] than it works fine. Is there somewhere to activate in the php.ini file ? Code: [Select] // I got 9 fields to in the table tbl_link ! $Row[2] should give me a number. $Verbinding = mysql_connect($db_host, $db_user, $db_passw); mysql_select_db($db_name); $sql = "Select * from tbl_link where userid=1"; $ResultShow = mysql_query($sql); while ($Row = mysql_fetch_assoc($ResultShow)){ echo $Row[2]; } Here is the webpage.php which executes data entered in the email form. I want to display a webpage which would confirm that the email has been sent but the header redirect does not work. An email gets sent but a blank page is displayed instead of confirmation. Can anyone help? this is urgent <?php error_reporting(6143); require_once('recaptchalib.php'); $publickey = "6Ldmbr8SAAAAAGT17oCjkB8Y60kSqvq_0w7APAJp"; $privatekey = "6Ldmbr8SAAAAAMY5lEl-7LnkWCovoFa9G7Vl3_kA"; isset($_POST['Email']) ? $Email = $_POST['Email'] : $Email = ""; isset($_POST['name']) ? $name = $_POST['name'] : $name = ""; isset($_POST['surname']) ? $surname = $_POST['surname'] : $surname = ""; ?> <meta http-equiv="content-type" content="text/html; charset=iso-8859-2"> <body bgcolor="#000000"></body> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> <?php if (isset($_POST['Submit'])) { //Validate form $errormessage = ""; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($name == '') { $errormessage .= "<li>Please provide your name.</li> ";} if ($surname == '') { $errormessage .= "<li>Please provide your surname.</li>";} if ($Email == '') { $errormessage .= "<li>What is your e-mail address?</li>";} if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)){ $errormessage = $errormessage . "<li>This is not a valid email address! </li>";} if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errormessage .= "<li>Please rewrite captcha characters</li>"; } echo "</ul></p>"; //If errors, return error message(s) and form if ($errormessage != "") { ?> <span class="link1"><a href="index.php">back to home page/a></span> <img src="images/clack.JPG"> <table align="center"> <p align="center" class="err_bold">correct the following errors:</p> <span class="text_err"><ul><?=$errormessage?></span> </table> <?php include("email-form.php"); } else { //If good, mail to DL $email_subject = "Hello, you have a new message"; $email_headers = "From: $name [$Email] \r\n"; $to = "blablabla@hotmail.com"; $message_content = "----------------------------------------------------------------------------------\n". " Hello\n". "name: $name\n". "surname: $surname\n". "E-mail: $Email\n". "-----------------------------------------------------------------------------------\n\n"; //Email message to Requestor if (mail($to, $email_subject, $message_content, $email_headers)) { //Display Sent Confirmation (Successful or NOT!) ?> <?php header ("Location: http://www.google.co.uk"); exit; ?> <?php } } } else { ?> <span class="link1"><a href="index.php">back to home page</a></span> <img src="images/clack.JPG"><br> <p class="err" align="center">Please fill the form below<br/></p> <?php include("email-form.php");?> <?php }; Another issue with trying to work on somebody else's script (and on no sleep!) I've got this mess of a page I'm trying to manipulate to add a feature to. When somebody goes to this page, it pulls all records. At the top, I added a way to refine the results by dates. That query works fine, I tested it in mysql. To avoid fighting with the original code, I created an if statement to create $query_selectAll. But when I put it in the page, it would just refresh with the same data. I echoed the query to make sure it is correct. Then I realized that there was another query, $query_selectAllItems, further down the page that was generating the results, and none of what I was doing made a difference. But I'm not sure why it's ignoring my query or how to work around this. I tried deleting the query $query_selectAllItems, thinking it would take mine, because it ends with the same: $result_all $result_all = mysql_query($query_selectall); or $result_all = mysql_query($query_selectAllItems); Code: [Select] <?php require_once('calendar/classes/tc_calendar.php'); include("include/auth.php"); include("include/conn.php"); @$a_row = mysql_fetch_array($result); // I added this if statement in to get my POST results, without having to make changes to the GET results he made. if (isset($_POST['view'])){ $view=$_POST['view']; } else { $view=$_GET['view']; } if ($view=="All") { $query_selectall = 'select * from tbl_registration'; echo $query_selectall; } elseif ($view=="dated") { $mydate = isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : ""; $end_date = isset($_REQUEST["date6"]) ? $_REQUEST["date6"] : ""; $query_selectall = "SELECT * FROM tbl_registration WHERE reg_timestamped BETWEEN STR_TO_DATE('$mydate', '%Y-%m-%d') AND STR_TO_DATE('$end_date' , '%Y-%m-%d')"; echo $query_selectall; } else { $query_selectall = "select * from tbl_registration where category='$view'"; echo $query_selectall; } $result_all = mysql_query($query_selectall); @$numRows_all = mysql_num_rows($result_all); ?> <title>WYF Admin</title> <html> <head> <script language="javascript" src="calendar/calendar.js"></script> <link href="include/styles.css" rel="stylesheet" type="text/css"> <SCRIPT language="JavaScript"> <!-- function confirm_delete(idval) { var verify= confirm("Do you really want to delete this Registration?"); if (verify== true) { window.location="delete_registrations.php?action=delete&did=" + idval; } } //--> </SCRIPT> <script type="text/javascript" src="js/jquery-latest.js"></script> <script type="text/javascript" src="js/jquery.tablesorter.js"></script> <script type="text/javascript"> $(function() { $("table").tablesorter({debug: true}); }); </script> </head> <body leftmargin="0" rightmargin="0" bottommargin="0" topmargin="0" cellspacing="0" cellpadding="0" bgcolor="ffffff"> <table width="100%"><tr><td align="left"><img src="images/logo.jpg"></td></tr> <tr><td><hr></td></tr> </table> <table><tr><td valign="top"> <table cellspacing="1" cellpadding="0" bgcolor="#cccccc" border="0" width="300"> <tr><td> <table cellspacing="0" cellpadding="0" width="300" height="400" bgcolor="#ffffff" border="0"> <tr><td align="left" valign="top"> <table width="250"><tr><td valign="top"> <b>Welcome </b><br><br> <?php //$query_selectAllItems = "SELECT *, DATE_FORMAT(workshop_date, '%e-%m-%Y') as 'my_date' FROM tbl_workshops"; $query_selectAllItems = "SELECT * FROM tbl_registration"; $result_all = mysql_query($query_selectAllItems); $numRows_all = mysql_num_rows($result_all); ?> <? include "include/nav.php"; ?> </td></tr></table></center> </td></tr> <tr><td></td></tr></table></tr></td></table> </td><td valign="top"> <div style="float:left;padding-right:40px;"><a href="getcsv.php">export to csv</a></div><div> <div style="float:right;margin-right:100px;"><form name="form1" method="post" action="viewregistrations2.php"><div style="float:left;overflow:visible;padding-right:10px;">View between</div> <div style="float:left;overflow:visible;padding-right:10px;"> <?php $myCalendar = new tc_calendar("date5", true, false); $myCalendar->setIcon("calendar/images/iconCalendar.gif"); $myCalendar->setDate(date('d'), date('m'), date('Y')); $myCalendar->setPath("calendar/"); $myCalendar->setYearInterval(2000, 2015); $myCalendar->dateAllow('2008-05-13', '2015-03-01'); $myCalendar->setDateFormat('j F Y'); $myCalendar->setAlignment('left', 'bottom'); $myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year'); $myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month'); $myCalendar->setSpecificDate(array("2011-06-01"), 0, ''); $myCalendar->writeScript(); ?> </div> <div style="float:left;overflow:visible;padding-right:10px;"> and </div> <div style="float:left;overflow:visible;padding-right:10px;"> <?php $myCalendar = new tc_calendar("date6", true, false); $myCalendar->setIcon("calendar/images/iconCalendar.gif"); $myCalendar->setDate(date('d'), date('m'), date('Y')); $myCalendar->setPath("calendar/"); $myCalendar->setYearInterval(2000, 2015); $myCalendar->dateAllow('2008-05-13', '2015-03-01'); $myCalendar->setDateFormat('j F Y'); $myCalendar->setAlignment('left', 'bottom'); $myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year'); $myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month'); $myCalendar->setSpecificDate(array("2011-06-01"), 0, ''); $myCalendar->writeScript(); ?> </div> <div style="float:left;overflow:visible;padding-right:10px;"><input type="hidden" name="view" id="view" value="dated"><input type="submit" value="go!"> </div></form> </div><br><br><br><br> <table width="95%" border="1" cellpadding="3" cellspacing="1" bordercolor="#999999" id="rowspan" class="tablesorter" name="table"><thead> <tr bgcolor="#ffffff"> <th width="125">Name</th> <th width="125">Address</th> <th width="125">Phone</th> <th width="125">Email</th> <th width="125">Workshop</th> <td width="50"> </td> <td width="50"> </td><td> </td> </tr></thead> <tbody> <? //output each row while ($c_row = mysql_fetch_array($result_all)){ ?> <tr> <td><?= $c_row['reg_fname'] ?> <?= $c_row['reg_lname'] ?></td> <td><?= $c_row['reg_address'] ?></td> <td><?= $c_row['reg_phone'] ?></td> <td><?= $c_row['reg_email'] ?></td> <td> <?php $catid = $c_row['reg_workshopid']; $query="SELECT * FROM tbl_workshops where workshop_id = '$catid'"; //Run query; $result=@mysql_query($query); $row=mysql_fetch_array($result); ?> <?php echo($row['workshop_title']); ?> </td> <td width="50" bgcolor="#DEE1EB"><div align="center"><a href="edit_registration.php?id=<? print $c_row['reg_id'] ?>">edit</a></div></td> <td width="50" bgcolor="#DEE1EB"><div align="center"><a href="javascript://" onClick="confirm_delete(<? print $c_row['reg_id'] ?>); return false">delete</a></div></td> <td width="50" bgcolor="#DEE1EB"><div align="center"><a href="printregistration.php?regid=<? print $c_row['reg_id'] ?>">view all / print</a></div></td> </tr> <? } //end while ?> </tbody> </table><br><br> </td></tr></table> Im using func_get_args, but it gives an error?: Too few arguments?, when its correct (as the number of %s = the number of values within $args) <?php function sprintify() { global $urls; $args = func_get_args(); $input = $args[0]; unset($args[0]); return sprintf($urls[$input], implode(', ', $args)); } echo sprintify('default', 46, 464, 46); /* For your information: $urls['default'] = '%s/%s/%s'; */ ?> I've written a script where it counts the page impressions on my website. When a visitor lands on the page, it counts their impression and then sets a $_SESSION so that if they reload or return to the page it doesn't count it again. But the problem is it sometimes does. Does this mean that the $_SESSION isn't being set probably? That's what it seems to be. And if so, what would be the reason for that? Here's my basic code: Code: [Select] if(isset($_SESSION['userid'])){ $userid = $_SESSION['userid']; } else{ $userid = rand(1000, 10000000); $_SESSION['userid'] = $userid; } $date = date('Y-m-d'); $counters = mysql_query("SELECT * FROM counters WHERE userid='$userid' AND impressions='1' AND date='$date'") or die(mysql_error()); if(!mysql_num_rows($counters)){ mysql_query("INSERT INTO counters (userid, impressions, date) VALUES('$userid', '1', current_date)") or die(mysql_error()); } |