Jump to content
Larry Ullman's Book Forums

chuflasky

Members
  • Posts

    40
  • Joined

  • Last visited

Posts posted by chuflasky

  1. Thanks stuart for your quick reply. I was tying to insert the date in the following format.. e.g 12/10/2011 - 12-10-2011 - 12.10.2011. I though that once i get the date on one of this format using the DATE_FORMAT() function i could it format it to anything that i want for example..$exp=12/10/2011, DATE_FORMAT($exp, '%m-%d-%Y') shouldn't this be the result store 12-10-2011 after being formatted. Or there is only one way to store the date for exp,

    2011-12-10. By the way i tried to insert the date in this format DATE_FORMAT($exp,'%Y-%m-%d'), and in 'expire_date' column get a NULL value.What do you think of that. Thanks stuart.

  2. Hi, i'm tying to store the date collected from a form input called 'Expire_date', i want the user to enter an expire date so i can store it in the data base the only problem that i'm having is that only 0's are store in the 'expire_date' column. Here is the script that i'm using to store the data.

     	<input type="text" name="expire_date" size="10" maxlength="15" id="expire" value="<?php if(isset($_POST['expire_date'])) echo $_POST['expire_date']; ?>" />    

    . This is the HTML form input.

     

     	$exp = $_POST['expire_date'];    

    . This is the variable that collect the date. This same variable is validated using PCRE.

     

            INSERT INTO events(  expire_date) VALUES( DATE_FORMAT($exp, '%m %d %Y' )" ; 	

    .This script to insert into the data base.

     

     

    The 'expire_date' column in the database is a DATE type. Thanks in advance.

  3. Thanks jonathon and HartleySan for you quick reply.

    I'm getting the password from one of the registered user. And for that particular user, the password is right, but that same password is sent to others user even though their stored password is different. I guessing for some reason the SQL query is selecting the same password.

     

    Thanks HartleySan. So how can i select a particular password for a particular user. I thought that by using the clause 'WHERE user_name = '$un' AND password = SHA1('password') ' , the query will select the password for that particular user. If i'm wrong correct me.

     

    Once again, Thanks Guys.

  4. Hi, i been working on a script that base on the information provided by the user, will send he password. Now the problem that i having is that i get the same password sent, even though i enter different email and user name.

    If someone can check my code and point me out what i'm doing wrong, I'll appreciate.

     <?php
    if(isset($_POST['submitted'])){
    
    //connect to the database
    require_once("../mysqli_conn/db_conn.php");
    $errors = array();	
    //validate the email
    if(empty($_POST['username']) ){
    $errors[] = "<p class='error'>Please enter your user name.</p>";
    }else{
    $un = mysqli_real_escape_string($dbc, trim($_POST['username']) );
    }
    ///vlidate the email///
    if(empty($_POST['email'])){
    $errors[] = "<p class='error'>Please enter your email.</p>";
    }else{
    $e = mysqli_real_escape_string($dbc,trim( $_POST['email']) );
    }
    if(empty($errors) ){
    $q =" SELECT member_id FROM members INNER JOIN username ON members.user_id= username.user_id AND members.email = members.email WHERE email= '$e' AND user_name='$un' ";
    $r = mysqli_query($dbc, $q) or die("Error: " . mysqli_error($dbc) );
    $num = mysqli_num_rows($r);
    if($num == 1){ //match was made
    
    //MAKE THE QUERY//
             $q = "SELECT password FROM members INNER JOIN username ON members.user_id = username.user_id WHERE user_name = '$un' AND password = SHA1('password')  ";
     	$r = mysqli_query($dbc, $q) or die("Error: " . mysqli_error($dbc) );
    
    
    while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
                    $password = $row['password'];
    }
    
    
     	if($r){ //it ran ok 
    
    
    
    /*   
    // Please specify your Mail Server - Example: mail.yourdomain.com.
            	ini_set("SMTP","outgoing.verizon.net");
    
    // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
            	ini_set("smtp_port","25");
    
    // Please specify the return address to use
            	ini_set('sendmail_from', 'chuflasky@hotmail.com');
    */
    
        $to = $e;
        $subject ="Don't reply to this message.";
        $body = "This is a request to a forgotten password from THEEVENTSMASTER.COM. If you think you received this email
        by mistake, delete it. You current password is ' $password ' . Remember to put your password in a safe place.";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $header  .= 'From:theeventsmaster.com'.'<theeventsmaster.com>'. "\r\n";
        $header  .= "Cc: theevent@theeventsmaster.com"."\r\n";
    
    $send_mail =  mail($to,$subject,$body, $header);
    
        	if($send_mail){
              	$url = "confirm.php";
              	header("Location: $url");
              	exit();
    
    /* $today = time;
        ini_set($now, 'off');
        $now = date_default_timezone_set($today);
        */
         	}else{
                     	function sendEmail($errors){
                  $errors [] = "<p class='error'> Your password could not be delivered, try again latter.</p";
               	echo "<div class='error_handler'>";
              echo "<h2 class='error_2'>Error!</h2>";
              echo "<p class='error'>The following error(s) ocurred.</p>";
                     	foreach($errors as $mgs){
                              echo "$mgs";
                     	}//end of for each
                     	echo "</div>";
                  }//end of sendEmail 
                    	}//end of send message
    
       	}// end of $r 
    
    }else{
          function errorReport($errors){
          $errors [] ="<p class='error'> The user name and email could not be verify.</p><br/><h2 class='error_2'>Plase try again.</h2>"; 
         	echo "<div class='error_handler'>";
              echo "<h2 class='error_2'>Error!</h2>";
              echo "<p class='error'>The following error(s) ocurred.</p>";
    
           	foreach($errors as $mgs){
               	echo "$mgs";
           }//end of for each
    
       echo "</div>";   		
    	} //end of error_report
    }
    
    }else{
    function error_report1($errors){
        echo "<div class='error_handler'>";
    echo "<h2 class='error_2'>Error!</h2>";
    echo "<p class='error'>The following error(s) ocurred.</p>";
    
              foreach ($errors as $mgs){
                   	echo " $mgs ";
              }
    
    echo "</div>";
    
    	} //end of error_report1
    
    }//end of empty errors 
    
    }//end if submitted
    
    
    
    ?>  

  5. Hi paul try to change your query from

    $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date)
    VALUES ('$fn', '$ln', '$e', SHA1('p'), NOW() )"; 

    To

     $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) 
    VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )";
    $r = @mysqli_query ($dbc, $q) or die("Error: " . mysqli_error($dbc) ); //this will output any query string error syntax.
    

    And see what happens.

    • Upvote 1
  6. Hi, every one i found this article from the old forum from pswason, and i tried on my local machine before and i couldn't get it to work but i tried on the remote server and that took care of my problem. To redirect users base on the request page. For the example if user want to post an not loggedin, redirect to logi_page_inc.php.

    This is the script to how redirect users base on the requested page. http://www.larryullm.com/forum/read.php?19,46857,46885.

    In order for this code to work you have to delete the header redirect on the login.php. From this script

    if($check){// if ok	
      		session_start();
      		$_SESSION['member_id'] = $data["member_id"];
      		$_SESSION['user_name'] = $data["user_name"];
    
    
      		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);
    
     		/*setcookie('member_id',$data['member_id'], time()+3600*24*7*365, '/','', 0, 0 );
     		setcookie('user_name', $data['user_name'], time()+3600*24*7*365, '/','',0 ,0);
     		*/
     		//redirect
    	$url = absolute_url("index.php");
    		header("Location: $url");
      	exit();
    }
    

    To

     if($check){// if ok	
      		session_start();
      		$_SESSION['member_id'] = $data["member_id"];
      		$_SESSION['user_name'] = $data["user_name"];
    
    
      		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);
    
     		/*setcookie('member_id',$data['member_id'], time()+3600*24*7*365, '/','', 0, 0 );
     		setcookie('user_name', $data['user_name'], time()+3600*24*7*365, '/','',0 ,0);
     		*/
    
                     make no redirection here so the code on the login_page_inc.php redirect the requested page.
     	}
    

    If some one have trouble in getting this script to work, feel free to ask. Or post the issue.

    • Upvote 1
  7. Ok guys this is what happened.

     

    earlier i modified the login.php to get the value of a variable and base on that variable either go to the index.php or to the URL store in that variable. The below code was the modification that i made.

      if($check){// if ok	
      		session_start();
      		$_SESSION['member_id'] = $data["member_id"];
      		$_SESSION['user_name'] = $data["user_name"];
    
    
      		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);
    
    
     		/*setcookie('member_id',$data['member_id'], time()+3600*24*7*365, '/','', 0, 0 );
     		setcookie('user_name', $data['user_name'], time()+3600*24*7*365, '/','',0 ,0);
     		*/
    
     		//redirect to  the request page
      	if(isset($page_name)){
    		$url= $page_name;
    		header("Location: $url");
    		$url= "../index.php";
    		header("location: $url",false);
    		exit();
     	}//end of isset
    
    	}else{ //unsuccessful!
      	//assign $data to $errors for error reporting
      	//in the login_page_inc.php.
      	$errors = $data;	
    }  

    And the original script base on the book is as follows.

     if($check){// if ok	
      		session_start();
      		$_SESSION['member_id'] = $data["member_id"];
      		$_SESSION['user_name'] = $data["user_name"];
    
    
      		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);
    
    
    
      		$url = absolute_url("../index.php");
      		header("Location: $url");
      		exit();
    
    
    
    
    	}else{ //unsuccessful!
      	//assign $data to $errors for error reporting
      	//in the login_page_inc.php.
      	$errors = $data;	
    } 

    I tried the original script, base on the book and it works, after login i get redirected to the index.php. But the first script, the modified one, redirected the user back to requested page base on the $page_name URL value. So now i need a way to redirect the users to requested page using another script. That means more work. Any ideas how to do this the easy way. I don't understand how this script was working in my machine and when moved to the serve, do not. Thanks for you help guy, i appreciated.

  8. Thanks HartleySan for the reply. I did exactly what you told me and didn't solve the problem. Actually when i changed the path from '../index.php' to 'index.php', and try to logout, it won't find the page, that is the index.php. One thing that i noticed in the browser is the follow.

    www.example.com/user_php/login_page_inc.php 

    . This is path to the login page when i click to sign In.

     

    And this is where i take me after loggedin

    www.example.com/user_php/login.php

    . As you can see instead of redirecting me to the index.php i get redirected to login.php. And as you know that where the absolute_url() function is declared. Any ideas. Thanks for you help.

  9. Thanks for the reply jonathon and matthaus, i solve the session problem and like you said matthaus, it was my php.ini configuration. But now the problem i having is that when i login, instead of being redirect to the index.php page like i suppose to, i get logged in but don't get redirect to the index.php. i stay in the login_page, as loggedin. I did not have any problem when i was developing my web page on my machine, the script was working fine. I starting to suspect that the absolute_url($pages = "../index.php"), is the problem.

    function absolute_url( $pages = "../index.php"){
    //start defining the url
    //url is http:// plus the host name plus the current directory:
    
    $url = 'http://'. $_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']);
    
    ///remove any trailing slashes
    $url = rtrim($url, '/\\');
    
    //add the page
    $url .= '/' . $pages;
    
    //return the url
    return $url;
    }//end of absolute function  

     

     

    I don't know if this have to be modify when move from my machine to the server. But if i logout, i get redirected to the index.php like suppose to even though i'm using the same function absolute_url("../index.php"). The bellow script is the logout.

     session_start(); //access the existing session
    
    //if no sssion variable exist redirect the user:
    if(!isset($_SESSION['user_name']) ){
    require_once("login_function_inc.php");
    $url = absolute_url();
    header("Location: $url");
    exit();
    }else{//cancel the session
       $_SESSION = array(); //clear the variable
    session_destroy(); //destroy the session itself.
    setcookie('PHPSESSID', '', time()-3600*24*7*365, '/', '', 0, 0); //destroy the cookie.
    require_once("login_function_inc.php");
    $url= absolute_url();
    header("Location: $url");
    exit();
    } 

    Or could it be that i have to keep modifying the php.ini file, and is so, to what path or section of the file should i modify . Thanks in advance.

  10. Hi, every one.

    I developed my web page in my computer using XAMPP. Everything was working fine until i moved to the server. Now i having the following problems.

    At the top of my page i got the following warning.

    Warning: session_start() [function.session-start]: open(/temp/sess_3e23bd83a0025df302a789c7e4f9789f, O_RDWR) failed: No such file or directory (2) in /home/theevent/public_html/index.phpon line 2

     

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/theevent/public_html/index.php:2) in/home/theevent/public_html/index.php on line 2

    That's one of my problems. The second problem that i having is that when i login from the login page instead of being redirected to the home page (index.php) i stay at the login page. But i know the session is working because i get the welcome message with the user name at the banner where i configured to be. If some have this problem before, please shed some light. Thanks.

  11. Problem solve. posting solution for the benefit of others.

     

     

    1: in the page that i want to redirect back i create a variable that store the current page URL. then i add that variable to the header that take the user to the login_page if they are not logged in.

     $page_name = $_SERVER['PHP-SELF'];
    if(!isset($_SESSION['user_name'])){
    		header("Location: login_page_inc.php" . (isset($page_name)? '?page_name=' . $page_name : '') );
    } 
    

     

    After being taken to the login_page_inc.php, retrieve the URL that the page came from using a hidden field in the login_page_inc.php.

     <input type = "hidden" name="page_name" value="<?php echo $_GET['page_name']; ?>" />

     

    Now and this is the most important. in the login.php not the login_page.inc.php on page 338 of the book PHP 6 AND MYSQL5 'Larry ullman', line 26 to 29 i made the following changes.

     if(isset($page_name)){
    $url = page_name;
    header("Location: $page_name");
    $url = absolute_url("../index.php");
    header("Location: $url" , false);
    exit();
    }
    

    I referred to the book for the benefit of the google search engine.

    • Upvote 1
  12. Hi, this is not related to the book, i just need some help.

    i being working in this script for the last past weeks and i still can't figured out. i still get redirected to the index page. I was wondering if i have to modified the login.php in order for the script to be executed.

    the code below is what a came up with.

     

    This is the script where i redirect the user if they are not logged in.

     <?php 
    session_start();
    
    $page_name = $_SERVER['PHP_SELF'];
    if(!isset($_SESSION['user_name'])  ){
    	header("Location: login.php" . (isset($page_name)? '?page_name='. $page_name: '' ) ); 
    	exit();
    
    
    }//localhost/index2/user_php/login.php?page_name=/index2/user_php/myevents.php
    
    else{ //end of this part
    require_once "../include/header.php";
    //need the data base connection to talk to the data base
    
       require_once("../mysqli_conn/db_conn.php");
    //select the events fron the data base//
    $query ="SELECT user_id, title_id, cat_id FROM events WHERE user_id = '$username' ";
       $result = mysqli_query($dbc, $query) or die("Error: " . mysqli_error($dbc) ) ;
    $rows = mysqli_num_rows($result);
    if($rows == 0){
      	echo "<p>You current have no events posted so far.</p>";
      	}else{
    
       		echo "<table cellspacing='3' cellpadding='3' width='50%'>";
     		while($rows = mysqli_fetch_array($result,MYSQLI_ASSOC) ){
     		echo '
       		<tr>
     			<td>Events Name:</td>
       			<td>' . $rows["name"]. '</td>
    			</tr> ';
    
      	}
     	echo"  </table>";
      	}
    
    }//end of else stament
    
    include("../include/footer.html");
    ?>  

     

     

     

    Now, i get redirected to login_page_inc.php. the below script is what i got.

     <?php include("../include/header.php");?>
    <?php
    /* 
    *login_page_inc.php
    */
    //this pega prints any errors associated with logging in
    //and it create the entire login page, including the form.
    
    ///include the header
    
    //print any errors message if they exist
    
    ///get the page url //this part goes in the header
    
     if(isset($_GET['page_name']) ){
    $page_name = $_GET['page_name'];
    }elseif(isset($_POST['page_name']) ){
    $page_name= $_POST['page_name'];
    }
    //end of this part
    
    
    //check to see if already logged in
    if(isset($_SESSION['user_name']) ){
    //redirect if page has a value.
    if(isset($page_name) && strlen($page_name) >0){
           $url = $page_name;
    	header("Location: $url");
    	exit();
    }else{
    	//redirect to home page
    	$url = "../index.php";
    	header("location: $url");
    	exit();
    }
    
    }
    
    
    if(!empty($errors) ){
    	echo "<div id='signIn_error_handler'>";
    echo "<h2 class='error_2'>Error!</h2>
    <p class='error_2'>The following error(s) occured:<br />";
    
    foreach($errors as $msg){
    
    	echo "  $msg<br />\n";		
    }
    echo "</p><p class='try_again'>Please Try again.</p><p><br /></p>";
    echo"</div>";
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sing In</title>
    <link href="../css/php_style.css" rel="stylesheet" media="all" type="text/css" />
    
    </head>
    
    <body>
    <div id="wrapper">
    
    
    <h2 class="signIn_form">Sign In Form</h2>
    <div id="user_signIn">
    
    <div id="image">
    <img src="../images/user-security.png" />
    </div><!--end of image -->
    
    <table cellpadding="3" cellspacing="3" width="50%">
    <tr>
    <form action="login.php" method="post" >
    <tr>
    <td><p>User Name:</p></td>
    <td><input type="text" name="username" maxlength="30" value="<?php if(isset($_POST['username']) )echo $_POST['username'] ?>" />
    </td>
     </tr>
     <tr> 
       <td><p>Password:</p></td>
    	<td><input type="password" name="password" maxlength="15" />
    	</td>
    	</tr>
    	<tr>
       <td>
       <input type="hidden" name="page_name" value="<?php  echo $_POST['page_name']; ?>"  />
       <input  type="hidden" name="page_name" value="<?php  echo  $_GET['page_name']; ?> "  />
       <input type="hidden" name="submitted" value="TRUE" />    
       <input type="submit" name="submit" value="Sign In" />
      </td>
     </tr>
    </form>
    </tr>
    </table>
    </div><!--end of user_signIn -->
    
    </div><!--end of wrapper -->
    
    </body>
    </html>
    <?php include("../include/footer.html");?>  

     

     

    And when i view page source, the hidden field with the $_GET variable has the value from which it came from. But still get redirected to the index.php.

    I was wondering if the login_function_inc.php and login.php has to be modified. and the reason that i think so, is because the form is being process by the login.php.

    and in the login.php below.

     

     <?php
    /*
    *login.php
    *this page processes the login form submissin.
    *upon succeful login, the user is redirected.
    *two include file are necessary.
    *set nothin to the web browser prion to the set cookie() line!
    */
    
    //chech if the form has been submitted
    if(isset($_POST['submitted']) ){
    
    
    	//for processing the login
    require_once("login_function_inc.php");
    
    
    //need the data base connection:
    require_once("../mysqli_conn/db_conn.php");
    
    
    
    list($check, $data) = check_login($dbc,$_POST["username"],$_POST["password"]);
    
    if($check){// if ok	
      		session_start();
      		$_SESSION['member_id'] = $data["member_id"];
      		$_SESSION['user_name'] = $data["user_name"];
    
    
      		$_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);
    
     		/*setcookie('member_id',$data['member_id'], time()+3600*24*7*365, '/','', 0, 0 );
     		setcookie('user_name', $data['user_name'], time()+3600*24*7*365, '/','',0 ,0);
     		*/
     		//redirect
    		$url = absolute_url("../index.php"); 
    		header("Location: $url");
    		exit();//quit the scrip   		
    
    		}
    		else{ //unsuccessful!
      	//assign $data to $errors for error reporting
      	//in the login_page_inc.php.
      	$errors = $data;	
    }
    
    
    mysqli_close($dbc);// close the data base connection
    }//end of if submitted
    
    //creat the page:
    include("login_page_inc.php");
    ?>  

     

     

    As i point in red from about that the redirection already set, if i change that to $url = absolute_url($page_name); and remove the code dirname($_SERVER['PHP-SELF']) to just $url ='http://' . $_SERVER['HTTP-HOST']; in the login_function_inc.php script, it redirect me back to the requested page, but when i try to login normally, it take me to XAMPP main page.

×
×
  • Create New...